浮动垂直对齐和ie 7问题

发布于 2024-12-16 02:16:13 字数 1546 浏览 2 评论 0原文

我的浮动 div 工作起来就像一个魅力,直到我注意到两个最上面的浮动 div 的垂直对齐有一个小错误。

如果 div 高度不同,垂直对齐就会关闭,有人知道解决这个问题的方法吗?如果间距在底部但在顶部也没关系。

我的问题的 ASCII 图:

div1|annoyinggap
    |div2
    | 
____|____    
div3 div4
    |
    |
    |
____|____ 

同样在 IE 7 中,DIVS 仅显示在一列中,而不是一个漂亮的 2 x 2 网格?

相关问题: 2 x 2 div 网格使用 float with min -height

HTML/CSS:

<div class="boxContainerTop">
<div class="boxContainer">
  <div class="Section2R2CCol"></div>  
  <div class="Section2R2CCol"></div>  
  <div class="Section2R2CCol"></div>  
  <div class="Section2R2CCol"></div> 
</div>  
</div>

.boxContainerTop {
    float: left;
}

.boxContainer {
    border: 1px solid #BBC614;
    float: left;
    height: auto;
    margin-bottom: 10px;
    margin-left: 10px;
    margin-top: 2px;
    width: 950px;
}

.Section2R2CCol:after {
    clear: both;
    content: ".";
    display: block;
    float: left;
    height: 0;
    line-height: 0;
    visibility: hidden;
}

.Section2R2CCol {
    display: inline-block;
    height: auto;
    min-height: 125px;
    padding-top: 5px;
    width: 470px;
}

在有人提到它之前附注:是的,我们可以争论谁关心 IE 7 的历史,我的答案是网站的访问者使用 IE 7 来证明维护开发是合理的。任何新功能都是为 ie8/ie9 构建的。

根据要求: http://jsfiddle.net/yBMdc/ jsfiddle 测试用例。 css 实际上有所不同,抱歉,CSS 已在此处更新。

My floated divs worked like a charm, until I noticed a minor bug in the vertical alignment in the two top most floated divs.

The vertical alignment is off if the divs height is different does anyone know a fix for this? It wouldn't matter if the spacing was at the bottom but its at the top.

My ASCII diagram of the issue:

div1|annoyinggap
    |div2
    | 
____|____    
div3 div4
    |
    |
    |
____|____ 

Also in IE 7 the DIVS just show in one column rather than a nice 2 x 2 grid?

Related question: 2 x 2 div grid using float with min-height

HTML/CSS:

<div class="boxContainerTop">
<div class="boxContainer">
  <div class="Section2R2CCol"></div>  
  <div class="Section2R2CCol"></div>  
  <div class="Section2R2CCol"></div>  
  <div class="Section2R2CCol"></div> 
</div>  
</div>

.boxContainerTop {
    float: left;
}

.boxContainer {
    border: 1px solid #BBC614;
    float: left;
    height: auto;
    margin-bottom: 10px;
    margin-left: 10px;
    margin-top: 2px;
    width: 950px;
}

.Section2R2CCol:after {
    clear: both;
    content: ".";
    display: block;
    float: left;
    height: 0;
    line-height: 0;
    visibility: hidden;
}

.Section2R2CCol {
    display: inline-block;
    height: auto;
    min-height: 125px;
    padding-top: 5px;
    width: 470px;
}

On a side note before someone mentions it: Yes we can argue who care's about IE 7 its history, my answer is enough of the visitors to the website use ie 7 to justify maintaining development. Any new functionality is built for ie8/ie9.

As requested: http://jsfiddle.net/yBMdc/ jsfiddle test case. css actually varies apologies for this CSS has been updated here.

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

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

发布评论

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

评论(4

屌丝范 2024-12-23 02:16:14

确保您使用的是 DOCTYPE。

<!DOCTYPE html>

Make sure you are using a DOCTYPE.

<!DOCTYPE html>
樱娆 2024-12-23 02:16:14

只需修改,

.Section2R2CCol {
    display: inline-block;
    *float: left;
    height: auto;
    min-height: 125px;
    padding-top: 5px;
    width: 470px;
}

http://jsfiddle.net/yBMdc/3/

Just Modify,

.Section2R2CCol {
    display: inline-block;
    *float: left;
    height: auto;
    min-height: 125px;
    padding-top: 5px;
    width: 470px;
}

http://jsfiddle.net/yBMdc/3/

年华零落成诗 2024-12-23 02:16:13

我的浮动 div 就像一个魅力,直到我注意到一个小错误
两个最上面的浮动 div 中的垂直对齐。

vertical-align: top 添加到 .Section2R2CCol

此外,在 ie 7 中,div 仅显示在一列中,而不是漂亮的 2 x 2
网格?

display: inline-block 更改为:

display: inline-block;
*display: inline;
zoom: 1;

参见: http://jsfiddle.net/thirtydot/yBMdc/1/

My floated divs worked like a charm, untill I noticed a minor bug in
the verticle alignment in the two top most floated divs.

Add vertical-align: top to .Section2R2CCol.

Also in ie 7 the divs just show in one column rather than a nice 2 x 2
grid?

Change display: inline-block to:

display: inline-block;
*display: inline;
zoom: 1;

See: http://jsfiddle.net/thirtydot/yBMdc/1/

香橙ぽ 2024-12-23 02:16:13

您不能在 ie6-7 中的块元素上使用 display: inline-block。它仅适用于内联元素。您可能应该使用 float: left 浮动它们。

You can't use display: inline-block on block elements in ie6-7. It will only work with inline elements. You should probably just float them using float: left.

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