How to fix the height of a
element?

2020-05-20 01:21发布

I've defined my div's height in a stylesheet:

.topbar{
  width:100%;
  height:70px;
  background-color:#475;
}

But as soon as text is entered into the div, the divs height changes.

Any ideas?

标签: css html
4条回答
狗以群分
2楼-- · 2020-05-20 01:26

You can try max-height: 70px; See if that works.

查看更多
走好不送
3楼-- · 2020-05-20 01:38

You can also use min-height and max-height. It was very useful for me

查看更多
我想做一个坏孩纸
4楼-- · 2020-05-20 01:39

If you want to keep the height of the DIV absolute, regardless of the amount of text inside use the following:

overflow: hidden;
查看更多
▲ chillily
5楼-- · 2020-05-20 01:50

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/

查看更多
登录 后发表回答