【问题标题】:Spacing between divsdiv之间的间距
【发布时间】:2011-11-09 17:52:45
【问题描述】:

这就是我的问题的样子:

如您所见,有 3 个图像(div),我不想删除每个 div 之间的黑色间距。

最重要的是,当我在我的 css 中放置以下内容时:

* {
padding: 0;
margin: 0;
}

然后它看起来很好:

问题是我的整个html不能使用padding: 0margin: 0,因为其他属性会被破坏......

我尝试在每个 div(图像)上添加:padding:0margin:0,但它不起作用。

HTML 源代码:

<div id="sidebar-left" class="sidebar" role="complementary">
       <div class="sb-ui sb-title"><h3>Account</h3></div>
       <div class="sb-con">
            <ul>
        <li><a href="index.php?subtopic=accountmanagement">My Account</a></li>
                <li><a href="index.php?subtopic=accountmanagement&action=logout">Logout</a></li>
            </ul>
       </div>
       <div class="sb-ui sb-end"></div>
</div>

我的 CSS:

#sidebar-left {
margin-right: 9px;
}

.sidebar {
width: 170px;
position: relative;
bottom: 7px;
}

.sidebar, #content {
float: left;
}

.sb-title {
height: 60px;
text-align: center;
}

.sb-ui {
background: url("../images/ui/sidebar_ui.png");
}

.sb-con {
background: url("../images/ui/sidebar_bgrepeat.jpg") repeat-y;
}

.sb-end {
height: 23px;
background-position: bottom center;
margin-bottom: 10px;
}

.sb-ui {
background: url("../images/ui/sidebar_ui.png");
}

我们将不胜感激所有帮助尝试。

【问题讨论】:

    标签: html spacing


    【解决方案1】:

    这可能是ul 上的边距造成的。

    .sb-con ul { padding:0; margin:0; }
    

    可能会产生预期的效果。 li 也可能会影响布局;但我们无法从您提供的代码中看出。

    您的“catch all”重置会删除默认边距/填充;因此它看起来还不错。

    编辑 - 您的 .sb-title h3 可能还需要移除底部边距,因为看起来您使用的是固定高度(60 像素),但默认边距会增加额外的高度。

    这很容易使用firebug 或 Chrome 的网络检查器进行调试,并带有间距来自何处的视觉指示。

    【讨论】:

    • &lt;ul&gt;&lt;h3&gt; 上的边距
    【解决方案2】:

    这是因为 UL 默认边距。 你需要风格:

    UL { margin: 0 }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-18
      • 1970-01-01
      • 2012-12-20
      • 1970-01-01
      • 1970-01-01
      • 2013-09-12
      相关资源
      最近更新 更多