Lesson 3 CSS Class and ID
Lesson 3 CSS Class and ID
Classes and ID
Selector
What are Classes?
• A Class is a user-defined selector. You can
create a class to apply a style rule to specific
HTML tags. Using CSS class you can control
individual HTML element formatting.
• Classes are defined by dots ( . ) There are two
methods of writing class. The first one is by
indicating the HTML elements followed by a dot
then followed by the class name (any name you
want for it). The second one is by writing the
class name preceded by a dot.
Example
• The picture on the right is a
CSS file that shows classes.
The first style is written using
the first method while the
second style is written using
the second method.
• The first one (p.bluefont) is a
style that can only be used
on paragraphs while the
second one (.redfont) can be
used on any HTML element.
This shows the difference
between the two methods of
writing the classes.
What are Classes?
• A class must be called on the HTML file for it to
be used. How is this done? You can call classes
by putting the class attribute in the tag you want
to style and the class name as its value. The
bluefont is the class name of p.bluefont and
redfont is the class name of .redfont.
Class Selector
• Class Selector is a style pplied to a particular set
of elements.
Class Selector
Class Selector
applied in the body
Output
ID Selector
• ID selector is a style applied to one element in a
page. It is normally used once, usually in a page
title or the navigation part of the page. ID
selector is defined by “#” and used the id
attribute of the HTML element.
• It is not advisable to start an id selector with a
number because some browsers do not support
it.
Example
ID Selector
ID Selector
applied in the
body
Output
Pseudo-classes and Links
• Pseudo-classes are defined by a colon and are
not user-defined. Specific pseudo-classes can
be used on specific HTML elements only.
• The anchor element has four pseudo-classes,
link, visited, hover and active. Each one affects
the behavior of the anchor element.
• The link pseudo-class is for hyperlinks that have
not yet been visited. The visited pseudo-class is
for visited hyperlinks. The hover is for hyperlinks
when the mouse is hovered over them. Lastly,
active pseudo-class is for hyperlinks when they
are clicked.
Example:
External style
link
Link Style
Output
Quiz: Identification
1. These classes are defined by a colon and are
not user defined.
2 – 5 What are the four pseudo classes of anchor
element.
6. It is for hyperlinks that have not yet been visited.
7. It is for hyperlinks when they have the mouse
stay close over them.
8 – 10. The order of the anchor property should be,
Link, then __________, followed by _______ and
last is _________.
Write T if the statement is true and F if not then write the
incorrect word that made the statement wrong.
1. A code is a user-defined selector.
2. Classes are defined by dots ( . )
3. One way to write a class is by writing the class name as
preceded by a dot.
4. There are three ways to write a class.
5. Class selector is applied to a particular set of elements.
6. Multiple- selector is a style applied to one element per
page.
7. You can write a class by indicating the header element
followed by a dot.
8. You may always run the case where two or more
selectors might just have the same properties and values.
9. With the use of classes, you can control individual HTML
element formatting.
10. You can call a class by putting the selector attribute in the
tag you want to style.
Quiz:
1. A term used when talking about design and layout in
CSS.
2. This part clears an area outside the border of a box.
3. Where text and images appear.
4. Clears an area around the content. This is transparent.
5. Part of the box that goes around the padding and content.
Backdrops:
- These are full sized
backdrops, just scale them up!
- Can be Copy-Pasted out of
Templates for use anywhere!