How to fix the height of a <div> element?
I've defined my div's height in a stylesheet:
.topbar{
width:100%;
height:70px;
background-color:#475;
}
But as soon as text is enter开发者_运维技巧ed into the div, the divs height changes.
Any ideas?
change the div to display block
.topbar{
display:block;
width:100%;
height:70px;
background-color:#475;
overflow:scroll;
}
i made a jsfiddle example here please check
http://jsfiddle.net/TgPRM/
If you want to keep the height of the DIV absolute, regardless of the amount of text inside use the following:
overflow: hidden;
You can also use min-height and max-height. It was very useful for me
I think height and overflow should work, like height 70px or according to need. And overflow could be auto like this:
.topbar{
width:100%;
height:70px;
background-color:#475;
overflow: auto;
}
Note: overflow with scroll will show the area of scrollbar either its visible or not I think.
You can try max-height: 70px; See if that works.
精彩评论