padding-block

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2021.

Thuộc tính CSS padding-blockthuộc tính viết tắt xác định padding logic đầu và cuối theo hướng block của một phần tử, ánh xạ sang các thuộc tính padding vật lý tùy thuộc vào chế độ viết, hướng và định hướng chữ của phần tử.

Try it

padding-block: 10px 20px;
writing-mode: horizontal-tb;
padding-block: 20px 40px;
writing-mode: vertical-rl;
padding-block: 5% 10%;
writing-mode: horizontal-tb;
padding-block: 2em 4em;
writing-mode: vertical-lr;
<section id="default-example">
  <div class="transition-all" id="example-element">
    <div class="box">
      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;
  unicode-bidi: bidi-override;
}

Các thuộc tính thành phần

Thuộc tính này là cách viết tắt cho các thuộc tính CSS sau:

Cú pháp

css
/* Giá trị <length> */
padding-block: 10px 20px; /* Độ dài tuyệt đối */
padding-block: 1em 2em; /* tương đối so với kích thước chữ */
padding-block: 10px; /* thiết lập cả giá trị đầu và cuối */

/* Giá trị <percentage> */
padding-block: 5% 2%; /* tương đối so với chiều rộng của khối chứa gần nhất */

/* Giá trị toàn cục */
padding-block: inherit;
padding-block: initial;
padding-block: revert;
padding-block: revert-layer;
padding-block: unset;

Thuộc tính padding-block có thể được chỉ định bằng một hoặc hai giá trị. Nếu chỉ định một giá trị, giá trị đó được dùng cho cả padding-block-startpadding-block-end. Nếu chỉ định hai giá trị, giá trị đầu tiên dùng cho padding-block-start và giá trị thứ hai dùng cho padding-block-end.

Giá trị

Thuộc tính padding-block nhận cùng các giá trị như thuộc tính padding-top.

Mô tả

Các giá trị padding được chỉ định bởi padding-block có thể tương đương với các thuộc tính padding-toppadding-bottom hoặc padding-rightpadding-left, tùy thuộc vào các giá trị được xác định cho writing-mode, directiontext-orientation.

Định nghĩa hình thức

Initial valueas each of the properties of the shorthand:
Applies toall elements, except table-row-group, table-header-group, table-footer-group, table-row, table-column-group and table-column
Inheritedno
Percentageslogical-width of containing block
Computed valueas each of the properties of the shorthand:
Animation typea length

Cú pháp hình thức

padding-block = 
<'padding-top'>{1,2}

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

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

Ví dụ

Thiết lập padding block cho văn bản dọc

HTML

html
<div>
  <p class="exampleText">Example text</p>
</div>

CSS

css
div {
  background-color: yellow;
  width: 120px;
  height: 120px;
}

.exampleText {
  writing-mode: vertical-rl;
  padding-block: 20px 40px;
  background-color: #c8c800;
}

Kết quả

Đặc tả

Specification
CSS Logical Properties and Values Module Level 1
# propdef-padding-block

Khả năng tương thích trình duyệt

Xem thêm