永久滚动条
这将为始终可见的元素提供滚动条。如果内容较少且不需要滚动,滚动条仍然存在,只是样式为禁用。
.scroll{
overflow: scroll;
height: 100px;
}
滚动条,仅在需要时
这将在需要时产生滚动条,如果内容较少且不需要滚动,则不会有滚动条。这可能看起来更好,并且不占用任何宽度。
.scroll{
overflow: auto;
height: 100px;
}
文档类型
您的内联编码做奇怪事情的原因也可能是因为错误的文档类型,这应该被定义。这些天的常见做法是<!DOCTYPE HTML>
。您只需将其放在 html 文件的开头,然后<html>
例子
.example_auto{
height: 75px;
overflow: auto;
width: 24%; /* just for demo */
display: inline-block; /* just for demo */
vertical-align: top; /* just for demo */
background: #FFC; /* just for demo */
}
.example_scroll{
height: 75px;
overflow: scroll;
width: 24%; /* just for demo */
display: inline-block; /* just for demo */
background: #FCF; /* just for demo */
}
<div class="example_auto">This is too little content to scroll.</div>
<div class="example_scroll">This is too little content to scroll.</div>
<div class="example_auto">This div has waaaaay more content en will need a scrollbar. This will look almost the same in both cases.</div>
<div class="example_scroll">This div has waaaaay more content en will need a scrollbar. This will look almost the same in both cases.</div>