Style a
background image with CSS

When we think of the horizontal rule, other cliche 90′s era design items come to mind; however the <hr> has made quite a comeback lately. A recent post at Smashing Magazine shows some fresh and creative uses for the once forgotten HTML tag.

Now that you have it in mind that you want to use a slick background image instead of that boring old straight line, the question arises – how do I code that effectively? At first you’d think, “I’ll just add a background image to the basic HTML hr tag,” but as you may have guessed, browsers display output differently when you do this.

For a simple solution, use the following CSS to style your <hr>line:
[sourcecode language="css"]
div.hr { height: 15px; background: url(images/hr.png) no-repeat scroll center;}
div.hr hr { display: none;}
[/sourcecode]

That effectively hides the <hr> tag from displaying anything funny, and allows you full control over the background image.

To use it in your HTML, use the following:
[sourcecode language="css"]


[/sourcecode]

No related posts.

About Mike

Michael Meisner is a rabid SEO enthusiast, with a strong background in all things marketing and web analytics. He lives in the heart of wine country in Napa, CA with his dog, Drifter, and works with wineries to help expand their consumer direct marketing efforts.
Comments are closed.