Home > Back-end >  Why css "overflow: scroll" doesn't work and the scroll bar doesn't show?
Why css "overflow: scroll" doesn't work and the scroll bar doesn't show?

Time:11-18

I add overflow: scroll to try to make the scroll bar appear, but it doesn't work, and I cannot figure out where is the problem. Please have a look, thank you so much!

What's more, I am using MacOS, and it doesn't work. But based on the same code, my friend uses Windows system, and it can work. By the way, we all use Chrome browser.

This really confuse me:(

UPDATE: I guess the MacOS will hide the scroll bar by default? Because based on the same code, MacOS will hide the scroll bar, and if I scroll down, the scroll bar will show next.But my friend is using Windows, and the scroll bar will always show on the page even he doesn't scroll down.

Here is the code.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>The Box Model</title>
<style>

body {
  background-color: gray;
  margin: 0px;
  padding: 10px;
}

#box {
  background-color: blue;
  border: 10px solid black;
  width: 500px;
  box-sizing: border-box;
  height: 200px;
  overflow: scroll;
}
#content {
  background-color: #90EE90; /*green*/
  margin: 50px;
  padding: 20px;

}

h1 {
  margin-bottom: 30px;
}

</style>
</head>
<body>

<h1>Box Model</h1>

<div id="box">
  <div id="content">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Lorem ipsum dolor sit amet, consectetur adipisicing elit.Lorem ipsum dolor sit amet, consectetur adipisicing elit.Lorem ipsum dolor sit amet, consectetur adipisicing elit.Lorem ipsum dolor sit amet, consectetur adipisicing elit.Lorem ipsum dolor sit amet, consectetur adipisicing elit.Lorem ipsum dolor sit amet, consectetur adipisicing elit.Lorem ipsum dolor sit amet, consectetur adipisicing elit.Lorem ipsum dolor sit amet, consectetur adipisicing elit.Lorem ipsum dolor sit amet, consectetur adipisicing elit.Lorem ipsum dolor sit amet, consectetur adipisicing elit.Lorem ipsum dolor sit amet, consectetur adipisicing elit.</div>
</div>


</body>
</html>



CodePudding user response:

<!DOCTYPE html>
<html>
<head>
<style>
div {
  background-color: #eee;
  width: 200px;
  height: 100px;
  border: 1px dotted black;
  overflow: scroll;
}
</style>
</head>
<body>

<h2>Overflow: scroll</h2>

<p>Setting the overflow value to scroll, the overflow is clipped and a scrollbar is added to scroll inside the box. Note that this will add a scrollbar both horizontally and vertically (even if you do not need it):</p>

<div>You can use the overflow property when you want to have better control of the layout. The overflow property specifies what happens if content overflows an element's box.</div>

</body>
</html>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

overflow : scroll , will only work and visible if you have fixed the size of the box and the content inside the box is bigger.

CodePudding user response:

Give this a try for your query regarding Overflow scroll.

<!DOCTYPE html>
<html>
<head>
<style>
.Scroll-Testing {
  background-color: rgb(15, 207, 255); width:500px; height: 400px; border: 1px dotted rgb(255, 95, 95);overflow-y: scroll; }
</style>
</head>
<body>
    <h2>Overflow: scroll Testing</h2>
    <div class="Scroll-Testing">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

        Why do we use it?
        It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
        
        
        Where does it come from?
        Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
        
        The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.</div>

</body>
</html>
  • Related