IE6中如何对齐浮动

发布于 2024-09-03 06:26:49 字数 1528 浏览 3 评论 0原文

我在 IE6 中显示浮动段落和图像时遇到问题。不过,在 Opera 和 Firefox 中显示这些内容没有问题。我在一个容器内有三个 div。每个 div 都有自己的段落和图像,要么向左浮动,要么向右浮动。为了达到理想的布局,我在大多数段落和图像上设置了负边距。

以下是我对齐浮动的方法:

---- 容器的 CSS 代码 -----

.container {
clear:both;
background:url(images/content_bg.png) repeat-x scroll 0 0 transparent;
width:850px;
height:750px;
overflow:hidden; 
margin:0 auto;
}

----- 第一个 div 的 CSS 代码 -----

.row1 {
float:left;
width:790px;
height:460px;
margin:5px 0 0 40px;
}

.pic1 {
float:right;
height:460px;
width:382px;
margin:-100px -50px 0 -60px;
}

h2, p {
font-family:Arial, Helvetica, sans-serif;
}

.row1 p {
font-size:12px;
text-indent:20px;
font-weight:bold;
text-align:justify;
margin:-10px -25px 0 0;
position:relative;
}

---------- 代码第二个 div -------------

.ro2 {
float:left;
width:790px;
height:234px;
margin:-185px 0 0 28px;
position:relative;
}

.row2 p {
float:right;
font-size:12px;
font-weight:bold;
text-align:justify;
text-indent:20px;
margin:-195px 258px 0 175px;
position:relative;
}

.pic2 {
float:left;
}

--------- 第三个 div 的代码 ---------------

.row3 {
float:left;
width:790px;
height:203px;
margin:-10px 0 0 40px;
position:relative;
}


.row3 p {
float:left;
font-size:12px;
font-weight:bold;
text-indent:20px;
text-align:justify;
margin:-180px 265px 0 10px;
position:relative;
}

.pic3 {
float:right;
}

div 的高度(.row1 到 .row3)基于图像的高度,以便 div 可以同时包含段落和图片。在 IE6 中查看时,这些段落似乎与图像相距很远。有些段落与其他图像重叠。

I am having problems displaying floated paragraphs and images in IE6. There was no problem displaying those in Opera and Firefox,though. I have three divs inside a container. Each div has its own paragraph and image either floated to the left or right. In order for me to achieve a desired layout, I set negative margins on most of the paragraphs and images.

Here is how I aligned the floats:

---- CSS code for the container -----

.container {
clear:both;
background:url(images/content_bg.png) repeat-x scroll 0 0 transparent;
width:850px;
height:750px;
overflow:hidden; 
margin:0 auto;
}

----- CSS code for the first div -----

.row1 {
float:left;
width:790px;
height:460px;
margin:5px 0 0 40px;
}

.pic1 {
float:right;
height:460px;
width:382px;
margin:-100px -50px 0 -60px;
}

h2, p {
font-family:Arial, Helvetica, sans-serif;
}

.row1 p {
font-size:12px;
text-indent:20px;
font-weight:bold;
text-align:justify;
margin:-10px -25px 0 0;
position:relative;
}

----------- code for the 2nd div -------------

.ro2 {
float:left;
width:790px;
height:234px;
margin:-185px 0 0 28px;
position:relative;
}

.row2 p {
float:right;
font-size:12px;
font-weight:bold;
text-align:justify;
text-indent:20px;
margin:-195px 258px 0 175px;
position:relative;
}

.pic2 {
float:left;
}

--------- code for the 3rd div ---------------

.row3 {
float:left;
width:790px;
height:203px;
margin:-10px 0 0 40px;
position:relative;
}


.row3 p {
float:left;
font-size:12px;
font-weight:bold;
text-indent:20px;
text-align:justify;
margin:-180px 265px 0 10px;
position:relative;
}

.pic3 {
float:right;
}

The divs' height ( .row1 to .row3) are based on the images' heights so that the div can contain both the paragraphs and the pictures. The paragraphs seem to be far away from the images when viewed in IE6. Some paragraphs are overlapping with other images.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

国产ˉ祖宗 2024-09-10 06:26:49

IE6 不支持它,并且包含许多“错误”...您应该为 IE7 及更高版本进行开发...

关于您的 css:

您正在使用position:relative;但不设置任何坐标,IE6不喜欢这样,尝试删除它!

您没有显示所有类的应用位置,某些 HTML 标签与 IE6 中的边距不兼容,请尝试使用填充。

在 IE6 中良好工作的一个好方法是使用 table 而不是 div,但 div 工作得很好,如下所示:

<div class="container" style="width:800px;">

  <div class="block" style="width:750px;margin:0 auto;">
    <div class="img_container" style="float:left;width:350px;"></div>
    <div class="txt_container" style="float:right;width:400px;"></div>
  </div>

  <div class="block" style="width:750px;margin:0 auto;">
    <div class="img_container" style="float:left;width:350px;"></div>
    <div class="txt_container" style="float:right;width:400px;"></div>
  </div>

  <div class="block" style="width:750px;margin:0 auto;">
    <div class="img_container" style="float:left;width:350px;"></div>
    <div class="txt_container" style="float:right;width:400px;"></div>
  </div>

</div>

这是一个示例,只是为了说明 IE6 应该将文本和图像包装在 div 中,然后该 div是漂浮的那个...

希望它有帮助...

IE6 it's not supported and contains many "bugs"... you should be developing for IE7 and above...

regarding your css:

you're using position:relative; but not setting any coordinates, IE6 doesn't like that, try removing it!

You don't show where all of does classes are applied, some HTML tags don't go well with margin in IE6, try using padding instead.

a good way for you to work well in IE6 is to use table instead of div, but div works just fine like this:

<div class="container" style="width:800px;">

  <div class="block" style="width:750px;margin:0 auto;">
    <div class="img_container" style="float:left;width:350px;"></div>
    <div class="txt_container" style="float:right;width:400px;"></div>
  </div>

  <div class="block" style="width:750px;margin:0 auto;">
    <div class="img_container" style="float:left;width:350px;"></div>
    <div class="txt_container" style="float:right;width:400px;"></div>
  </div>

  <div class="block" style="width:750px;margin:0 auto;">
    <div class="img_container" style="float:left;width:350px;"></div>
    <div class="txt_container" style="float:right;width:400px;"></div>
  </div>

</div>

This is an example, just to illustrate that you should for IE6 wrap the text and images inside a div and that div is the one to float...

Hope it helps...

难忘№最初的完美 2024-09-10 06:26:49

IE6 有一个影响浮动的错误,它使边距是实际值的两倍。我敢打赌这就是问题所在,因为您设置了边距,并说“在 IE6 中查看时,这些段落似乎与图像相距甚远。某些段落与其他图像重叠。”

值得庆幸的是,有一个简单的解决方案 - 每当您设置浮动时,也设置“display:inline”。如果不会影响其他浏览器,并且会阻止 IE 6 将边距加倍。

请参阅 positioniseverything 的相关文章。请注意,您必须在 IE6 中查看页面才能使示例有意义。

IE6 has a bug affecting floats which makes margins double their actual value. I bet this is the issue, seeing as you have margins set, and said "The paragraphs seem to be far away from the images when viewed in IE6. Some paragraphs are overlapping with other images."

Thankfully, there is an easy fix for this - anytime you set a float, also set 'display:inline'. If won't affect other browsers, and will stop IE 6 from doubling the margins.

See positioniseverything's article on this. Note you have to view the page in IE6 for the examples to make sense.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文