box-pack

非標準:此特性未標準化。我們不建議在生產環境中使用非標準特性,因為它們瀏覽器支援有限,並且可能會更改或被移除。但是,在沒有標準選項的特定情況下,它們可以是合適的替代方案。

已棄用:此特性不再推薦。雖然某些瀏覽器可能仍然支援它,但它可能已經從相關的網路標準中刪除,可能正在刪除過程中,或者可能僅為相容性目的而保留。請避免使用它,如果可能,請更新現有程式碼;請參閱本頁底部的相容性表格以指導您的決策。請注意,此特性可能隨時停止工作。

警告: 這是原始 CSS 彈性盒佈局模組草案的屬性,已被更新的標準取代。有關當前標準的資訊,請參閱彈性盒

-moz-box-pack-webkit-box-pack CSS 屬性指定 -moz-box-webkit-box 如何在其佈局方向上打包其內容。只有當盒模型中有多餘空間時,其效果才可見。

佈局方向取決於元素的朝向:水平或垂直。

語法

css
/* Keyword values */
box-pack: start;
box-pack: center;
box-pack: end;
box-pack: justify;

/* Global values */
box-pack: inherit;
box-pack: initial;
box-pack: unset;

box-pack 屬性指定為下面列出的關鍵字值之一。

start

盒模型將內容打包到起始位置,將所有多餘空間留在末尾。

center

盒模型將內容打包到中心,將所有多餘空間平均分配到起始位置和末尾。

end

盒模型將內容打包到末尾,將所有多餘空間留在起始位置。

justify

空間在每個子元素之間均勻分配,第一個子元素之前或最後一個子元素之後沒有多餘空間。如果只有一個子元素,則該值視為 start

注意

為了打包目的而指定的盒模型起始邊緣取決於盒模型的朝向和方向

  • 對於水平元素,起始是上邊緣。
  • 對於垂直元素,起始是左邊緣。
Normal Reverse
Horizontal left right
Vertical top bottom

與起始相對的邊緣被指定為末尾

如果使用元素的 pack 屬性設定打包,則樣式將被忽略。

正式定義

初始值start
應用於CSS display 值為 -moz-box-moz-inline-box-webkit-box-webkit-inline-box 的元素
繼承性
計算值同指定值
動畫型別離散

正式語法

box-pack = 
start |
center |
end |
justify

示例

box-pack 的示例

css
div.example {
  border-style: solid;

  display: -moz-box; /* Mozilla */
  display: -webkit-box; /* WebKit */

  /* Make this box taller than the children,
     so there is room for the box-pack */
  height: 300px;
  /* Make this box wide enough to show the contents
     are centered horizontally */
  width: 300px;

  /* Children should be oriented vertically */
  -moz-box-orient: vertical; /* Mozilla */
  -webkit-box-orient: vertical; /* WebKit */

  /* Align children to the horizontal center of this box */
  -moz-box-align: center; /* Mozilla */
  -webkit-box-align: center; /* WebKit */

  /* Pack children to the bottom of this box */
  -moz-box-pack: end; /* Mozilla */
  -webkit-box-pack: end; /* WebKit */
}

div.example p {
  /* Make children narrower than their parent,
     so there is room for the box-align */
  width: 200px;
}
html
<div class="example">
  <p>I will be second from the bottom of div.example, centered horizontally.</p>
  <p>I will be on the bottom of div.example, centered horizontally.</p>
</div>

規範

不屬於任何標準。

瀏覽器相容性

另見