This is part 7 of my series, Basics of CSS2. In this part of the series, I give you some word processing features that CSS offers. However, it is the web designer to implement the word processing features and not the web page user. We shall talk about Text Indentation, Text Alignment, Text Decoration, Text Letters and Word Spacing, and Text Transformation.
Note: If you cannot see the code or if you think anything is missing (broken link, image absent), just contact me at forchatrans@yahoo.com. That is, contact me for the slightest problem you have about what you are reading.
Text Indentation
In an HTML (or XHTML) element, all the lines of text begin from the left end of the element. You can make the first line to start at a distance to the right. This is text indentation. You need the, "text-indent" property and a length or percentage value for this. The length value can be a number in pixels. If you use a percentage value, the value will be relative to the width of the element that has the text. Try the following code, which illustrates this in percentage:
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
p {width:50%; text-indent:10%}
text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text
The BODY element has a paragraph, which has text. From the style sheet, we see that the first line is indented by 10%. This is 10% of the paragraph width. From the style sheet, the width of the paragraph is 50% the width of the BODY element.
Note: some browsers may interpret the 10% wrongly, as 10% of the element (BODY) containing the paragraph, instead of 10% of the Paragraph element itself.
Text Alignment
The text-align property is used to Left Justify, Right Justify, Center Justify or Double Justify text in an HTML containing element. You should know what these terms mean from your word processor lessons. The alternative text-align values are as follows:
left
For left Justification.
Right
For right Justification.
center
For center Justification.
justify
For double Justification.
The following code gives an example for double justification:
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
p {width:50%; text-align:justify}
I am a man. You are a woman. What is his name? Is he the man we saw with the blue jacket in the party? Many people of this town use this street. Today is a bright day. Could this mean some good luck in my endeavors? There are about 400 countries in the world. With the advance of technology the world keeps becoming relatively smaller and smaller.
Try the above code if you have not already done so, and note that the text lines flush to the left and right ends of the Paragraph (rectangular) element.
Text Decoration
Text Decoration deals with underlining of text, over-lining (opposite of underline) of text, drawing a line across text and making a text to blink. To achieve any of these options, you need the "text-decoration" property and any of the following values; each value gives its particular effect:
none
Produces no text decoration; this is the same as in the case where the "text-decoration" property is absent.
underline
Each line of text in the element (containing element) is underlined
overline
Each line of text in the element (containing element) has a line above it.
line-through
Each line of text in the element (containing element) has a line through the middle
blink
Text in the element (containing element) blinks (alternates between visible and invisible).
The following shows an underlining example for a SPAN element:
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
span {text-decoration:underline}
In Europe, Football is a very important sport. Good players are extremely rich.
The following example would show an H4 heading blinking. The blinking value does not work with all browsers.
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
h4 {text-decoration:blink}
span {text-decoration:underline}
Act Now!
In Europe, Football is a very important sport. Good players are extremely rich. Act now by sending your kid to a football school.
Try the above two examples if you have not already done so. In this last example, there are two CSS rules: one for h4 and one for span. The number of rules you can have in your style sheet can be very big; here we have just two.
Letter Spacing
Sometimes you would want to space out the characters (letters) of a Heading or SPAN element or some other element. You use the "letter-spacing" property. This is followed of-course by a colon, then a length value. In part 4 of these tutorials I said there are three common units: the pixel, the percentage and the em. Here, use the em unit (see meaning later). The following example shows the spacing of characters of an H3 element of 0.2em and of a SPAN element of 0.1em (try the code):
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
h3 {letter-spacing:0.2em}
span {letter-spacing:0.1em}
Section Two
In this section, we look at the second problem affecting life in the University.
Word Spacing
Instead of separating characters, you can separate words. You use the "word-spacing" property followed of-course by a colon, then a length value measured in em. You can still use some other unit, but em would do. Nothing stops you from combing letter and word spacing. When you separate the characters of words in a phrase, you would have to separate the words, so that the separation between characters should not be the same as the separation between words. The following example illustrates this for the phrase in an H3 element (try the code).
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
h3 {letter-spacing:0.2em; word-spacing:1em}
Section Two
In this section, we look at the second problem affecting life in the University....
The first CSS rule property above separates the characters and the second one separates the words. Note that a space of 0.1em for letter spacing is not the same as a space of 0.1em for word spacing. Also note that for letter and word spacing we have used decimal (less than 1) values for the length value and not whole numbers.
Text Transformation
You might want all the letters of a phrase to be in uppercase or in lowercase. You might also want only the first letter of each word to be in uppercase while the rest of the letters are in lowercase. All this is the text transformation feature. You need the text-transform property for this. This is of course followed by a colon and then a value. You have to choose one of the following values:
uppercase
This value puts all the characters of the containing element in uppercase.
lowercase
This value puts all the characters of the containing element in lowercase.
capitalize
This value puts the first character of each word in the containing element in uppercase.
none
No transformation effects. Same as if you did not have the text-transform property.
The following code shows the use of two of these values (try the code):
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
h4 {text-transform:capitalize}
span {text-transform:uppercase}
a summary of john smith biography
John Smith was born in 1930. His parents ...
Wow, if you have read through the series from the beginning to this point, then you are beginning to get the feel of presentation with CSS.
Let us stop here and continue in the next part of the series.
Chrys
Published by Chrys Forcha
I have more than 10 years experience in computer programming, software, electronics and telecommunications. I have a First Degree in Electronics and a Master's Degree in Technical Education. As well a... View profile
- Understanding CSS Fixed PositioningIn the article I give you an in depth explanation of CSS Fixed Positioning.
- XHTML Table BasicsIn this article, I explain the basics of XHTML tables.
- Designing an XHTML FormIn this article I show you how to design and submit web page forms.
- JSON FileIn this article, I explain the meaning of JSON File.
- XHTML Hyperlink BasicsIn this part of the series, I explain the meaning of Hyperlinks and how to implement them.
- CSS Surrounding Element Properties
- Positioning HTML Elements with CSS and Layering
- CSS Dimensions and Resolutions
- CSS Classification
- CSS List
- Guide to XHTML Layout in Containing Blocks
- Understanding CSS Absolute Positioning and Layering
