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>
					

范例

Setting left padding using pixels and percentages

.content { padding-left: 5%; }
.sidebox { padding-left: 10px; }
					

规范

规范 状态 注释
CSS 基本 Box 模型
The definition of 'padding-left' in that specification.
工作草案 无变化。
CSS Level 2 (Revision 1)
The definition of 'padding-left' in that specification.
推荐 无变化。
CSS Level 1
The definition of 'padding-left' in that specification.
推荐 初始定义。

浏览器兼容性

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. 更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
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

图例

完整支持

完整支持

另请参阅

元数据

  • 最后修改: