::first-letter (:first-letter)
==============================

概要
--

`::first-letter` CSS 虛擬元素 (en-US)選取了一個區塊第一行的第一個字母，如果那一行前面沒有其他內容（例如圖片或是行內表格）。

The first letter of an element is not necessarily trivial to identify:

* Punctuation, that is any characters defined in Unicode in the *open* (Ps), *close* (Pe), *initial quote* (Pi), *final quote* (Pf) and *other punctuation* (Po) classes, preceding or immediately following the first letter is also matched by this pseudo-element.
* Similarly some languages have digraphs that are always capitalized together, like the `IJ` in Dutch. In these rare cases, both letters of the digraph should be matched by the `::first-letter` pseudo-element. (This is poorly supported by browsers, check the browser compatibility table (en-US)).
* Finally, a combination of the `::before` (en-US) pseudo-element and the `content` (en-US) property may inject some text at the beginning of the element. In that case, `::first-letter` will match the first letter of this generated content.

A first line has meaning only in a block-container box (en-US), therefore the `::first-letter` pseudo-element has an effect only on elements with a `display` (en-US) value of `block`, `inline-block`, `table-cell`, `list-item` or `table-caption`. In all other cases, `::first-letter` has no effect.

Only a small subset of all CSS properties can be used inside a declaration block of a CSS ruleset containing a selector using the `::first-letter` pseudo-element:

* All font properties : `font` (en-US), `font-style` (en-US), `font-feature-settings` (en-US), `font-kerning` (en-US), `font-language-override` (en-US), `font-stretch` (en-US), `font-synthesis` (en-US), `font-variant` (en-US), `font-variant-alternates` (en-US), `font-variant-caps` (en-US), `font-variant-east-asian` (en-US), `font-variant-ligatures` (en-US), `font-variant-numeric` (en-US), `font-variant-position` (en-US), `font-weight` (en-US), `font-size` (en-US), `font-size-adjust` (en-US), `line-height` (en-US) and `font-family` (en-US).
* All background properties : `background` (en-US), `background-color`, `background-image` (en-US), `background-clip` (en-US), `background-origin` (en-US), `background-position` (en-US), `background-repeat` (en-US), `background-size` (en-US), `background-attachment`, and `background-blend-mode` (en-US).
* All margin properties: `margin` (en-US), `margin-top` (en-US), `margin-right` (en-US), `margin-bottom` (en-US), `margin-left` (en-US).
* All padding properties: `padding` (en-US), `padding-top` (en-US), `padding-right` (en-US), `padding-bottom` (en-US), `padding-left` (en-US).
* All border properties: the shorthands `border` (en-US), `border-style` (en-US), `border-color`, `border-width` (en-US), `border-radius` (en-US), `border-image`, and the longhands properties.
* The `color` (en-US) property.
* The `text-decoration` (en-US), `text-shadow` (en-US), `text-transform` (en-US), `letter-spacing` (en-US), `word-spacing` (en-US) (when appropriate), `line-height` (en-US), `text-decoration-color` (en-US), `text-decoration-line` (en-US), `text-decoration-style` (en-US), `box-shadow`, `float` (en-US), `vertical-align` (en-US) (only if `float` is `none`) CSS properties.

As this list will be extended in the future, it is recommended that you not use any other properties inside the declaration block, in order to keep the CSS future-proof.

**備註：** In CSS 2, pseudo-elements were prefixed with a single colon character. As pseudo-classes were also following the same convention, they were indistinguishable. To solve this, CSS 2.1 changed the convention for pseudo-elements. Now a pseudo-element is prefixed with two colon characters, and a pseudo-class is still prefixed with a single colon.As several browsers already implemented the CSS 2 version in a release version, all browsers supporting the two-colon syntax also support the old one-colon syntax.If legacy browsers must be supported, `:first-letter` is the only viable choice; if not, `::first-letter` is preferred.

Example
-------

Make the first letter of every paragraph red and big.

### HTML Content


```html
<p>
  Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
  eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam
  voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita
  kasd gubergren, no sea takimata sanctus est. Lorem ipsum dolor sit amet. Lorem
  ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy amet.
</p>
<p>
  Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie
  consequat.
</p>
<p>
  Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit
  lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure
  dolor in hendrerit in vulputate velit esse molestie consequat, vel illum
  dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio
  dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te
  feugait nulla facilisi.
</p>
<p>-The beginning of a special punctuation mark.</p>
<p>_The beginning of a special punctuation mark.</p>
<p>"The beginning of a special punctuation mark.</p>
<p>'The beginning of a special punctuation mark.</p>
<p>*The beginning of a special punctuation mark.</p>
<p>#The beginning of a special punctuation mark.</p>
<p>「特殊的汉字标点符号开头。</p>
<p>《特殊的汉字标点符号开头。</p>
<p>“特殊的汉字标点符号开头。</p>
```

### CSS Content


```css
p::first-letter {
  /\* Use :first-letter if support for IE 8 or earlier is needed \*/
  color: red;
  font-size: 130%;
}
```

### Output

規範
--

| Specification |
| --- |
| CSS Pseudo-Elements Module Level 4 # first-letter-pseudo |

瀏覽器相容性
------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

參見
--

* `::first-line` (en-US) 虛擬元素。