Movatterモバイル変換


[0]ホーム

URL:


previous  next  contents  properties  index  


16 Text

Contents

The properties defined in the following sections affect the visualpresentation of characters, spaces, words, and paragraphs.

16.1Indentation: the'text-indent' property

Name:text-indent
Value:<length> |<percentage> |inherit
Initial:0
Applies to:block containers
Inherited:yes
Percentages:refer to width of containing block
Media:visual
Computed value:the percentage as specified or the absolute length

This property specifies the indentation of the first line of textin a block container. More precisely, it specifies the indentation of thefirst box that flows into the block's firstline box. The box is indented withrespect to the left (or right, for right-to-left layout) edge of theline box. User agents must render this indentation as blank space.

'Text-indent' only affects a line if it is thefirst formatted line of anelement. For example, the first line of an anonymous block box is onlyaffected if it is the first child of its parent element.

Values have the following meanings:

<length>
The indentation is a fixed length.
<percentage>
The indentation is a percentage of the containingblock width.

The value of'text-indent' may be negative, butthere may be implementation-specific limits. If the value of'text-indent' is either negative orexceeds the width of the block, thatfirst box, described above,can overflow the block.The value of'overflow' will affectwhether such text that overflows the block is visible.

Example(s):

The following example causes a '3em' text indent.

p { text-indent: 3em }

Note: Since the 'text-indent' property inherits, when specified ona block element, it will affect descendant inline-block elements. For this reason, it is often wise to specify 'text-indent: 0' on elements that are specified 'display:inline-block'.

16.2Alignment: the'text-align' property

Name:text-align
Value:left | right | center | justify |inherit
Initial:a nameless value that acts as 'left' if 'direction' is 'ltr', 'right' if 'direction' is 'rtl'
Applies to:block containers
Inherited:yes
Percentages:N/A
Media:visual
Computed value:the initial value or as specified

This property describes how inline-level content of a blockcontainer is aligned. Valueshave the following meanings:

left, right, center, justify
Left, right, center, and justify text, respectively, as described inthe section on inline formatting.

A block of text is a stack oflineboxes. In the case of 'left', 'right' and 'center', this property specifieshow the inline-level boxes within each line box align with respect to the linebox's left and right sides; alignment is not with respect to theviewport. In the case of 'justify',this property specifies that the inline-level boxes are to be made flushwith both sides of the line box if possible, by expanding or contractingthe contents of inline boxes, else aligned as for the initialvalue. (See also'letter-spacing' and'word-spacing'.)

If an element has a computed value for 'white-space' of 'pre' or'pre-wrap', then neither the glyphs of that element's text content norits white space may be altered for the purpose of justification.

Note: CSS may add a way to justify text with'white-space: pre-wrap' in the future.

Example(s):

In this example, note that since'text-align' is inherited, allblock-level elements inside DIV elements with a class name of 'important' willhave their inline content centered.

div.important { text-align: center }

Note.The actual justification algorithm used depends on the user-agent and the language/script of the text.

Conforming user agents mayinterpret the value 'justify' as 'left' or 'right', depending onwhether the element's default writing direction is left-to-right orright-to-left, respectively.

16.3Decoration

16.3.1Underlining, overlining, striking, andblinking: the'text-decoration'property

Name:text-decoration
Value:none | [ underline || overline || line-through || blink ] |inherit
Initial:none
Applies to:all elements
Inherited:no (see prose)
Percentages:N/A
Media:visual
Computed value:as specified

This property describes decorations that are addedto the text of an element using the element's color.When specified on or propagated to an inline element, itaffects all the boxes generated by that element, and is furtherpropagated to any in-flow block-level boxes that split the inline (seesection 9.2.1.1).But, in CSS 2.2, it is undefined whether the decorationpropagates into block-level tables.For block containers that establish aninline formattingcontext, the decorations are propagated to an anonymous inlineelement that wraps all the in-flow inline-level children of the blockcontainer. For all other elements it is propagated to any in-flowchildren. Note that text decorations are not propagated to floatingand absolutely positioned descendants, nor to the contents of atomicinline-level descendants such as inline blocks and inline tables.

