我有一个弹出框显示一些结果,由于这些结果被裁剪了,我希望显示一个滚动条(而且我不想让弹出框太长)。
您需要向 div 标签添加 style="overflow-y:scroll;"
。 (这会强制在垂直方向上出现滚动条)。
如果只想在需要时显示滚动条,可以使用 overflow-y:auto;
。
使用CSS类创建一个带有滚动条的漂亮Div。
.DivToScroll{
background-color: #F5F5F5;
border: 1px solid #DDDDDD;
border-radius: 4px 0 4px 0;
color: #3B3C3E;
font-size: 12px;
font-weight: bold;
left: -1px;
padding: 10px 7px 5px;
}
.DivWithScroll{
height:120px;
overflow:scroll;
overflow-x:hidden;
}
要添加滚动条,您需要定义
因此,请执行以下操作:
.my_scroll_div{
overflow-y: auto;
max-height: 100px;
}
!important
,然后尝试使用.my_scroll_div{ overflow-y: auto !important; max-height: 100px !important; }
。 - undefinedjQuery('#mydiv').css("overflow-y", "scroll");
<div class="scrollingDiv">foo</div>
div.scrollingDiv
{
overflow:scroll;
}
<head>
<style>
div.scroll
{
background-color:#00FFFF;
width:40%;
height:200PX;
FLOAT: left;
margin-left: 5%;
padding: 1%;
overflow:scroll;
}
</style>
</head>
<body>
<div class="scroll">You can use the overflow property when you want to have better control of the layout. The default value is visible.better control of the layout. The default value is visible.better control of the layout. The default value is visible.better control of the layout. The default value is visible.better control of the layout. The default value is visible.better control of the layout. The default value is visible.better </div>
</body>
</html>
<div>
元素定义一个调用并分配overflow: auto
CSS属性。<div class="container">
在CSS文件中,您可以写入以下内容:.container{
overflow: "auto";
}
易于操作
的方法,附带简单易懂的解释
。.my_scroll_div {
overflow-y: auto;
max-height: 100px;
}
这里是上述代码的一些解释。
overflow-y: auto;
CSS的overflow-y
属性在需要时添加滚动条,如果我们想在特定高度(例如,在我们的情况下为100px)之后添加滚动条,则需要使用:
max-height: 100px;
我们添加CSS的max-height
属性,例如要在高度100px
之后添加滚动条,则使用max-height: 100px;
。
希望这个解释有助于澄清概念。
<html>
<head>
<style>
div.scroll {
max-height: 50px;
overflow: scroll;
}
</style>
</head>
<body>
<div class="scroll">
You can use the overflow property when you want to have better
control of the layout. The default value is visible.better control
of the layout. The default value is visible.better control of the
layout. The default value is visible.better control of the layout.
The default value is visible.better control of the layout. The
default value is visible.better control of the layout. The default
value is visible.better
</div>
</body>
</html>