tags:

views:

881

answers:

4

Hi

I'm looking for a way to do something which in my opinion should be super simple, but I couldn't figure it out...

I want a graphical element on my web page which is exactly 1 pixel high, 100% wide and has a certain color, let's say red. It should look exactly the same in all browser and should preferably not break the semantics too much.

I don't want to use any images for this and I don't want to use more than one HTML element. Of course, I will not use JavaScript.

I tried the old classic which probably many of you know:

<div class="hr"></div>

<style ...>
.hr {
    height: 1px;
    background: red;
    width: 100%;
    font-size: 1px; /* IE 6 */
}
</style>

The problem with the above solution is that IE6 will render this as two or three pixels high, to fit the non-existing contents of the div.

Any ideas?

+5  A: 

just do

.hr {
  height: 0px;
  margin: 0px;
  border-bottom: 1px solid #FF0000;
  font-size: 1px;
}

I went through the same thing when I was new to CSS.

Robert Greiner
Heh, I've worked with CSS professionally for over a year, but not until now do I have to support IE6... :)
Deniz Dogan
The problem with this solution is that I'm unable to properly set a margin on the `div.hr`, it acts really strange in IE6.
Deniz Dogan
oh, sorry about my assumptions. I hate dealing with IE6 also. I tried @Meep3D's solution and it worked, might want to go with him :P
Robert Greiner
+3  A: 

adding an overflow: hidden; style should fix it also.

Meep3D
Worked great, thanks a lot.
Deniz Dogan
+1  A: 

I don't have IE6 to test this, but I remember it had to do something with the line height. Have you tried this?

line-height: 1px;
Ivan Zlatanov
A: 

I don't have IE6 handy to test, but an actual HR tag can work in modern browsers. Took me a couple of tries to realise you set the background color not the border color:

hr { width:75%; height:1px; background-color:#ebebeb; border:none; margin:1.5em auto; }

(adjust to suit)

Anentropic