为什么固定位置元素的静态定位子元素会增加宽度?

发布于 2024-09-29 08:48:04 字数 1854 浏览 0 评论 0原文

更新:

如果我将 ul 替换为 ,这似乎只是 ul/li 的问题>div 并删除 li 并将相关样式应用到 a 上,这样就可以了。 ID' 仍然想知道为什么 ul/li 结构会出现问题,因为边距/填充已被显式重置。


我在处理 IE7 中固定位置元素的子元素时遇到了一些麻烦。它们似乎从某个地方获得了宽度/边距/填充,但我无法辨别在哪里或如何修复它。

您可以在 jsFiddle 中查看它。我添加了背景颜色只是为了调试。 image/li 标签应与黄色齐平,并且在 IE8、mozilla 和 webkit 中都存在。但在 IE7 中,左侧有一个额外的约 20px 的空间将它们推倒,就好像 liaimg 标签有一个边距。但是,如果我查看 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 技术交流群。

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

发布评论

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

评论(1

抚你发端 2024-10-06 08:48:04

这与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 using list-style: none inside none; IE7 still adds the spacing for the list-marker despite the marker being set to none. The solution was to set list-style-type: none; instead of using the shorthand.

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