为什么固定位置元素的静态定位子元素会增加宽度?
更新:
如果我将 ul
替换为 ,这似乎只是
并删除 ul
/li
的问题>divli
并将相关样式应用到 a
上,这样就可以了。 ID' 仍然想知道为什么 ul
/li
结构会出现问题,因为边距/填充已被显式重置。
我在处理 IE7 中固定位置元素的子元素时遇到了一些麻烦。它们似乎从某个地方获得了宽度/边距/填充,但我无法辨别在哪里或如何修复它。
您可以在 jsFiddle 中查看它。我添加了背景颜色只是为了调试。 image/li 标签应与黄色齐平,并且在 IE8、mozilla 和 webkit 中都存在。但在 IE7 中,左侧有一个额外的约 20px 的空间将它们推倒,就好像 li
、a
或 img
标签有一个边距。但是,如果我查看 IEDevToolbar 中的属性,则没有应用边距或填充。此外,即使我为所有元素分配宽度并使用 IEDevToolbar 直接在每个元素上将边距/填充归零,也会发生这种情况。
我对这个完全迷失了。
下面是相关代码...相关布局上有一个 XHTML 1.0 Transitional 文档类型:
<style type="text/css">
.social-widgets {
position: fixed;
top: 125px;
left: 0px;
background: #f00;
width: 34px;
}
.social-widgets-content {
list-style: none inside none;
margin: 0;
padding: 0;
text-align: left;
background: #ff0;
}
.social-widgets-content li {
margin: 10px 0 !important;
padding:0;
width: 34px;
background: #0f0;
}
.social-widgets-content img {
display:block;
border-top: 2px solid #e9e8e8;
border-bottom: 2px solid #e9e8e8;
border-right: 2px solid #e9e8e8;
padding: 0px; margin:0px;
background: #00f;
}
</style>
<div class="social-widgets">
<ul class="social-widgets-content">
<li><a href="#"><img src="/images/button/button.facebook.png"></a></li>
<li><a href="#"><img src="/images/button/button.twitter.png"></a></li>
<li><a href="#"><img src="/images/button/button.feedback.png"></a></li>
</ul>
</div> <!-- /.social-widgets -->
UPDATE:
This seem to only be an issue with ul
/li
if i replace the ul
with a div
and remove the li
and apply the relevant style to the a
's instead its fine. ID' still liek to know why the ul
/li
structure presents a problem since margin/padding have been reset explicitly.
Im having soem trouble with the children of a fixed position element in IE7. They seem to be gaining width/margin/padding from somewhere but I cant discern where or how to fix it.
You can take a look at it in jsFiddle here. Ive added the bg colors just for debugging. The image/li tags should be flush with they yellow, and are in IE8 as well as mozilla and webkit. But in IE7 there is an extra ~20px of space to the left pushing them over, as if the li
, a
, or img
tags had a margin. However, if i look through the properties in IEDevToolbar there is no margin or padding being applied. Futhermore, this happens even if i assign widths to everything and zero out margin/padding directly on each element with IEDevToolbar.
I'm totally lost on this one.
Below is the relevent code... There is a XHTML 1.0 Transitional doctype on the layout in question:
<style type="text/css">
.social-widgets {
position: fixed;
top: 125px;
left: 0px;
background: #f00;
width: 34px;
}
.social-widgets-content {
list-style: none inside none;
margin: 0;
padding: 0;
text-align: left;
background: #ff0;
}
.social-widgets-content li {
margin: 10px 0 !important;
padding:0;
width: 34px;
background: #0f0;
}
.social-widgets-content img {
display:block;
border-top: 2px solid #e9e8e8;
border-bottom: 2px solid #e9e8e8;
border-right: 2px solid #e9e8e8;
padding: 0px; margin:0px;
background: #00f;
}
</style>
<div class="social-widgets">
<ul class="social-widgets-content">
<li><a href="#"><img src="/images/button/button.facebook.png"></a></li>
<li><a href="#"><img src="/images/button/button.twitter.png"></a></li>
<li><a href="#"><img src="/images/button/button.feedback.png"></a></li>
</ul>
</div> <!-- /.social-widgets -->
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这与
position:fixed;
无关。这是列表样式的问题。当使用list-style: none inside none;
时,尽管标记设置为none
,IE7 仍会为列表标记添加间距。解决方案是设置list-style-type: none;
而不是使用简写。This has nothing to do with
position:fixed;
. It was an issue with the list styling. When usinglist-style: none inside none;
IE7 still adds the spacing for the list-marker despite the marker being set tonone
. The solution was to setlist-style-type: none;
instead of using the shorthand.