padding-left
CSS 属性 padding-left
是指一个元素在内边距区域(padding area)中左边的宽度。内边距(padding)是指一个元素的内容和边框之间的区域。
尝试一下
元素的“填充区域”是其内容和边框之间的空间。
备注: padding
属性可用于通过一个声明在元素的四个边(上、下、左、右)上设置填充。
语法
css
/* 长度单位参数 */
padding-left: 0.5em;
padding-left: 0;
padding-left: 2cm;
/* 百分数参数 */
padding-left: 10%;
/* 全局参数 */
padding-left: inherit;
padding-left: initial;
padding-left: unset;
padding left
属性指定为从下表中选择的单个值。与外边距(margins)不同,可以接受的值不允许是负数。
参数
<length>
-
填充内边距的长度。它必须是非负的。
<percentage>
-
以与父级盒子的百分比表示的填充大小。它也必须是非负的。
标准定义
初始值 | 0 |
---|---|
适用元素 | all elements, except table-row-group , table-header-group , table-footer-group , table-row , table-column-group and table-column . It also applies to ::first-letter and ::first-line . |
是否是继承属性 | 否 |
Percentages | refer to the width of the containing block |
计算值 | the percentage as specified or the absolute length |
Animation type | a length |
标准语法
padding-left =
<length-percentage [0,∞]>
<length-percentage> =
<length> |
<percentage>
样例
使用“px”单位和百分比设置 padding-left 的样例
css
.content {
padding-left: 5%;
}
.sidebox {
padding-left: 10px;
}
规范
Specification |
---|
CSS Box Model Module Level 3 # padding-physical |
浏览器兼容性
BCD tables only load in the browser
另见
- Introduction to the CSS basic box model
padding-top
,padding-right
,padding-bottom
and thepadding
shorthand- The mapped logical properties:
padding-block-start
,padding-block-end
,padding-inline-start
, andpadding-inline-end
and the shorthandspadding-block
andpadding-inline