为什么底部填充和底部边距无助于在这些链接之间添加垂直间距? [英] Why do bottom padding and bottom margins not help to add vertical spacing between these links?
问题描述
我有一个带有链接的div。我用< br>
标签将它们排列在一起,因为我无法弄清楚如何在CSS中添加垂直间距。我尝试在样式规则中添加底部边距和底部填充,但似乎没有任何效果(为什么?)。我可以添加另一个< br>
标记来分隔它们,但我必须假设有一种更好的方法来处理CSS,而我只是不能够
$ b $
<!DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Transitional // ENhttp: //www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
< html xmlns =http://www.w3.org/1999/xhtml>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = utf-8/>
< title>无标题文档< / title>
< style type =text / css>
html,body
{
height:100%;
保证金:0;
padding:0;
font-weight:normal;
font-size:12pt;
font-family:Verdana,Arial,Helvetica,serif,sans-serif;
background:lime;
}
#linksouter
{
margin:0;
padding:0;
border-style:solid;
border-width:0px;
位置:绝对;
top:0px;
left:0px;
width:80px;
背景:蓝色;
text-align:left;
}
#linksinner
{
margin:80px 0 0 .5em;
宽度:100%;
背景:紫红色;
display:inline;
身高:100%;
}
#linksinner a
{
color:red;
text-decoration:none;
背景:黄色;
}
< / style>
< / head>
< body>
< div id =linksouter>
< div id =linksinner>
< a href =#> 1< / a>< br />
< a href =#> 1< / a>< br />
< a href =#> 1< / a>< br />
< a href =#> 1< / a>< br />
< a href =#> 1< / a>< br />
< / div>
< / div>
< / body>
< / html>
垂直边距和填充仅适用于块级元素 div
和 p
。 a
是一个内联元素,所以它不会工作。
为了做到你想要的,你需要添加以下样式到您的链接:
display:block;
只有这样才能正确应用顶部和底部的页边距和分页功能
编辑:如果你这样做,你也可以去掉< br />
标签
I have a div with links in it. And I'm lining them up one over the other with <br>
tags because I couldn't figure out how to add vertical spacingn with CSS. I tried adding a bottom margin and a bottom padding to the a style rule but it didn't seem to have any effect (why?). I could add another <br>
tag to separate them more but I have to assume there's a nicer way to do this with CSS that I just haven't been able to figure out.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
html, body
{
height: 100%;
margin: 0;
padding: 0;
font-weight:normal;
font-size:12pt;
font-family: Verdana, Arial, Helvetica, serif, sans-serif;
background:lime;
}
#linksouter
{
margin: 0;
padding: 0;
border-style:solid;
border-width:0px;
position:absolute;
top: 0px;
left: 0px;
width: 80px;
background: blue;
text-align:left;
}
#linksinner
{
margin: 80px 0 0 .5em;
width:100%;
background:fuchsia;
display:inline;
height:100%;
}
#linksinner a
{
color:red;
text-decoration: none;
background:yellow;
}
</style>
</head>
<body>
<div id="linksouter">
<div id="linksinner">
<a href="#">1</a><br />
<a href="#">1</a><br />
<a href="#">1</a><br />
<a href="#">1</a><br />
<a href="#">1</a><br />
</div>
</div>
</body>
</html>
Vertical margin and padding only works on block level elements like div
and p
. a
is an inline element so it wont work.
In order to do what you want you need to add the following style to your links:
display:block;
only then will margin and paging for top and bottom get applied correctly
EDIT: if you do it this way you can also get rid of the <br/>
tags
这篇关于为什么底部填充和底部边距无助于在这些链接之间添加垂直间距?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!