I have a div with following style: height:250px;scroll:auto;. I want it to scroll after 250 px but should have height according to the content in it.
For example, if the content in it is 100px, then, the height of div should be 100 without scroll. But, if the height exc开发者_开发问答eeds 250px, it should show scroll.
How can do it?
Is this what you are after?
Demo
CSS:
.dyn-height {
width:100px;
max-height:250px;
overflow-y:scroll;
}
height:
optional - just for the demo.
try this: max-height should do the trick.
html
<div class="height">
blah<br/>
blah<br/>
</div>
css:
.height { max-height:250px; border:1px solid red; overflow:auto; }
Use overflow-y
with the auto
option.
This way the scroll bar will not show up until it is needed.
Otherwise the scroll bar will display, even if you do not need it to show.
.my_div {
width:100px;
max-height:250px;
overflow-y:auto;
}
just try max-height and do overflow-y:scroll just it
.hidden {
width:100px;
max-height:250px;
overflow-y:scroll;
}
<div class="hidden">
<h5>If the content in this div exceeds 250px it should appear a scroll bar</h5>
</div>
精彩评论