开发者

Strange IE7 bug with hr width in a floated div

I ran into this very strange "bug" with IE7, I have many div.column floated left, no width specified. The strange thing is that in IE7 the hr element width seems to take up 100% width of t开发者_运维百科he container of these columns. And also the css rules for hr do not seem to be applied nicely, the background img looks very weird, border doesnt seem to be removed:

hr.style3{background:url(../images/backgrounds/hr1.gif) repeat-x;border: 0 none;height:3px;margin:15px 0;}

<div class="column last">
    <div class="title">Useful info</div>
    <hr class="style3" />
    <ul class="links line_height3">
         <li>
             <a href="#">sample link</a>
         </li>
    </ul>
</div>


tw16 suggested http://borgar.net/s/2007/01/style-hr-elements/ which is a very cool technique, however for some reason I could not make it work for my particular case, perhaps I missed something.

Anyhow, I opted to use a div instead, but to make it behave similar to hr I wrap this div around a display:none hr:

css:

.hr hr {
    display:none
}

html:

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

However, if your div.hr is inside a floated container (which, in my case, is also in another floated container), then you may have to assign a fixed width for it (only for IE7). I use modernizr plugin so I did something like this:

.ie7 .hr {width:100px}

With this method, you can:

  1. Style the "hr" with background image etc easily, which should work cross browsers
  2. Still keep the hr element where you want it so text readers and such can see it
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