aboutsummaryrefslogtreecommitdiff
path: root/files/zh-tw/web/css/_colon_first-child/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-tw/web/css/_colon_first-child/index.html')
-rw-r--r--files/zh-tw/web/css/_colon_first-child/index.html154
1 files changed, 154 insertions, 0 deletions
diff --git a/files/zh-tw/web/css/_colon_first-child/index.html b/files/zh-tw/web/css/_colon_first-child/index.html
new file mode 100644
index 0000000000..195449ca3d
--- /dev/null
+++ b/files/zh-tw/web/css/_colon_first-child/index.html
@@ -0,0 +1,154 @@
+---
+title: ':first-child'
+slug: 'Web/CSS/:first-child'
+tags:
+ - CSS
+ - CSS Pseudo-class
+ - Layout
+ - Reference
+ - Web
+translation_of: 'Web/CSS/:first-child'
+---
+<div>{{CSSRef}}</div>
+
+<p><code>:first-child</code>是<a href="/en-US/docs/Web/CSS">CSS</a>當中的一種<a href="/en-US/docs/Web/CSS/Pseudo-classes">偽類別(pseudo-class)</a>,代表任何身為長子的元素(親元素的第一個子元素)。</p>
+
+<h2 id="語法">語法</h2>
+
+<pre class="syntaxbox">{{csssyntax}}
+</pre>
+
+<h2 id="範例">範例</h2>
+
+<h3 id="範例_1">範例 1</h3>
+
+<h4 id="HTML_內文">HTML 內文</h4>
+
+<pre class="brush: html">&lt;div&gt;
+ &lt;span&gt;This span is limed!&lt;/span&gt;
+ &lt;span&gt;This span is not. :(&lt;/span&gt;
+&lt;/div&gt;
+</pre>
+
+<h4 id="CSS_內文">CSS 內文</h4>
+
+<pre class="brush: css">span:first-child {
+ background-color: lime;
+}
+</pre>
+
+<p>呈現效果如下:</p>
+
+<p><span>{{EmbedLiveSample('範例_1',300,50)}}</span></p>
+
+<h3 id="範例_2_-_使用_UL">範例 2 - 使用 UL</h3>
+
+<h4 id="HTML_內文_2">HTML 內文</h4>
+
+<pre class="brush: html">&lt;ul&gt;
+ &lt;li&gt;List 1&lt;/li&gt;
+ &lt;li&gt;List 2&lt;/li&gt;
+ &lt;li&gt;List 3&lt;/li&gt;
+&lt;/ul&gt;</pre>
+
+<h4 id="CSS_內文_2">CSS 內文</h4>
+
+<pre class="brush: css">li{
+ color:red;
+}
+li:first-child{
+ color:green;
+}</pre>
+
+<p>呈現效果如下:</p>
+
+<p><span>{{EmbedLiveSample('範例_2_-_使用_UL',300,100)}}</span></p>
+
+<h2 id="規格">規格</h2>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">規格</th>
+ <th scope="col">狀態</th>
+ <th scope="col">註解</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{SpecName('CSS4 Selectors', '#first-child-pseudo', ':first-child')}}</td>
+ <td>{{Spec2('CSS4 Selectors')}}</td>
+ <td>無變更</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('CSS3 Selectors', '#first-child-pseudo', ':first-child')}}</td>
+ <td>{{Spec2('CSS3 Selectors')}}</td>
+ <td>無變更</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('CSS2.1', 'selector.html#first-child', ':first-child')}}</td>
+ <td>{{Spec2('CSS2.1')}}</td>
+ <td>初始定義</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="瀏覽器相容性">瀏覽器相容性</h2>
+
+<p>{{CompatibilityTable}}</p>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>功能</th>
+ <th>Chrome</th>
+ <th>Firefox (Gecko)</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari</th>
+ </tr>
+ <tr>
+ <td>基礎支援</td>
+ <td>4.0</td>
+ <td>{{CompatGeckoDesktop("1.9")}}</td>
+ <td>7<sup>[1]</sup></td>
+ <td>9.5</td>
+ <td>4</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>功能</th>
+ <th>Android</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>IE Mobile</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ </tr>
+ <tr>
+ <td>基礎支援</td>
+ <td>1.0</td>
+ <td>{{CompatGeckoMobile("1.9.1")}}</td>
+ <td>7<sup>[1]</sup></td>
+ <td>10.0</td>
+ <td>3.1</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<p>[1] 在不重新載入網頁的情況下,Internet Explorer 7 的樣式表並不會套用在動態新增的元素上。在 Internet Explorer 8,若元素是以點擊連結而形成的,則 <code>first-child</code> 在該連結不被選取後才有作用。</p>
+
+<h2 id="參見">參見</h2>
+
+<ul>
+ <li>{{cssxref(":last-child")}}</li>
+ <li>{{cssxref(":nth-child")}}</li>
+ <li>{{cssxref(":last-of-type")}}</li>
+</ul>