css设置 上下间距 的方法:1、使用“line-h ei ght:间距值;”样式来设置上下间距;2、使 用M arg in -t op和mar gin -bottom属性来设置上下间距;3、使用padding-top和padding-bottom属性来设置。
本教程操作环境:windows7系统、CSS3 && HT ML 5版、Dell G3 电 脑。
1、使用line-height属性设置上下间距
<!DOCTY PE html>
<html>
<head>
< ;m eta charset="utf-8">
<style type="text/css">
div{
width: 200px;
border: 1px solid red ;
}
. abc {
line-height: 50px;
}
</style>
</head>
<body>
<div >
<p>第一段</p>
<p>第二段</p>
<p>第三段</p>
<p>第四段</p>
</div>< br >
<div class="abc">
<p>第一段</p>
<p>第二段</p>
<p>第三段</p>
<p>第四段</p>
</div>
</body>
</html>效果图:
2、使用margin-top和margin-bottom属性来设置上下间距
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style type="text/css">
div{
width: 200px;
border: 1px solid red;
}
.abc p {
margin-top:50px;
margin-bottom:50px;
}
</style>
</head>
<body>
<div >
<p>第一段</p>
<p>第二段</p>
<p>第三段</p>
<p>第四段</p>
</div><br>
<div class="abc">
<p>第一段</p>
<p>第二段</p>
<p>第三段</p>
<p>第四段</p>
</div>
</body>
</html>效果图:
【推荐教程:CSS视频教程 、html视频教程】
3、使用padding-top和padding-bottom属性来设置上下间距
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style type="text/css">
div{
width: 200px;
border: 1px solid red;
}
.abc p {
padding-top:30px;
padding-bottom:30px;
}
</style>
</head>
<body>
<div >
<p>第一段</p>
<p>第二段</p>
<p>第三段</p>
<p>第四段</p>
</div><br>
<div class="abc">
<p>第一段</p>
<p>第二段</p>
<p>第三段</p>
<p>第四段</p>
</div>
</body>
</html>效果图:
更多编程相关知识,请访问:编程视频!!
以上就是css上下间距怎么设置的详细内容,更多请关注其它相关 文章 !
总结
以上是 为你收集整理的 css上下间距怎么设置 全部内容,希望文章能够帮你解决 css上下间距怎么设置 所遇到的问题。
如果觉得 网站内容还不错, 推荐好友。
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did199474