Internet Explorer ignores really small heights set

2019-07-16 21:39发布

I have CSS that looks like this...

.ColorSeparatorArea
{
    background-color: #3d3d77;
    height: 1px;
}

... and then I'm applying that style to a DIV element:

<div class="ColorSeparatorArea"></div>

It works fine in non-IE browsers, but in IE, it sets the height of the div to the height of one line of text and it won't let me go any smaller. Anyone know how to get around this problem?

7条回答
你好瞎i
2楼-- · 2019-07-16 21:49

Also set the font-size style:

font-size: 1px;
查看更多
地球回转人心会变
3楼-- · 2019-07-16 21:51

Wouldn't this work better and be more semantic?

<hr />

.

hr
{
    border: 1px solid #3d3d77;
}
查看更多
再贱就再见
4楼-- · 2019-07-16 21:54

I remember having a similar problem with spacing/separator <div>s in IE. I found this page which helped me. The solution I used was to put an empty comment in the <div>, i.e.

<div class="ColorSeparatorArea"><!-- --></div>

It seems an odd thing to do, but it works.

查看更多
Summer. ? 凉城
5楼-- · 2019-07-16 22:01

Depending on the version of Internet Explorer, it will use height as if it is min-height and grow the box however big it feels like growing the box.

查看更多
时光不老,我们不散
6楼-- · 2019-07-16 22:03

Stick a non breaking space (& nbsp;) into that div, set the font-size (and possibly line-height) to 1px and it should be fine.

查看更多
▲ chillily
7楼-- · 2019-07-16 22:07
.ColorSeparatorArea
{
    background-color: #3d3d77;
    height: 1px;
    overflow: hidden;
}
查看更多
登录 后发表回答