Movatterモバイル変換


[0]ホーム

URL:


  1. 面向开发者的 Web 技术
  2. CSS:层叠样式表
  3. CSS 参考
  4. 属性
  5. padding-left

此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in EnglishAlways switch to English

padding-left

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.

padding-leftCSS 属性设置了元素左侧内边距区域的宽度。

尝试一下

padding-left: 1.5em;
padding-left: 10%;
padding-left: 20px;
padding-left: 1ch;
padding-left: 0;
<section>  <div>    <div>      Far out in the uncharted backwaters of the unfashionable end of the      western spiral arm of the Galaxy lies a small unregarded yellow sun.    </div>  </div></section>
#example-element {  border: 10px solid #ffc129;  overflow: hidden;  text-align: left;}.box {  border: dashed 1px;}

元素的内边距区域是其内容和边框之间的空间。

备注:通过padding 属性,只需一次声明,就可以为元素的所有四边设置内边距。

语法

css
/* <length> 值 */padding-left: 0.5em;padding-left: 0;padding-left: 2cm;/* <percentage> 值 */padding-left: 10%;/* 全局值 */padding-left: inherit;padding-left: initial;padding-left: revert;padding-left: revert-layer;padding-left: unset;

padding-left 属性可以从下面的列表中指定一个值。与 margin 不同,padding 不允许使用负值。

<length>

作为定值的内边距尺寸。必须是非负值。

<percentage>

相对于包含块的行内尺寸(水平语言中的宽度,由writing-mode 定义)的百分比。必须是非负值。

形式定义

初始值0
适用元素all elements, excepttable-row-group,table-header-group,table-footer-group,table-row,table-column-group andtable-column. It also applies to::first-letter and::first-line.
是否是继承属性
Percentagesrefer to the width of the containing block
计算值the percentage as specified or the absolute length
动画类型alength

形式语法

padding-left =
<length-percentage [0,∞]>

<length-percentage> =
<length>|
<percentage>

示例

使用像素和百分比值设置左内边距

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

规范

Specification
CSS Box Model Module Level 3
# padding-physical

浏览器兼容性

参见

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2026 Movatter.jp