Professional Documents
Culture Documents
Basic Css Properties
Basic Css Properties
Font Family
The font-family property allows us to change the particular font we are using. You may
select any font which is installed on the clients computer with this property. Some of the
more commonly used fonts include:
•Arial
•Verdana
It is possible to specify and include non standard fonts but this is a little more complex.
We'll look at this later.
style.css
1. h1 {
3. }
4. p {
5. font-family: Verdana;
6. }
Hobbies
On the weekend I got all my watches and attached them together into a belt.
Font Size
Font-size may be specified using a few different types but the easiest to work with is
pixels (px).
h1{
font-family:Times New Roman;
}
p{font-family:Verdana;
1. }
<!doctype html>
<html>
<head>
<title>Hobbies</title>
<meta name="description" content="Let's demonstrate some CSS">
<meta name="keywords" content="html tutorial css linked">
<link href="style.css" rel="stylesheet">
</head>
<body>
<h1>Hobbies</h1>
<p>On the weekend I got all my watches and attached them together into a belt.</p>
<p>It turned out to be a waist of time.</p>
</body>
</html>
Hobbies
On the weekend I got all my watches and attached them together into a belt.
Font Weight
The font-weight css property allows us to specify how thick the lines of the characters
are. It may be one of the following values:
•lighter
•normal
•bold
•bolder
Some font families only have normal and bold weights. In this case if you specify lighter it
will default back to normal and if you specify bolder it will default back to bold.
Put this code in style.css and see the change.
h1{
font-weight:normal;
}
p{
font-weight:bold;
}
Colour Properties
Colour is a reasonably complex thing to define. There are several ways in which we can do
this. We will look at colour in much more detail in a later section. Here we will just work
with it in it's simplest form which is with Hexadecimal numbers. A colour is specified by a
hash ( # ) followed by 6 hexadeximal numbers. The first 2 are the amount of red, the
second 2 the amount of green and the final 2 the amount of blue.
Note also that in CSS we use the American spelling for colour so we drop the u, eg color. If
you happen to be American then this won't be a problem but for others it is something to
keep in mind.
Colour
The color property allows us to specify the colour of the text.
h1{
color:#9ACA42;
}
p{
color:#357180;
}
Background Colour
The background-color property allows us to specify the background colour for the
element.
h1{
background-color:#9ACA42;
}
p{
background-color:#A0D2DC;
}
Pseudo classes:
a:hover {
Explanation
a:link {
color: aquamarine;
The example above will change the color of all unvisited links to
aquamarine.
When used in combination with the :hover pseudo-class, :link must
appear first, or else not be defined at all, in order for the :hover
styles to work. This is because they are equally specific, so if :link
came after, those styles would override the hover styles.
The :link pseudo-class will target all <a> elements that have an
href attribute, even if the href has an empty value. So, in that
sense, it is like the attribute selector [href].
This means the following three HTML elements are all able to be
styled via the :link pseudo-class:
<a href="https://css-tricks.com">CSS-Tricks</a>
<a>CSS-Tricks</a>
<a href>CSS-Tricks</a></code>
Again, the HTML would fail validation, since href is not a valid
attribute for <div>.
Due to the fact that :link can target only <a> elements, :link styles
can be defined in the CSS without the element type selector, like
this:
:link {
color: aquamarine;
Also, for all practical purposes when using HTML, the :link pseudo-
class is somewhat irrelevant since the same effect can be
achieved by simply targeting all <a> elements directly:
a{
color: aquamarine;
.
The:visited pseudo-class selector can change some of the styling
on an anchor link (<a>) element if the user’s browser has already
visited the link. It’s meant to help users distinguish the difference
between links they have and haven’t visited.
a:visited {
color: gray;
The :hover pseudo class in CSS selects elements when the mouse
cursor is current over them. It’s commonly associated with link
(<a>) elements.
a:hover {
color: green;
}
So when a link like this is “hovered” (like with a cursor on a device
with a mouse):
<a href="https://google.com">Go to Google</a>
It will turn green and have a line beneath and above it.
In IE 6 and below, :hover used to only work on links, but in newer
browsers, it works on any element. This can be particularly useful
for things like dropdown menus in which you can wait for the :hover
of a parent list item and then reveal the next level of the nested
menu. Careful though, hover effects should be coupled with some
kind of action, as that has been a long-established web pattern.
•O
•V :visited
•E
•H :hover
•A :active
•T
•E
Doing them in that order is ideal.
a:link { /* Essentially means a[href], or that the link actually goes somewhere
*/
color: blue;
a:visited {
color: purple;
a:hover {
color: green;
a:active {
color: red;
Otherwise, say if you listed the :visited style last, if that link was
visited it would override the :active and :hover declaration and the
link would always be purple regardless if you were hovering or if
the link was active (not ideal).
The :focus pseudo class in CSS is used for styling an element that is
currently targeted by the keyboard, or activated by the mouse.
Here is an example:
textarea:focus {
background: pink;