Applying Many Styles to an Element Instead of one, you can apply many styles to an element. You have many options. You can create the style in either the head section or in a separate file. To apply the styles, in the style attribute of an element, provide the list of styles separated by spaces. Here are examples: <html> <head> <title>Chemistry: Periodic Table</title> <link rel="stylesheet" href="collaboration.css"> <link rel="stylesheet" href="definitions.css"> <head> <body> <p class="MainTitle">Chemistry: Periodic Table</p> <p class="presentation">In chemistry, the periodic table is used to organize the chemical elements based on their atomic numbers, their electron arrangement, and other properties. Based on the atomic numbers, the first 12 elements are:</p> <ul> <li>Hydrogen</li> <li>Helium</li> <li class="alkali-metal significant">Lithium</li> <li class="earth-metal significant bulletless">Beryllium</li> <li class="metalloid significant">Boron</li> <li>Carbon</li> <li>Nitrogen</li> <li>Oxygen</li> <li class="halogen">Fluorine</li> <li class="noble-gas bulletless">Neon</li> <li class="alkali-metal">Sodium</li> <li class="earth-metalbulletless">Magnesium</li> </ul> <p class="presentation">Based on their properties, these 12 elements can be presented as follows:</p> <div align="center"> <table border=5> <tr> <td>Atomic Number</td> <td>Element</td> <td>Symbol</td> <td>Atomic Mass</td> </tr> <tr> <td>1</td> <td>Hydrogen</td> <td>H</td> <td>1.0079</td> </tr> <tr> <td>2</td> <td>Helium</td> <td>He</td> <td>4.002682</td> </tr> <tr> <td class="alkali-metal significant">3</td> <td class="alkali-metal significant">Lithium</td> <td class="alkali-metal">Li</td> <td class="alkali-metal">6.941</td> </tr> <tr> <td class="earth-metal">4</td> <td class="earth-metal significant">Berylium</td> <td class="earth-metal">Be</td> <td class="earth-metal significant">9.0122</td> </tr> <tr> <td class="metalloid">5</td> <td class="metalloid">Boron</td> <td class="metalloid">B</td> <td class="metalloid">10.811</td> </tr> <tr> <td>6</td> <td>Carbon</td> <td>C</td> <td>12.011</td> </tr> <tr> <td>7</td> <td>Nitrogen</td> <td>N</td> <td>14.0067</td> </tr> <tr> <td>8</td> <td>Oxygen</td> <td>O</td> <td>15.9994</td> </tr> <tr> <td class="halogen">9</td> <td class="halogen">Fluorin</td> <td class="halogen">F</td> <td class="halogen">18.998403</td> </tr> <tr> <td>10</td> <td>Neon</td> <td>Ne</td> <td>20.1797</td> </tr> <tr> <td class="alkali-metal">11</td> <td class="alkali-metal">Sodium</td> <td class="alkali-metal">Na</td> <td class="alkali-metal">22.989769</td> </tr> <tr> <td class="earth-metal">12</td> <td class="earth-metal">Magnesium</td> <td class="earth-metal">Mg</td> <td class="earth-metal">24.305</td> </tr> </table> <div> </body> </html> This would produce:
Grouping Styles Applying the Same Style to Various Elements Consider the following styles: <html>
<head>
<title>Chemistry: Carbon</title>
<style>
p {
font-family: Times New Roman;
font-size: 12pt; }
li {
font-family: Times New Roman;
font-size: 12pt; }
</style>
</head>
<body>
<h1>Chemistry: Carbon</h1>
<p>Carbon is one of the most commonly found chemical components on earth. It
can be found inside the earth, on the human body, and in many organic compounds.
Carbon is the 6th most abundant chemical element on earth. The order of
abundance is:</p>
<ol>
<li>Hydrogen
<li>Helium
<li>Oxygen
<li>Neon
<li>Nitrogen
</ol>
</body>
</html>
This would produce: Notice that both styles are exactly the same: same font and same text size. If you have various elements that use the same style, instead of creating the styles separately, you can create the list of tags separated by commas and followed by the style definition. Here is an example: <html>
<head>
<title>Chemistry: Carbon</title>
<style>
p, li {
font-family: Times New Roman;
font-size: 12pt; }
</style>
</head>
<body>
<h1>Chemistry: Carbon</h1>
<p>Carbon is one of the most commonly found chemical components on earth. It
can be found inside the earth, on the human body, and in many organic compounds.
Carbon is the 6th most abundant chemical element on earth. The order of
abundance is:</p>
<ol>
<li>Hydrogen
<li>Helium
<li>Oxygen
<li>Neon
<li>Nitrogen
</ol>
</body>
</html>
In the same way, you can create a group of as many styles as you want. Here is an example: <html>
<head>
<title>Chemistry: Hydrogen</title>
<style>
#main-title
{
color: red;
font-size: 24pt;
font-family: Rockwell;
}
#introduction, #molecule, #hydrogen, li, #carbon, .description
{
color: blue;
}
</style>
</head>
<body>
<p id="main-title">Chemistry: Hydrogen</p>
<p id="introduction">Introduction</p>
<p id="hydrogen">Hydrogen is the most widely available chemical element on earth.
It is primarily presented as a gas. Hydrogen has no odor and no color.</p>
<p class="description">Hydrogen has the simplest atom with one electron, one proton,
and (the only element with) zero neutron. The fundametal characteristics of hydrogen
are as follows:</p>
<ul>
<li>Chemical Symbol: H
<li>Atomic Number: 1
<li>Atomic Weight: 1.008
<li>Phase: Gas
<li>Appearance: Colorless
</ul>
<p id="molecule">Hydrogen Molecule</p>
<p id="hydrogen">Hydrogen is revealed as a molecule of two atoms as H<sub>2</sub>.
The atom easily combines with many types of elements to form various categories of
liquids, gases, and solids. That's how
it is found in water as it combines with oxygen (O) to produce H<sub>2</sub>O
(water).</p>
<p id="carbon">While hydrogen is the dominant substance in the universe, carbon is
the main component of most minerals such as diamond and graphite. Combining
hydrogen and carbon results in many types of organic compounds.</p>
</body>
</html>
This would produce:
Grouping Styles by Type Consider the following styles: <html>
<head>
<title>Chemistry: Hydrogen</title>
<style>
#main-title
{
color: Red;
font-size: 24pt;
font-family: Rockwell;
}
li
{
color: Black;
font-size: Medium;
font-family: Times New Roman;
}
#sub-title
{
color: Blue;
font-size: x-large;
font-family: Rockwell;
}
.description
{
color: Blue;
font-size: Medium;
font-family: Times New Roman;
}
#introduction
{
color: Green;
font-family: Times New Roman;
}
#carbon
{
color: Green;
font-family: Garamond;
}
#copyright
{
color: Gray;
font-size: 12px;
font-family: Comic Sans MS;
}
</style>
</head>
<body>
<p id="main-title">Chemistry: Hydrogen</p>
<p id="sub-title">Introduction</p>
<p id="introduction">Hydrogen is the most widely available chemical element on
earth. It is primarily presented as a gas. Hydrogen has no odor and no color.</p>
<p class="description">Hydrogen has the simplest atom with one electron, one proton,
and (the only element with) zero neutron. The fundametal characteristics of
hydrogen are as follows:</p>
<ul>
<li>Chemical Symbol: H
<li>Atomic Number: 1
<li>Atomic Weight: 1.008
<li>Phase: Gas
<li>Appearance: Colorless
</ul>
<p id="sub-title">Hydrogen Molecule</p>
<p id="description">Hydrogen is revealed as a molecule of two atoms as H<sub>2</sub>.
The atom easily combines with many types of elements to form various categories of
liquids, gases, and solids. That's how it is found in water as it combines with
oxygen (O) to produce H<sub>2</sub>O (water).</p>
<p id="carbon">While hydrogen is the dominant substance in the universe, carbon is
the main component of most minerals such as diamond and graphite. Combining hydrogen
and carbon results in many types of organic compounds.</p>
<p id="copyright">- - - - -Copyright © 2015- - - - -</p>
</body>
</html>
Notice that many tags use the same styles. For example, the p and the td elements use the same font but different text colors. The h1 and the li elements use the same font but apply different colors. The above code would produce:
If different tags or classes share some styles, you can create a list of tags and/or classes separated by commas and followed by the style(s) they share. This means that you will have to create different style sections for the same tag(s) or class(es). Here are examples: #main-title { color: Red; font-size: 24pt; } li { color: Black; font-size: Medium; } #sub-title { font-size: x-large; } #main-title, #sub-title { font-family: Rockwell } .description { font-size: Medium; } #sub-title, .description { color: Blue } #carbon, #introduction { color: Green; } #introduction, li, .description { font-family: Times New Roman; } #carbon { font-family: Garamond; } #copyright { color: Gray; font-size: 12px; font-family: Comic Sans MS; } Style Grouping and Links Style Pounding Remember that you can create a style for a link using the # symbol for the style and an identifier for the tag in the HTML code. Here are examples: <html>
<head>
<title>Anthropology</title>
<style>
.main-title {
color: red;
font-size: 24pt;
font-family: Bodoni MT Black; }
li.presentation {
color: black;
font-size: 12pt;
font-family: Times New Roman; }
p.presentation {
font-size: 1.15em;
font-family: Garamond; }
a:link#copyright {
font-size: 1.15em;
font-family: Georgia;
color: DeepPink; }
a:active#copyright {
color: Gold;
font-size: 1.15em;
font-family: Georgia; }
a:visited#copyright {
font-size: 1.15em;
font-family: Georgia;
color: SeaGreen;}
a:hover#copyright {
color: Peru;
font-size: 1.15em;
font-family: Georgia; }
</style>
<head>
<body>
<p class="main-title">Anthropology</p>
<p class="presentation">Anthropology is the study of the origins as well as the
contemporary aspects of humans. The study includes:</p>
<ul>
<li class="presentation">Human Body: The study of anthropology includes the
physical traits of the <a href="body.htm">human body</a>. This includes such
information as what might have created the shapes on the human body and how that
body currently appears</li>
<li class="presentation">Environment: Anthropology must establish the culture in
which the human lives, how the <a href="environment.htm">environment</a>
influences the human over time, and how the human influences the environment as
time passes by</li>
<li class="presentation">Age: This is the part of anthropology that studies the
origins of the human body and its evolution over the years</li>
</ul>
<p><a href="index.htm" class="title">Social Sciences</a> | <a href="resources.htm"
class="title">Resources</a> | <a href="services.htm" class="title">Services</a></p>
<p><a href="scopy.htm" id="copyright">Copyright © 2015</a></p>
</body>
</html>
This would produce:
When it comes to the identified elements, you can first create the pounding part and put the list of common styles in its body. This can be done as follows: #copyright { font-size: 1.15em; font-family: Georgia; } Each pseudo-class and the pounding name can then be used for its unique style(s). This can be done as follows: #copyright {
font-size: 1.15em;
font-family: Georgia; }
a:link#copyright { color: DeepPink; }
a:active#copyright { color: Gold; }
a:visited#copyright { color: SeaGreen; }
a:hover#copyright { color: Peru; }
Everything else stays the same; that is, assign the name of the pound part to the id attribute of the link element that will use it. Class Style Grouping and Links Imagine you have links that don't use a pounding style. Here are examples: a:link { font-size: 1.15em; font-family: Cambria; color: DarkMagenta; } a:active { font-size: 1.15em; font-family: Cambria; color: Green; } a:visited { font-size: 1.15em; font-family: Cambria; color: Teal; } a:hover { font-size: 1.15em; font-family: Cambria; color: DarkOrange; } If, or since, the pseudo-classes share some styles, you can combine those styles in one section where you would provide the a name, the colon, and each pseudo-class where they would be separated with commas. The group is followed by curly brackets. In those brackets, create the common style(s). Here is an example: a:link, a:active, a:visited, a:hover { font-size: 1.15em; font-family: Cambria; } Somewhere else in the file, each pseudo-class would provide its unique style(s) in its own section. This can be done as follows: a:link, a:active, a:visited, a:hover
{
font-size: 1.15em;
font-family: Cambria;
}
a:link { color: DarkMagenta }
a:active { color: Green }
a:visited { color: Teal }
a:hover { color: DarkOrange }
In the same way, you might want to use a class for the links. Here is an example: a.title:link { color: Gray; font-size: 1.15em; font-family: Comic Sans MS; } a.title:active { color: Brown; font-size: 1.15em; font-family: Comic Sans MS; } a.title:visited { color: Blue; font-size: 1.15em; font-family: Comic Sans MS; } a.title:hover { color: Red; font-size: 1.15em; font-family: Comic Sans MS; } This time too, create a common section that has the a name, the period and the name of the class, followed by a colon and the name of the pseudo class where they are separated by commas, followed by curly brackets. In the brackets, define the desired style(s). This can be done as follows: a.title:link, a.title:active, a.title:visited, a.title:hover
{
font-size: 1.15em;
font-family: Comic Sans MS;
}
In separate sections, each pseudo-class can define its unique style(s). Here are examples: <html>
<head>
<title>Anthropology</title>
<style>
.main-title {
color: red;
font-size: 24pt;
font-family: Bodoni MT Black; }
li.presentation {
color: black;
font-size: 12pt;
font-family: Times New Roman; }
p.presentation {
font-size: 1.15em;
font-family: Garamond; }
a:link, a:active, a:visited, a:hover
{
font-size: 1.15em;
font-family: Cambria;
}
a:link { color: DarkMagenta }
a:active { color: Green }
a:visited { color: Teal }
a:hover { color: DarkOrange }
#copyright {
font-size: 1.15em;
font-family: Georgia; }
a:link#copyright { color: DeepPink; }
a:active#copyright { color: Gold; }
a:visited#copyright { color: SeaGreen; }
a:hover#copyright { color: Peru; }
a.title:link,
a.title:active,
a.title:visited,
a.title:hover
{
font-size: 1.15em;
font-family: Comic Sans MS;
}
a.title:link { color: Gray; }
a.title:active { color: Brown; }
a.title:visited { color: Blue; }
a.title:hover { color: Red; }
</style>
<head>
<body>
<p class="main-title">Anthropology</p>
<p class="presentation">Anthropology is the study of the origins as well as the
contemporary aspects of humans. The study includes:</p>
<ul>
<li class="presentation">Human Body: The study of anthropology includes the
physical traits of the <a href="body.htm">human body</a>. This includes such
information as what might have created the shapes on the human body and how that
body currently appears</li>
<li class="presentation">Environment: Anthropology must establish the culture in
which the human lives, how the <a href="environment.htm">environment</a>
influences the human over time, and how the human influences the environment as
time passes by</li>
<li class="presentation">Age: This is the part of anthropology that studies the
origins of the human body and its evolution over the years</li>
</ul>
<p><a href="index.htm" class="title">Social Sciences</a> | <a href="resources.htm"
class="title">Resources</a> | <a href="services.htm" class="title">Services</a></p>
<p><a href="scopy.htm" id="copyright">Copyright © 2015</a></p>
</body>
</html>
This would produce: |