padding-top

padding-top CSS 属性设置了元素顶部内边距区域的高度。

尝试一下

内边距区域是指一个元素的内容和边框之间的区域。

CSS padding-top 属性对元素盒子的影响

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

语法

css
/* <length> 值 */
padding-top: 0.5em;
padding-top: 0;
padding-top: 2cm;

/* <percentage> 值 */
padding-top: 10%;

/* 全局值 */
padding-top: inherit;
padding-top: initial;
padding-top: revert;
padding-top: revert-layer;
padding-top: unset;

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

<length>

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

<percentage>

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

形式定义

初始值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.
是否是继承属性
Percentagesrefer to the width of the containing block
计算值the percentage as specified or the absolute length
Animation typea length

形式语法

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

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

示例

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

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

规范

Specification
CSS Box Model Module Level 3
# padding-physical

浏览器兼容性

BCD tables only load in the browser

参见