简体   繁体   English

IE7浮动左侧和堆叠问题

[英]IE7 float left and stacking problem

Quick question about floating elements left with IE7. 有关IE7留下的浮动元素的快速问题。 Basically I have some HTML like this 基本上我有一些像这样的HTML

<div><a href></a></div>
<div><a href></a></div>
<div><a href></a></div>
<div><a href></a></div>

The divs need to line up next to each other inline horizontally. div需要在水平方向内联排列。

Right now the divs are floated left and the anchor tags inside them have background images, width, height and display:block. 现在,div向左浮动,其中的锚标签有背景图像,宽度,高度和显示:块。

As of now it works in all browsers except IE6 + 7. In those two browsers everything is stacked on each other like a pile vertically. 截至目前,它适用于除IE6 + 7之外的所有浏览器。在这两个浏览器中,所有浏览器都像垂直堆叠一样堆叠在一起。 Is there a quick way to fix for IE? 是否有快速修复IE的方法? I only have access to the CSS file. 我只能访问CSS文件。 I cannot edit the HTML. 我无法编辑HTML。

try using this: 试着用这个:

zoom: 1; // IE hack to trigger hasLayout
*display: inline; // IE hack to achieve inline-block behavior
*float: none;

it will only be read by IE, it's a hack, but since you can't access the html, might work. 它只会被IE读取,这是一个黑客攻击,但由于你无法访问html,可能会有效。

Make sure you have the width of the parent container wrapping your divs that you are floating left. 确保您的父容器的宽度包裹您左侧浮动的div。 Also set the width of each div that is floating left and it should work. 同时设置左侧浮动的每个div的宽度,它应该工作。

<div id='wrap-it'>
    <div><a href></a></div>
    <div><a href></a></div>
    <div><a href></a></div>
    <div><a href></a></div>
</div>
<style>
    #wrap-it { width: 200px; }
    #wrap-it div { float: left; width: 50px; }
</style>

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

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