Using CSS we can style text on a web page in a number of different ways.
We can:
The CSS color
property is used to set the colour of text. We can give the color
property one of the following values:
Take a look at the CCS code in this example and to see how we use the color
property and the different values we can use.
xxxxxxxxxx
<h2>Italy</h2>
<h3>Capitol</h3>
<p>Rome</p>
<h3>Population</h3>
<p>59 million</p>
xxxxxxxxxx
h2 {
color: blue;
}
h3{
color: #009900;
}
p{
color: rgb(255, 0, 0);
}
We can also set the background colour of text by using the background-color
CSS property. Again this takes either a colour name, a HEX value or a RGB value.
xxxxxxxxxx
<h2>Italy</h2>
<h3>Capitol</h3>
<p>Rome</p>
<h3>Population</h3>
<p>59 million</p>
xxxxxxxxxx
h2 {
color: blue;
background-color: gray;
}
h3{
color: #009900;
background-color: #cccccc;
}
p{
color: rgb(255, 0, 0);
background-color: rgb(192, 192, 192);
}
We use the text-align
CSS property to set how the text should align. We can give it the following values:
xxxxxxxxxx
<h2>Italy</h2>
<h3>Capitol</h3>
<p>Rome</p>
<h3>Population</h3>
<p>59 million</p>
<h3>About Italy</h3>
<p>Italy, officially the Italian Republic is a country consisting of a peninsula delimited by the Alps and several islands surrounding it. Italy is located in south-central Europe, and is also considered part of Western Europe. A unitary parliamentary republic with Rome as its capital and largest city, the country covers a total area of 301,340 km2 (116,350 sq mi) and shares land borders with France, Switzerland, Austria, Slovenia, and the enclaved microstates of Vatican City and San Marino. Italy has a territorial enclave in Switzerland (Campione) and a maritime exclave in Tunisian waters (Lampedusa). With around 60 million inhabitants, Italy is the third-most populous member state of the European Union. </p>
xxxxxxxxxx
h2 {
color: blue;
background-color: gray;
text-align: center;
}
h3{
color: #009900;
background-color: #cccccc;
text-align: right;
}
p{
color: rgb(255, 0, 0);
background-color: rgb(192, 192, 192);
text-align: justify;
}
text-align
properties to left, right, center and justify.We use the text-decoration
CSS property to add (or remove) decorations to text. We can give it the following values:
Take a look at the following HTML code (scroll to the right) and the CSS code to see how the different text decorations are used.
xxxxxxxxxx
<h2>Volcanology of Italy</h2>
<p>The country is situated at the meeting point of the <span class="mytext-under">Eurasian Plate</span> and the <span class="mytext-under">African Plate</span>, leading to considerable seismic and volcanic activity. There are 14 volcanoes in Italy, four of which are active: <span class="mytext-over">Etna, Stromboli, Vulcano and Vesuvius</span>. The last is the only active volcano in mainland Europe and is most famous for the destruction of Pompeii and Herculanum in the eruption in <span class="mytext-through">80 AD</span> 79 AD. Several islands and hills have been created by volcanic activity, and there is still a large active caldera, the Campi Flegrei north-west of Naples. </p>
xxxxxxxxxx
.mytext-under{
text-decoration: underline;
}
.mytext-over {
text-decoration: overline;
background-color: yellow;
}
.mytext-through {
text-decoration: line-through;
}