Cascading Style Sheets/Text
From WikiKnowledge
Contents |
[edit] letter-spacing
The letter-spacing property controls the amount of space between letters. Its values are:
| Value | Effect |
|---|---|
| normal | (Default) Use the default setting. |
| <length> | A length value setting the space between letters. |
| inherit | Inherit this setting. |
For example, to put 5 pixels of space between every letter you can use this code:
| Code | Result |
|---|---|
<span style="letter-spacing:5px;"> 5 pixels of space between every letter </span> |
5 pixels of space between every letter |
You can also use negative values to have letters come closer to each other. In this example you put -2 pixels of space between the letters.
| Code | Result |
|---|---|
<span style="letter-spacing:-2px;"> -2 pixels of space between every letter </span> |
-2 pixels of space between every letter |
[edit] word-spacing
This is similar to the letter-spacing property shown above except it controls the space between the words and not between the letters. Note that a "word" to CSS is any group of characters with white space around them, so this property will have no effect on languages such as Japanese which don't use spaces between words. Its values are the same as those used for the letter-spacing property:
| Value | Effect |
|---|---|
| normal | (Default) Use the default setting. |
| <length> | A length value setting the space between words. |
| inherit | Inherit this setting. |
In this example we will put 10 pixels of space between the words.
| Code | Result |
|---|---|
<span style="word-spacing:10px;"> 10 pixels of space between every word </span> |
10 pixels of space between every word |
Just as with the letter-spacing property, the word-spacing property can also take a negative values to reduce the amount of space between words.
| Code | Result |
|---|---|
<span style="word-spacing:-5px;"> -5 pixels of space between every word </span> |
-5 pixels of space between every word |
[edit] text-indent
This paragraph is 200 pixels wide and has a text-indent of 10%, making the text-indent 20 pixels.
This paragraph is 200 pixels wide and has a negative text-indent of 10% (-10%), making the text-indent 20 pixels outside its container.
This property allows you to indent the first line in a paragraph. Values are:
| Value | Description |
|---|---|
| <length> | Any length value. |
| <percentage> | The percentage of the containing block. |
| inherit | Inherit this setting. |
By setting this to a positive value, the paragraph will be indented. A negative value will cause the first line to over hang the paragraph. When using negative values, the text will hang outside its container, so you will need to make sure that there is space to the left of the paragraph for this text. As the text is overflowing the block it is affected by any settings made to the overflow property.
[edit] text-align
This allows you to control the alignment of text. Values are:
| left | (Default) Left align text. |
|---|---|
| right | Right align text. |
| center | Center text. |
| justify | Justify text. |
| inherit | Inherit this setting. |
These settings are the same as what you would find in a word processor. Left aligned text will line up to the left, right aligned text will line up to the right and centered text will be in the center. Justified text will line up to the left and right at the same time, this is done by changing the space between the words so that every sentence will end exactly on the right margin.
[edit] text-decoration
This property controls the underlining, strikethrough, overlining and blinking of text. Values are:
| none | This turns off all the other settings. |
|---|---|
| underline | This puts an underline under text. |
| overline | This puts an overline over text. |
| line-through | This puts a line through the text. |
| blink | This causes the text to blink. Internet Explorer does not support this setting. |
| inherit | Inherit this setting. |
It is possible to apply as many of the styles to a single bit of text as you want. For example to apply all of the styles to a single piece of text simply use this code:
| HTML | Example |
|---|---|
<span style="text-decoration: underline overline line-through blink; ">Example text</span> |
Example text |
The text-decoration of an element is drawn over the elements contents, including any child elements, and cannot be overriden by child elements. Example text with this part in red
[edit] text-transform
The text-transform property allows you to alter the case of text. Its values are:
| capitalize | Makes the first letter of every word uppercase. |
|---|---|
| uppercase | Make the text uppercase. |
| lowercase | Make the text lowercase. |
| none | Leave the capitalization the same as it appeared in the HTML/XML document. |
| inherit | Inherit this setting. |
You need to be careful when using the lowercase setting as some words in English need to be in uppercase. For example the sentence "Videos I like", will end up being displayed as "videos i like" even though the I should always be a capital I.
[edit] white-space
This property allows you to control what is done with the white space in a document. By default a browser will collapse extra spaces between words and ignore all line breaks. Values are:
| normal | (Default) Extra white space in the HTML document is ignored. |
|---|---|
| pre | All white space in the HTML document is kept. |
| nowrap | The text does not wrap to the next line unless a <br> tag is found. |
| inherit | Inherit this setting. |
Lots of unneeded spaces.
All of the extra spaces in the above sentence will normally be turned in to a single space when you view it in a web browser. Sometimes you may not want this to happen, such as when writing out example HTML code. In these situations, you can set the white-space property to pre to prevent the browser replacing the extra spaces.
| HTML | Example |
|---|---|
<span style="white-space: pre;">Lots of unneeded spaces.</span> | Lots of unneeded spaces. |
The nowrap setting tells the browser not to wrap text if it doesn't fit on one line. The pre setting tells the browser not to collapse white space between words.
[edit] line-height
This property allows you to control the amount of space between lines of text. Values are:
| normal | |
|---|---|
| <number> | |
| <length> | |
| <percentage> | |
| inherit | Inherit this setting. |
[edit] text-shadow
- CSS 2
| IE | Opera | Safari | Firefox |
|---|---|---|---|
| NO | NO | Partial 1.1+ | NO |
The text-shadow property applies drop shadows to text. Safari is at present the only web-browser to offer any support for this property. The syntax is:
<color> <x-offset> <y-offset> <blur>
You start with the color of the shadow, then the x-offset, the y-offset, and finally a optional blur radius. An example text-shadow.
text-shadow: blue 5px 5px 2px;
This creates a blue shadow 5 pixels below and 5 pixels to the right of the text with a small blur.
You can create multiple text shadows by using a comma separated list of shadows, for example:
text-shadow: blue 5px 5px 2px, black -5px -5px 2px;
This rule will create two drop shadows. Note that no browser (including Safari) currently supports multiple shadows.
[edit] Tips
- By potting the shadow at 0,0 and giving it a blur, you can create a "glow" effect instead of a shadow.
