CSS1
CSS1
CSS1
Purpose of CSS
CSS, or Cascading Style Sheets, is a language that is used
in combination with HTML that customizes how HTML
elements will appear. CSS can de�ne styles and change
the layout and design of a sheet.
1 of 4 8/19/23, 10:15
Firefox about:srcdoc
Inline Styles
CSS styles can be directly added to HTML elements by <h2 style="text-align: center;">Centered
using the style attribute in the element’s opening tag.
text</h2>
Each style declaration is ended with a semicolon. Styles
added in this manner are known as inline styles.
<p style="color: blue; font-size:
18px;">Blue, 18-point text</p>
Selector Chaining
CSS selectors de�ne the set of elements to which a CSS
rule set applies. For instance, to select all <p>
elements, the p selector can be used to create style
rules.
2 of 4 8/19/23, 10:15
Firefox about:srcdoc
Chaining Selectors
CSS selectors can be chained so that rule sets apply only /* Select h3 elements with the section-
to elements that match all criteria. For instance, to select
heading class */
<h3> elements that also have the section-heading
class, the selector h3.section-heading can be used.
h3.section-heading {
color: blue;
}
3 of 4 8/19/23, 10:15
Firefox about:srcdoc
Selector Speci�city
Speci�city is a ranking system that is used when there are h1#header {
multiple con�icting property values that point to the
color: blue;
same element. When determining which rule to apply, the
selector with the highest speci�city wins out. The most } /* implemented */
speci�c selector type is the ID selector, followed by class
selectors, followed by type selectors. In this example, only
h1 {
color: blue will be implemented as it has an ID selector
whereas color: red has a type selector.
color: red;
} /* Not implemented */
CSS ID selectors
The CSS ID selector matches elements based on the #job-title {
contents of their id attribute. The values of id
font-weight: bold;
attribute should be unique in the entire DOM. For
selecting the element having job-title as the value of
}
the id attribute, a # needs to be prepended.
Print Share
4 of 4 8/19/23, 10:15