Underlines, overlines, and line-throughs are applied only to text(including white space, letter spacing, and word spacing): margins,borders, and padding are skipped.User agents must not render these text decorations on content that isnot text. For example, images and inline blocks must not be underlined.

Note. If an element E has both 'visibility:hidden' and 'text-decoration: underline', the underline is invisible(although any decoration of E's parentis visible.) However, CSS 2.2 does not specify if the underline is visible orinvisible in E's children:

<span> <span>  underlined or not? </span></span>

This is expected to be specified in level 3 of CSS.

The 'text-decoration' property on descendant elements cannot have anyeffect on the decoration of the ancestor. In determining the positionof and thickness of text decoration lines, user agents may consider thefont sizes of and dominant baselines of descendants, but must use thesame baseline and thickness on each line. Relatively positioning adescendant moves all text decorations affecting it along with thedescendant's text; it does not affect calculation of the decoration'sinitial position on that line.

Values have the following meanings:

none
Produces no text decoration.
underline
Each line of text is underlined.
overline
Each line of text has a line above it.
line-through
Each line of text has a line through the middle.
blink
Text blinks (alternates between visible and invisible).Conforming user agentsmay simply not blink the text. Note that not blinking the text is one technique to satisfycheckpoint 3.3 of WAI-UAAG.

The color(s) required for the text decoration must be derived from the'color' property value of the element on which 'text-decoration' is set. The color of decorations must remain the same even if descendant elements have different'color' values.

Some user agents have implemented text-decoration by propagating the decoration to the descendant elements as opposed to preserving a constant thickness and line position as described above. This was arguably allowed by the looser wording in CSS2. SVG1, CSS1-only, and CSS2-only user agents may implement the older model and still claim conformance to this part of CSS 2.2. (This does not apply to UAs developed after this specification was released.)

Example(s):

In the following example for HTML, the text content of all A elements acting as hyperlinks (whether visited or not) will be underlined:

a:visited,a:link { text-decoration: underline }

Example(s):

In the following style sheet and document fragment:

   blockquote { text-decoration: underline; color: blue; }   em { display: block; }   cite { color: fuchsia; }
   <blockquote>    <p>     <span>      Help, help!      <em> I am under a hat! </em>      <cite> —GwieF </cite>     </span>    </p>   </blockquote>

...the underlining for the blockquote element is propagated to an anonymous inline element that surrounds the span element, causing the text "Help, help!" to be blue, with the blue underlining from the anonymous inline underneath it, the color being taken from the blockquote element. The<em>text</em> in the em block is also underlined,as it is in an in-flow block to which the underline is propagated. The final line of text is fuchsia, but the underline underneath it is still the blue underline from the anonymous inline element.

Sample rendering of the above underline example

This diagram shows the boxes involved in the example above. The roundedaqua line represents the anonymous inline element wrapping the inlinecontents of the paragraph element, the rounded blue line representsthe span element, and the orange lines represent the blocks.

16.4Letter and word spacing: the'letter-spacing' and'word-spacing' properties

Name:letter-spacing
Value:normal |<length> |inherit
Initial:normal
Applies to:all elements
Inherited:yes
Percentages:N/A
Media:visual
Computed value:'normal' or absolute length

This property specifies spacing behavior betweentext characters. Values have the following meanings:

normal
The spacing is the normal spacing for the current font.This value allows the user agent to alter the spacebetween characters in order to justify text.
<length>
This value indicates inter-character spaceinaddition to the default space betweencharacters. Values may be negative, but there may beimplementation-specific limits. User agents may not further increase or decrease the inter-characterspace in order to justify text.

Character spacing algorithms are user agent-dependent.

Example(s):

In this example, the space between characters inBLOCKQUOTE elements is increased by '0.1em'.

blockquote { letter-spacing: 0.1em }

In the following example, the user agent is not permittedto alter inter-character space:

blockquote { letter-spacing: 0cm }   /* Same as '0' */

When the resultant space between two characters is not the same asthe default space, user agents should not useligatures.

Name:word-spacing
Value:normal |<length> |inherit
Initial:normal
Applies to:all elements
Inherited:yes
Percentages:N/A
Media:visual
Computed value:for 'normal' the value '0'; otherwise the absolute length

This property specifies spacing behavior between words.Values have the following meanings:

normal
The normal inter-word space, as defined by the current font and/ortheUA.
<length>
This value indicates inter-word spaceinaddition to the default space betweenwords. Values may be negative, but there may beimplementation-specific limits.

Word spacing algorithms are user agent-dependent. Word spacing isalso influenced by justification (see the'text-align' property).Word spacing affects each space (U+0020) and non-breaking space(U+00A0), left in the text after the white space processing rules havebeen applied. The effect of the property on other word-separatorcharacters is undefined. However general punctuation, characters withzero advance width (such as the zero with space U+200B) andfixed-width spaces (such as U+3000 and U+2000 through U+200A) are notaffected.

Example(s):

In this example, the word-spacing between each word in H1 elements isincreased by '1em'.

h1 { word-spacing: 1em }

16.5Capitalization: the'text-transform' property

Name:text-transform
Value:capitalize | uppercase | lowercase | none |inherit
Initial:none
Applies to:all elements
Inherited:yes
Percentages:N/A
Media:visual
Computed value:as specified

This property controls capitalization effects ofan element's text. Values have the following meanings:

capitalize
Puts the first character of each word in uppercase; other characters are unaffected.
uppercase
Puts all characters of each word in uppercase.
lowercase
Puts all characters of each word in lowercase.
none
No capitalization effects.

The actual transformation in each case is written languagedependent. See BCP 47 ([BCP47]) for ways to find the language ofan element.

Only characters belonging to "bicameral scripts"[UNICODE] areaffected.

Example(s):

In this example, all text in an H1 element is transformed to uppercasetext.

h1 { text-transform: uppercase }

16.6White space: the'white-space' property

Name:white-space
Value:normal | pre | nowrap | pre-wrap | pre-line |inherit
Initial:normal
Applies to:all elements
Inherited:yes
Percentages:N/A
Media:visual
Computed value:as specified

This property declares how white space inside the element ishandled. Values have the following meanings:

normal
This value directs user agents to collapse sequencesof white space, and break lines as necessary to fill line boxes.
pre
This value prevents user agents from collapsing sequencesof white space. Lines are only broken at preserved newline characters.
nowrap
This value collapses white space as for 'normal', but suppressesline breaks within text.
pre-wrap
This value prevents user agents from collapsing sequencesof white space. Lines are broken at preserved newline characters, and as necessary to fill line boxes.
pre-line
This value directs user agents to collapse sequences of whitespace. Lines are broken at preserved newline characters, and asnecessary to fill line boxes.

Newlines in the source can be represented by a carriage return(U+000D), a linefeed (U+000A) or both (U+000D U+000A) or by some othermechanism that identifies the beginning and end of document segments,such as the SGML RECORD-START and RECORD-END tokens. The CSS'white-space' processing model assumes all newlines have beennormalized to line feeds.UAs that recognize other newline representations must apply the whitespace processing rules as if this normalization has taken place. If nonewline rules are specified for the document language, each carriagereturn (U+000D) and CRLF sequence (U+000D U+000A) in the document textis treated as single line feed character.This default normalization rule also applies to generatedcontent.

UAs must recognize line feeds (U+000A) as newline characters. UAsmay additionally treat other forced break characters as newlinecharacters per UAX14.

Example(s):

The following examples show whatwhite space behavior is expectedfrom the PRE and P elements and the "nowrap" attribute in HTML.

pre        { white-space: pre }p          { white-space: normal }td[nowrap] { white-space: nowrap }

In addition, the effect of an HTML PRE element with thenon-standard "wrap" attribute is demonstrated by the following example:

pre[wrap]  { white-space: pre-wrap }

16.6.1The 'white-space' processing model

For each inline element (including anonymous inline elements), thefollowing steps are performed, treating bidi formatting characters as ifthey were not there:

  1. Each tab (U+0009), carriage return (U+000D), or space (U+0020) character surrounding a linefeed (U+000A) character is removed if 'white-space' is set to 'normal', 'nowrap', or 'pre-line'.
  2. If 'white-space' is set to 'pre' or 'pre-wrap', any sequence of spaces (U+0020) unbroken by an element boundary is treated as a sequence of non-breaking spaces. However, for 'pre-wrap', a line breaking opportunity exists at the end of the sequence.
  3. If 'white-space' is set to 'normal' or 'nowrap', linefeed characters are transformed for rendering purpose into one of the following characters: a space character, a zero width space character (U+200B), or no character (i.e., not rendered), according to UA-specific algorithms based on the content script.
  4. If 'white-space' is set to 'normal', 'nowrap', or 'pre-line',
    1. every tab (U+0009) is converted to a space (U+0020)
    2. any space (U+0020) following another space (U+0020) — even a space before the inline, if that space also has 'white-space' set to 'normal', 'nowrap' or 'pre-line' — is removed.

Then, the block container's inlines are laid out. Inlines are laidout, taking bidireordering into account, and wrapping as specified by the'white-space' property.When wrapping, line breaking opportunities are determined basedon the text prior to the white space collapsing steps above.

As each line is laid out,

  1. If a space (U+0020) at the beginning of a line has 'white-space' set to 'normal', 'nowrap', or 'pre-line', it is removed.
  2. All tabs (U+0009) are rendered as a horizontal shift that lines up the start edge of the next glyph with the next tab stop. Tab stops occur at points that are multiples of 8 times the width of a space (U+0020) rendered in the block's font from the block's starting content edge.
  3. If a space (U+0020) at the end of a line has 'white-space' set to 'normal', 'nowrap', or 'pre-line', it is also removed.
  4. If spaces (U+0020) or tabs (U+0009) at the end of a line have 'white-space' set to 'pre-wrap', UAs may visually collapse them.

Floated and absolutely-positioned elements do not introduce a linebreaking opportunity.

Note.CSS 2.2 does not fully define where line breaking opportunities occur.

16.6.2Example of bidirectionality with white space collapsing

Given the following markup fragment, taking special note of spaces (with varied backgrounds and borders for emphasis and identification):

      <ltr>A <rtl> B </rtl> C</ltr>

...where the<ltr> element represents a left-to-right embedding and the<rtl> element represents a right-to-left embedding, and assuming that the 'white-space' property is set to 'normal', the above processing model would result in the following:

This would leave two spaces, one after the A in the left-to-right embedding level, and one after the B in the right-to-left embedding level. This is then rendered according to the Unicode bidirectional algorithm, with the end result being:

     A  BC

Note that there are two spaces between A and B, and none between B and C. This can sometimes be avoided by using the natural bidirectionality of characters instead of explicit embedding levels. Also, it is good to avoid spaces immediately inside start and end tags, as these tend to do weird things when dealing with white space collapsing.

16.6.3Control and combining characters' details

Control characters other than U+0009 (tab), U+000A (line feed),U+0020 (space), and U+202x (bidi formatting characters) are treated ascharacters to render in the same way as any normal character.

Combining characters should be treated as part of the characterwith which they are supposed to combine. For example, :first-letterstyles the entire glyph if you have content like"o<span>&#x308;</span>"; it does not justmatch the base character.


previous  next  contents  properties  index  


[8]ページ先頭

©2009-2025 Movatter.jp