diff options
| author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:43:23 -0500 |
|---|---|---|
| committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:43:23 -0500 |
| commit | 218934fa2ed1c702a6d3923d2aa2cc6b43c48684 (patch) | |
| tree | a9ef8ac1e1b8fe4207b6d64d3841bfb8990b6fd0 /files/zh-tw/web/css/css_box_model | |
| parent | 074785cea106179cb3305637055ab0a009ca74f2 (diff) | |
| download | translated-content-218934fa2ed1c702a6d3923d2aa2cc6b43c48684.tar.gz translated-content-218934fa2ed1c702a6d3923d2aa2cc6b43c48684.tar.bz2 translated-content-218934fa2ed1c702a6d3923d2aa2cc6b43c48684.zip | |
initial commit
Diffstat (limited to 'files/zh-tw/web/css/css_box_model')
| -rw-r--r-- | files/zh-tw/web/css/css_box_model/index.html | 167 | ||||
| -rw-r--r-- | files/zh-tw/web/css/css_box_model/mastering_margin_collapsing/index.html | 107 |
2 files changed, 274 insertions, 0 deletions
diff --git a/files/zh-tw/web/css/css_box_model/index.html b/files/zh-tw/web/css/css_box_model/index.html new file mode 100644 index 0000000000..cb4dd91343 --- /dev/null +++ b/files/zh-tw/web/css/css_box_model/index.html @@ -0,0 +1,167 @@ +--- +title: CSS Box Model +slug: Web/CSS/CSS_Box_Model +tags: + - CSS + - CSS Box Model + - CSS Reference + - NeedsTranslation + - Overview + - TopicStub +translation_of: Web/CSS/CSS_Box_Model +--- +<div>{{CSSRef}}</div> + +<p><strong>CSS Box Model</strong> is a CSS module that defines the rectangular boxes, including their padding and margin, that are generated for elements and laid out according to the visual formatting model.</p> + +<h2 id="Reference">Reference</h2> + +<h3 id="Properties">Properties</h3> + +<h4 id="Properties_controlling_the_flow_of_content_in_a_box">Properties controlling the flow of content in a box</h4> + +<div class="index"> +<ul> + <li>{{cssxref("box-decoration-break")}}</li> + <li>{{cssxref("box-sizing")}}</li> + <li>{{cssxref("overflow")}}</li> + <li>{{cssxref("overflow-x")}}</li> + <li>{{cssxref("overflow-y")}}</li> +</ul> +</div> + +<h4 id="Properties_controlling_the_size_of_a_box">Properties controlling the size of a box</h4> + +<div class="index"> +<ul> + <li>{{cssxref("height")}}</li> + <li>{{cssxref("width")}}</li> + <li>{{cssxref("max-height")}}</li> + <li>{{cssxref("max-width")}}</li> + <li>{{cssxref("min-height")}}</li> + <li>{{cssxref("min-width")}}</li> +</ul> +</div> + +<h4 id="Properties_controlling_the_margins_of_a_box">Properties controlling the margins of a box</h4> + +<div class="index"> +<ul> + <li>{{cssxref("margin")}}</li> + <li>{{cssxref("margin-bottom")}}</li> + <li>{{cssxref("margin-left")}}</li> + <li>{{cssxref("margin-right")}}</li> + <li>{{cssxref("margin-top")}}</li> +</ul> +</div> + +<h4 id="Properties_controlling_the_paddings_of_a_box">Properties controlling the paddings of a box</h4> + +<div class="index"> +<ul> + <li>{{cssxref("padding")}}</li> + <li>{{cssxref("padding-bottom")}}</li> + <li>{{cssxref("padding-left")}}</li> + <li>{{cssxref("padding-right")}}</li> + <li>{{cssxref("padding-top")}}</li> +</ul> +</div> + +<h4 id="Other_properties">Other properties</h4> + +<div class="index"> +<ul> + <li>{{cssxref("box-shadow")}}</li> + <li>{{cssxref("visibility")}}</li> +</ul> +</div> + +<h2 id="Guides_and_tools">Guides and tools</h2> + +<dl> + <dt><a href="/en-US/docs/Web/CSS/CSS_Box_Model/Introduction_to_the_CSS_box_model">Introduction to the CSS box model</a></dt> + <dd>Explains one of the fundamental concept of CSS, the box model: describes the meaning of the margin, padding, as well as the different areas of a box.</dd> + <dt><a href="/en-US/docs/Web/CSS/CSS_Box_Model/Mastering_margin_collapsing">Mastering margin collapsing</a></dt> + <dd>In several cases, two adjacent margins are collapsed into one. This article describes when this is happening and how to control it.</dd> + <dt><a href="/en-US/docs/Web/CSS/CSS_Box_Model/Box-shadow_generator">Box-shadow generator</a></dt> + <dd>An interactive tool that allows to visually create shadows and to generate the needed syntax for the {{cssxref("box-shadow")}} property.</dd> +</dl> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName("CSS3 Box")}}</td> + <td>{{Spec2("CSS3 Box")}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName("CSS2.1", "box.html")}}</td> + <td>{{Spec2("CSS2.1")}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName("CSS1")}}</td> + <td>{{Spec2("CSS1")}}</td> + <td>Initial definition</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + +<p>{{CompatibilityTable}}</p> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>Basic support</td> + <td>1.0</td> + <td>{{CompatGeckoDesktop("1")}}</td> + <td>3.0</td> + <td>3.5</td> + <td>1.0 (85)</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support</td> + <td>1.0</td> + <td>{{CompatGeckoMobile("1")}}</td> + <td>6.0</td> + <td>6.0</td> + <td>1.0</td> + </tr> + </tbody> +</table> +</div> diff --git a/files/zh-tw/web/css/css_box_model/mastering_margin_collapsing/index.html b/files/zh-tw/web/css/css_box_model/mastering_margin_collapsing/index.html new file mode 100644 index 0000000000..be8ea00259 --- /dev/null +++ b/files/zh-tw/web/css/css_box_model/mastering_margin_collapsing/index.html @@ -0,0 +1,107 @@ +--- +title: 理解邊界重疊的原因 +slug: Web/CSS/CSS_Box_Model/Mastering_margin_collapsing +translation_of: Web/CSS/CSS_Box_Model/Mastering_margin_collapsing +--- +<div>{{CSSRef}}</div> + +<div>當一個 Block 的 <a href="/en-US/docs/Web/CSS/margin-bottom">下邊界範圍</a> ( margin-bottom ) 和一個 Block 的 <a href="/en-US/docs/Web/CSS/margin-top">上邊界範圍</a> ( margin-top ) 都有設定時只會留下最大那個,這種情況我們稱為<strong>邊界重疊</strong> ( margin collapsing )。請留意設定了 float 或<a href="https://developer.mozilla.org/en-US/docs/Web/CSS/position#absolute">絕對定位</a>的元件並不會產生邊界重疊。</div> + + + +<p>有三個標準情況會形成邊界重疊:</p> + +<dl> + <dt>同一層的相鄰</dt> + <dd>兩個相鄰的元素邊界就會發生重疊,除非後者有加上clear-fix。例如: + <pre class="brush: html notranslate"><style> + p:nth-child(1){ + margin-bottom: 13px; + } + p:nth-child(2){ + margin-top: 87px; + } +</style> + + <p>下邊界範圍會...</p> + <p>...跟這個元素的上邊界範圍重疊。</p> +</pre> + </dd> + <dd>如果邊界會合併的的話,理所當然會認為上例中的上下兩個元素會合成一個 100px 的邊界範圍。<br> + 但其實會發生重疊,而且只會留下最大的邊界範圍,以此例子來說,邊界範圍就是 87px。</dd> + <dt></dt> + <dt>父元素與第一個/最後一個子元素</dt> + <dd>如果第一個子元素跟父元素的上邊界範圍 ( margin-top ) 貼在一起,也會發生邊界重疊的情況。除非父元素有設定邊框 ( border ) 、 內距 ( padding )、內容設定為 inline 或是有加上 clear-fix,這些都會隔開子元素和父元素的屬性。<br> + 最後一個子元素也是,但是與父元素的下邊界範圍 ( margin-bottom ) 更容易被隔開,因為父元素可以設定這些屬性。例如:</dd> + <dd> + <pre class="brush: html notranslate"><style type="text/css"> + section { + margin-top: 13px; + margin-bottom: 87px; + } + + header { + margin-top: 87px; + } + + footer { + margin-bottom: 13px; + } +</style> + +<section> + <header>上邊界重疊是 87</header> + <footer>下邊界重疊還是 87 不能再高了</footer> +</section></pre> + </dd> + <dt>空的元素</dt> + <dd>當同一個元素上邊界範圍可以直接貼到下邊界範圍時,也會發生邊界重疊。這種情況會發生在一個元素完全沒有設定邊框 ( border ) 、 內距 ( padding )、高度 ( height ) 、最小高度 ( min-height ) 、最大高度 ( max-height ) 、內容設定為 inline 或是加上 clear-fix 的時候。例如:</dd> + <dd> + <pre class="brush: html notranslate"><style> + p { + margin: 0px; + } + div { + margin-top: 13px; + margin-bottom: 87px; + } +</style> + +<p>下邊界範圍是 87</p> +<div></div> +<p>...上邊界範圍也是 87。</p> +</pre> + </dd> +</dl> + +<p>上面這些情況是會同時發生的,那時邊界重疊的原因又更複雜了。</p> + +<p>比較特別的是,當計算的時候某些邊界範圍是負數,邊界重疊的結果會取最大值和最小值相加。舉例來說如果 -13px、8px 和 100px 疊在一起,邊界範圍的計算方法會是 100px - 13px 也就是 87px。</p> + +<p>以上這些內容都是發生在 Block-Level 的元素,設定 floating 和 absolutely positioned 的元素完全不用擔心邊界重疊的計算。</p> + +<h2 id="標準文件">標準文件</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName("CSS2.1", "box.html#collapsing-margins", "margin collapsing")}}</td> + <td>{{Spec2("CSS2.1")}}</td> + <td>Initial definition</td> + </tr> + </tbody> +</table> + +<h2 id="參考">參考</h2> + +<ul> + <li><a href="/en-US/docs/Web/CSS/CSS_Reference">CSS Reference</a></li> + <li>{{css_key_concepts}}</li> +</ul> |
