div 之间的间距
这就是我的问题的样子:
正如你所看到的,有 3 个图像(div),我想要't 删除每个 div 之间的黑色间距。
最重要的是,当我在 css 中放置以下内容时:
* {
padding: 0;
margin: 0;
}
然后它看起来很好:
问题是我不能在整个 html 中使用 padding: 0
和 margin: 0
,因为其他属性将会被破坏......
我尝试添加:<代码>填充:0和每个 div(图像)上的 margin: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");
}
我们将不胜感激所有的帮助尝试。
This is how my problem looks like:
As you can see, there are 3 images (divs), and I wan't to remove that black spacings between each divs.
The most important thing is that, when I place in my css the following:
* {
padding: 0;
margin: 0;
}
Then it looks fine:
The problem is that I can't use padding: 0
and margin: 0
for my whole html, because other attributes will be broken then...
I've tried to add: padding:0
and margin:0
on each div (image), but it not work.
HTML Source:
<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>
My 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");
}
All help attempts will be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可能是
ul
上的边距造成的。可能会达到想要的效果。
li
也可能会影响布局;但我们无法从您提供的代码中得知。您的“catch all”重置会删除默认的边距/填充;这就是为什么它看起来不错。
编辑 - 您的
.sb-title h3
可能还需要删除底部边距,因为看起来您使用的是固定高度(60px),但默认边距会增加额外的高度。这可以使用 firebug 或 Chrome 的 Web 检查器轻松调试,并提供间距来自何处的视觉指示。
It's likely the margin on the
ul
is causing this.may have the desired effect. The
li
might also be affecting the layout; but we can't tell from your provided code.Your "catch all" reset removes the default margin/padding; hence why it looks ok.
Edit - your
.sb-title h3
may also need the bottom margin removed as it looks like you are using a fixed height (60px) but the default margin would add extra height.This is easily debugged with firebug or Chrome's web inspector with the visual indications of where the spacing is coming from.
这是因为 UL 默认裕度。
你需要风格:
That's because of UL default margin.
You need style: