Interview Questions

Colored Horizontal Rule?

CSS Interview Questions and Questions


(Continued from previous question...)

99. Colored Horizontal Rule?

You can apply styles to Horizontal Rules <HR> in IE without problems, but NN4.xx can only render the silvery HR. But there is a way around it:

.rule {border-top-width: 1px;
border-top-style: solid;
border-color: #FF0000;
margin: 0px 2%;}

that, applied to a div, should give you a red HR in NN4.xx and IE, with a 2% gap on the left and right side.

CSSharky Logo
On this page is an Example of a coloured 'Horizontal Rule'.
Update:
Thanks to Matt Del Vecchio here is an improved format for the Horizontal Rule:

hr { height:0px;
border:0px;
border-top:1px solid #ff1493; }

....this works in both IE and Netscape. It tells the browser to not render the hr rule itself, and then sets a 1px border, which looks just how most folks want to render the hr rule. It uses the <hr> element and that is better than writing your own class as all devices will know what to do with an <hr> tag.

(Continued on next question...)

Other Interview Questions