In CSS, we can manipulate text positioning by changing its alignment and indentation. There are three kinds of text positioning, horizontal alignment, vertical alignment and indentation.
We use the text-align property to align text horizontally. There are four types of horizontal alignments, left, right, centre and justify. The CSS structures are illustrated as follows:
h1{ text-align:left;} h2{text-align:right;} p{text-align: center;} div{text-align: justify;}
<!Doctype html> <html> <head> </head> <body> <h1 style="text-align: left;"> The text is aligned left</h1> <h2 style="text-align: right;"> The text is aligned right</h2> <h3 style="text-align: right;"> The text is aligned at centre</h3> <p style="text-align: justify;">In CSS, we can manipulate text positioning by changing its alignment and indentation. In addition, we can also control spacing between letters, spacing between words and spacing between lines of text.</p> </body> </html>
In CSS, we can manipulate text positioning by changing its alignment and indentation. In addition, we can also control spacing between letters, spacing between words and spacing between lines of text.
In CSS, the vertical-align property it is commonly used to align text vertically in cells of table and text alongside an image. There are a couple of values associated with the vertical-align property, namely text-top, middle, text-bottom, top, baseline and more.
<!DOCTYPE html> <html> <head> <title>Vertical Alignment</title> <style type="text/css"> .onTop {vertical-align: text-top;} .AtMiddle {vertical-align: middle;} .AtBottom{vertical-align: text-bottom;} </style> </head> <body> <h1>Vertical Alignment in CSS</h1> <p><img src="http://htmltutor.org/wp/wp-content/uploads/2015/01/hue2.jpg" class="onTop"> Circle</p> <p><img src="http://htmltutor.org/wp/wp-content/uploads/2015/01/hue2.jpg" class="AtMiddle" /> Circle</p> <p><img src="http://htmltutor.org/wp/wp-content/uploads/2015/01/hue2.jpg" class="AtBottom" /> Circle</p> </body> </html>
*If you can't see the effect of the alignments, please click on Example 18.2
Text indentation means how far back the first line of a paragraph is pushed to the right or left. The property is text-indent and its value is in pixel or ems. The value can be positive or negative. If the value is positive, the text is pushed to the right whereas if the value is negative the text is pushed to the left.
<p style="text-indent: 20px">Text indentation means how far back the first line of a paragraph is pushed to the right or left. The property is text-indent and its value is in pixel or ems. <p style="text-indent: -20px">The value can be positive or negative. If the value is positive, the text is pushed to the right whereas if the value is negative the text is pushed to the left.</p>
Text indentation means how far back the first line of a paragraph is pushed to the right or left. The property is text-indent and its value is in pixel or ems.
The value can be positive or negative. If the value is positive, the text is pushed to the right whereas if the value is negative the text is pushed to the left.
Copyright©2008 Dr.Liew Voon Kiong. All rights reserved |Contact|Privacy Policy