这里是浮动box
左边对象是浮动的,这里是采用margin-left来定位,这里的文本会离左边有3px的空白误差。
这里是浮动box,使用了* html #floatbox2 {margin-right: -3px;}解决3px bug左边对象是浮动的,这里是采用* html p.no3px{height:1%;margin-left: 0;},这里的文本会离左边没有了3px的空白误差。
IE/div浮动文本出现3px间距的bug产生的条件:当左边对象是浮动的,右边对象采用外补丁的左边距(margin-left:?px;)来定位,则右边对象内的文本会离左边有3px的空白误差。
CSS: #ie3px{float: left; width: 100px; height: 50px; background: #f60;} p.ie3px{margin: 0 0 0 100px; background: #333; text-align:left; color:#fff;} XHTML: <div id="ie3px">这里是浮动box</div> <p class="ie3px">左边对象是浮动的,这里是采用margin-left来定位,这里的文本会离左边有3px的空白误差。</p>IE/div浮动文本出现3px间距的bug解决方法: 利用hack *html div{}为IE单独写一个样式
* html #ieno3px{margin-right:-3px;} * html p.no3px{height:1%;margin-left: 0;} CSS: #ieno3px{float: left; width: 100px; height: 50px; background: #f60;} p.no3px{margin: 0 0 0 100px; background: #333; text-align:left; color:#fff;} * html #ieno3px{margin-right:-3px;} * html p.no3px{height:1%;margin-left: 0;} XHTML: <div id="ieno3px">这里是浮动box,使用了<span class="alt">* html #floatbox2 {margin-right: -3px;}</span>解决3px bug</div> <p class="no3px">左边对象是浮动的,这里是采用<span class="alt">* html p.no3px{height:1%;margin-left: 0;}</span>,这里的文本会离左边没有了3px的空白误差。</p> IE/浮动对象外补丁的双倍距离 这个元素,浮动左对齐(float:left),左侧外补丁(margin-left:50px;),在wrap层内,但在IE浏览器中Box1离左边的距离会是100px,而实际距离应是50px。当一个元素用于非float:none;的浮动状态时,IE下该元素既被视为块级元素,display:block; CSS: #box1{ margin-left:50px; float:left; background:#f60; width:200px;} XHTML: <div class="wrap"> <div id="box1">这个元素,浮动左对齐(float:left),左侧外补丁(margin-left:50px;),在wrap层内,但在IE浏览器中Box1离左边的距离会是100px,而实际距离应是50px。当一个元素用于非float:none;的浮动状态时,IE下该元素既被视为块级元素,display:block; </div> </div> 这是个拥有正确margin-left的元素,解决的办法就是,使浮动效果消失,这里采用了display:inline;原理可参阅on having layout。 CSS: #box2{ margin-left:50px; float:left; background:#f60; width:200px; display:inline ;} XHTML: <div class="wrap"> <div id="box2">这是个拥有正确margin-left的元素,解决的办法就是,使浮动效果消失,这里采用了display:inline;原理可参阅on having layout。</div> </div> [Ctrl+A 全选 注:引入外部Js需再刷新一下页面才能执行]