CSS属性 padding-left
是指一个元素在内边距区域(padding area)中左边的宽度。内边距(padding)是指一个元素的内容和边框之间的区域。
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
元素的“填充区域”是其内容和边框之间的空间。
贴士: padding
属性可用于通过一个声明在元素的四个边(上、下、左、右)上设置填充。
语法
/* 长度单位参数 */
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 |
标准语法
样例
使用“px”单位和百分比设置 padding-left的样例
.content { padding-left: 5%; }
.sidebox { padding-left: 10px; }
规范
规范版本 | 阶段 | 备注 |
---|---|---|
CSS Basic Box Model padding-left |
Working Draft | 没有改变 |
CSS Level 2 (Revision 1) padding-left |
Recommendation | 没有改变 |
CSS Level 1 padding-left |
Recommendation | 初始定义 |
浏览器兼容性
BCD tables only load in the browser
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
另见
- 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