











Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!












Contents ■ Introduction to CSS ■ CSS Syntax ■ Selectors (^) Element, ID, Class ■ (^) CSS Types (^) Inline, Internal, External ■ (^) Cascading Order ■ (^) Multiple CSS Files ■ (^) CSS Comments
CSS Syntax ■ A CSS rule-set consists of a selector and a declaration block: ■ The selector points to the HTML element you want to style. ■ (^) The declaration block contains one or more declarations separated by semicolons. ■ (^) Each declaration includes a CSS property name and a value, separated by a colon. ■ A CSS declaration always ends with a
CSS Selectors ■ CSS selectors are used to "find" (or select) HTML elements based on their element name, id, class, attribute, and more.
Grouping Selectors
H1 Heading H2 heading!
This is a paragraph.
The id Selector ■The id selector uses the id attribute of an HTML element to select a specific element. ■The id of an element should be unique within a page, so the id selector is used to select one unique element! ■To select an element with a specific id, write a hash (#) character, followed by the id of the element. ■The style rule below will be applied to the HTML element with id=“id1“. ■ Note: An id name cannot start with a number!
Software Engineering
This paragraph is not affected by the style.
The class Selector (Cont…) ■ (^) You can also specify that only specific HTML elements should be affected by a class. ■ (^) In the example below, only
elements with class="center" will be center-aligned.
This heading will not be affected
This paragraph will be red and center- aligned.
The class Selector (Cont…) ■ (^) HTML elements can also refer to more than one class. ■ (^) In the example below, theelement will be styled according to class="center" and to class="large”.
This heading will not be affected
This paragraph will be red and center-aligned.
This paragraph will be red, center- aligned, and in a large font-size.
Inline Styles ■ An inline style may be used to apply a unique style for a single element. ■ To use inline styles, add the style attribute to the relevant element. The style attribute can contain any CSS property.University of Malakand
Internal Style Sheet ■An internal style sheet may be used if one single page has a unique style. ■Internal styles are defined within the
This is a heading
This is a paragraph.
Example body { background-color: grey; } h1 { color: red; margin-left: 40px; }
Cascading Order ■ (^) Following is the priority order in which CSS style will be applied. (^) Inline style (inside an HTML element) (^) Internal and External style sheets (^) Browser default ■ (^) So, an inline style (inside a specific HTML element) has the highest priority, which means that it will override a style defined inside the tag, or in an external style sheet, or a browser default value.
CSS Comments ■ Comments are used to explain the code, and may help when you edit the source code at a later date. ■ (^) Comments are ignored by browsers. ■ (^) A CSS comment starts with /* and ends with */. ■ (^) Comments can also span multiple lines: