CSS 中的 padding 简写属性
CSS 中的 padding 属性允许您设置 padding-top、padding-right、padding-bottom、padding-left 的内边距。它是一个简写属性。
例如
padding:10px 5px 7px 10px;
这里:
上内边距为 10px
右内边距为 5px
下内边距为 7px
左内边距为 10px
语法
CSS padding 属性的语法如下:
Selector {
padding: /*value*/
}
值可以是:
padding-top
padding-right
padding-bottom
padding-left
以下示例说明了 CSS padding 简写属性:
包含所有值的 padding 属性
包含所有值的 padding 属性设置顶部、右侧、底部和左侧属性的值:
padding: 35px 70px 50px 40px;
示例
让我们看看这个例子:
<!DOCTYPE html>
<html>
<head>
<style>
p.demo {
border: 2px solid blue;
padding: 35px 70px 50px 40px;
}
</style>
</head>
<body>
<h1>Demo Heading</h1>
<p>This is a demo text.</p>
<p class="demo">This is another demo text.</p>
<p>Another demo text</p>
<h2>Demo Heading2</h2>
<p>Demo text</p>
</body>
</html>
包含三个值的 padding 属性
padding 属性包含三个值。上内边距为 35px。左和右属性为 70px。下内边距为 50px:
padding: 35px 70px 50px;
示例
让我们看看这个例子:
<!DOCTYPE html>
<html>
<head>
<style>
p.demo {
border: 2px solid blue;
padding: 35px 70px 50px;
}
</style>
</head>
<body>
<h1>Demo Heading</h1>
<p>This is a demo text.</p>
<p class="demo">This is another demo text.</p>
<p>Another demo text</p>
<h2>Demo Heading2</h2>
<p>Demo text</p>
</body>
</html>
包含两个值的 padding 属性
padding 属性包含两个值,即顶部和底部边距为 2em。左和右属性为 3em:
padding: 2em 3em;
示例
让我们看看这个例子:
<!DOCTYPE html>
<html>
<head>
<style>
div {
height: 150px;
width: 300px;
padding: 5% 10% 20% 5%;
background-image: url("https://tutorialspoint.com/images/home_tensor_flow.png");
text-align: center;
font-weight: bold;
font-size: 1.2em;
box-sizing: border-box;
}
div > div {
border-radius: 80px;
padding: 2em 3em;
box-shadow: 0 0 4px 0.8px black;
}
</style>
</head>
<body>
<div>Learn TensorFlow
<div>TensorFlow is an open source machine learning framework for all developers.</div>
</div>
</body>
</html>
包含单个值的 padding 属性
padding 属性包含单个值,即所有 padding 属性都设置为 2em:
padding: 2em;
示例
让我们看看这个例子:
<!DOCTYPE html>
<html>
<head>
<style>
div {
height: 150px;
width: 100px;
padding: 5% 1%;
background-color: papayawhip;
border-radius: 5%;
box-sizing: border-box;
}
div > div {
width: 50px;
height: 50px;
border-radius: 50%;
padding: 2em;
box-shadow: 0 0 9px 1px black;
}
span {
padding: 10px;
}
</style>
</head>
<body>
<div>
<div></div>
<span><i>button</i></span>
</div>
</body>
</html>
广告
数据结构
网络
关系数据库管理系统 (RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP