简体   繁体   English

在IE7中浮动Div

[英]Floating Div in IE7

I really hoped my IE7 woes were over, but my company still supports it across our enterprise, so alas I'm stuck with fixing some glitches. 我真的希望我的IE7问题已经结束了,但是我的公司仍然在我们的企业中支持它,所以我很难解决一些问题。 I must be overlooking something incredibly silly, and I was wondering if a fresh set of eyes can help fix. 我必须忽视一些非常愚蠢的东西,我想知道一双新鲜的眼睛是否可以帮助修复。 So in this problem, my text div that I have is suppose to float along side the image div, but it isn't working. 所以在这个问题中,我所拥有的文本div假设沿着图像div浮动,但它不起作用。

<div id="news-container">
    <div class="news-item">
        <div class="news-image" style="background:url('images/site/previewimage.png') no-repeat;">
            <img src="images/site/image-border.png" alt="" />
        </div>
        <div class="news-text">
            <h1>Latest News</h1>
            <h2><a href="#">"Almost, Maine" Tickets are now on sale!</a></h2>
            <p>Text blah blah blah.</p>
            <div class="linkbutton redlink"><a href="#">Read More</a></div>
        </div>
    </div>
</div>

And the CSS... 而CSS ......

#news-container {
    width:100%;
    margin:20px 0;
    float:left;
    position:relative;
    clear:both;
}
.news-item {
    width:960px;
    margin:auto;
    position:relative;
}
.news-image {
    height:210px;
    width:340px;
    margin-right:20px;
    position:relative;
    display:block;
    float:left;
}
.news-text {
    width:900px;
    display:block;
    position:relative;
}

Thank you for your help! 谢谢您的帮助!

It's not really working in Chrome and Firefox. 这不是真正的Chrome和Firefox的工作。

What's happening is, when you float an element, text within elements that surround the float (that are still in the document flow) will move aside for that float, however the container itself (in your case, .news-text still starts in the same left position. 发生的事情是,当你浮动一个元素时,围绕浮动元素的元素中的文本(仍然在文档流中)将移动到那个浮点数,但是容器本身(在你的情况下, .news-text仍然在相同的左侧位置。

If your text goes longer than the image, you will see the text fall to the same left starting position as your image. 如果文字比图像长,您会看到文字落在与图像相同的左起始位置。

To get a proper "hanging indent", you need to assign a width to .news-text that is the remainder of the width leftover by the image, and set a left margin to push it away from the image. 要获得正确的“悬挂缩进”,您需要为.news-text分配宽度,该宽度是图像剩余的宽度,并设置左边距以将其推离图像。 This will work in all browsers including IE 7. 这适用于包括IE 7在内的所有浏览器。

Preview in IE 7: http://fiddle.jshell.net/EqWA4/show/ 在IE 7中预览: http//fiddle.jshell.net/EqWA4/show/

To see the code: http://jsfiddle.net/EqWA4/ 要查看代码: http//jsfiddle.net/EqWA4/

.news-text {
    width:500px;
    margin-left: 365px;
    display:block;
    position:relative;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM