views:

549

answers:

7

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?

+4  A: 
.ColorSeparatorArea
{
    background-color: #3d3d77;
    height: 1px;
    overflow: hidden;
}
Jon Kruger
See the font-size comment by Shog9. Also consider setting line-height: 0;
Mike Robinson
Combined this solution with @goodenoughs
hamlin11
+1  A: 

Also set the font-size style:

font-size: 1px;
Shog9
font-size: 0; works too
Mike Robinson
+3  A: 

You need to specify the line-height if the height is lower than the default line-height.

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

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.

X-Istence
+5  A: 

Wouldn't this work better and be more semantic?

<hr />

.

hr
{
    border: 1px solid #3d3d77;
}
tj111
A HR-element is never semantic, it is purely presentational just like B or I. Horizontal rule tells you nothing more than "insert a horizontal rule here" just like I tells you that "This text is italic".
Arve Systad
I used to agree with that comment, but now I tend to think that a horizontal rule does/can have some semantic meaning along the lines of "the content before this rule is somehow conceptually separate from the content after this rule". I'm not claiming that it carries nearly as much implied semantic value as a heading (h1-h6) or definition list, but perhaps more like a (often allegedly 'semantically neutral') div "encloses a separate thing" an hr "separates 2 things"
Andy Ford
+1  A: 

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.

Pourquoi Litytestdata
A: 

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

Arve Systad