
Originally Posted by
ArthurKay
Is it possible to have more than one background image styled for an HR tag?
Quite simply, No.
The css attribute "background-image" is included for the (x)html element "hr" in CSS 2.x, but browser support is not consistent. For example, IE and Opera (and some versions of Safari) will render a border around the hr, even if you set "border:none;" in the css.
I'm also not convinced that the code you posted would actually span the entire width of the viewport, since theoretically it only would do so when the width of the middle image equals 14% or more of the total viewport.
There is, however, a good way of achieving this effect with simple css. I will assume that, for stylistic reasons, the images are not just plain lines (in which case you'd be much better suited using divs with css borders for the outer two lines).
Code:
css:
#line {
width:100%; /* this is assumed if not specified, so you can omit this line if you want */
height:1px; /* set the height of the line container */
vertical-align:middle; /* this will cascade to the subordinate divs */
margin:0; /* necessary for < IE7 */
}
#line_left {
width:49%; /* we must account for IE's crappy box model */
background:url('line.gif') repeat-x;
float:left;
z-index:1;
}
#line_right {
width:49%; /* we must account for IE's crappy box model */
height:1px;
background:url('line.gif') repeat-x;
float:right;
z-index:1;
}
#line_clearfloat {
clear:both;
}
#line_middle {
width:40px; /* replace this value with the width of the actual image */
height:1px;
background:url('middle.gif') no-repeat;
margin:auto; /* this will center the image */
margin-top:-1px; /* this will place it on top of the lines above */
_margin-top:-38px; /* hack for < IE7 */
z-index:2; /* this tells browsers to display this image on top of the other images */
}
Code:
(x)html:
<div id="line">
<div id="line_left"> </div>
<div id="line_right"> </div>
<div id="line_clearfloat"> </div>
</div>
<div id="line_middle"> </div>
Since you were using the (x)html attribute "align," I will assume you're not interested in validating as XHTML Strict. If you are, however, you'll need to omit the _margin-top hack for IE, as the underscore hack will not pass css validation. If you'd like to achieve validation, delete the _margin-top line in the css and replace <div id="line_middle"> </div> in the (x)html with the following:
Code:
(x)html:
<!--[if lte IE 6]><div style="margin-top:-38px;"><![endif]-->
<div id="line_middle"> </div>
<!--[if lte IE 6]></div<![endif]-->
If you'd like to use this multiple times on the same page, you can leave the css as it is and replace the attribute "id" with "class" in the (x)html.
Hope this is helpful.