padding-left
CSS
property sets the width of the
padding area
to the left of an element.
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.
An element's padding area is the space between its content and its border.
注意:
padding
property can be used to set paddings on all four sides of an element with a single declaration.
/* <length> values */ padding-left: 0.5em; padding-left: 0; padding-left: 2cm; /* <percentage> value */ padding-left: 10%; /* Global values */ padding-left: inherit; padding-left: initial; padding-left: unset;
padding-left
property is specified as a single value chosen from the list below. Unlike margins, negative values are not allowed for padding.
<length>
The size of the padding as a fixed value. Must be nonnegative.
<percentage>
The size of the padding as a percentage, relative to the width of the containing block. Must be nonnegative.
| 初始值 |
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
.
|
| 继承 | no |
| 百分比 | refer to the width of the containing block |
| 计算值 | the percentage as specified or the absolute length |
| 动画类型 | a length |
<length> | <percentage>
.content { padding-left: 5%; }
.sidebox { padding-left: 10px; }
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
padding-left
|
Chrome 完整支持 1 | Edge 完整支持 12 | Firefox 完整支持 1 | IE 完整支持 4 | Opera 完整支持 3.5 | Safari 完整支持 1 | WebView Android 完整支持 ≤37 | Chrome Android 完整支持 18 | Firefox Android 完整支持 4 | Opera Android 完整支持 14 | Safari iOS 完整支持 1 | Samsung Internet Android 完整支持 1.0 |
完整支持
padding-top
,
padding-right
,
padding-bottom
和
padding
简写
padding-block-start
,
padding-block-end
,
padding-inline-start
,和
padding-inline-end
and the shorthands
padding-block
and
padding-inline
height
margin-bottom
margin-left
margin-right
margin-top
margin-trim
max-height
max-width
min-height
min-width
overscroll-behavior
overscroll-behavior-block
overscroll-behavior-inline
overscroll-behavior-x
overscroll-behavior-y
padding
padding-bottom
padding-left
padding-right
padding-top
visibility
width