Web Design and Development Lecture 5
Web Design and Development Lecture 5
development
Lecture 5
Course Instructor: Wardah Mahmood
Email Id: [email protected]
CSS revision
• Cascading Style Sheets (CSS)
• Used to describe the presentation of documents
• Define sizes, spacing, fonts, colors, layout, etc.
• Improve content accessibility
• Improve flexibility
• Designed to separate presentation from content
• Due to CSS, all HTML presentation tags and attributes are deprecated, e.g. font,
center, etc.
Why CSS?
• Some CSS styles are inherited and some not.
• Text-related and list-related properties are inherited - color, font-size, font-family,
line-height, text-align, list-style, etc
• Box-related and positioning styles are not inherited - width, height, border,
margin, padding, position, float, etc.
• <a> elements do not inherit color and text-decoration
Style sheet syntax
• Stylesheets consist of rules, selectors, declarations, properties and values
selector:pseudo-class {
property:value;
}
https://www.w3schools.com/css/css_pseudo_classes.asp
Pseudo-elements
• A CSS pseudo-element is used to style specified parts of an element.
• For example, it can be used to:
• Style the first letter, or line, of an element
• Insert content before, or after, the content of an element
selector::pseudo-element {
property:value;
}
https://www.w3schools.com/css/css_pseudo_elements.asp
How to measure specificity?
• Memorize how to measure specificity. “Start at 0, add 1000 for style attribute,
add 100 for each ID, add 10 for each attribute, class or pseudo-class, add 1 for
each element name or pseudo-element. So in
The specificity value would be 122 (0,1,2,2 or 0122): 100 for #content, 10 for
.data, 10 for :hover, 1 for body and 1 for img.” [CSS Specificity]
How to measure specificity?
• Alternative way: “Count the number of ID attributes in the selector (= a). Count
the number of other attributes and pseudo-classes in the selector (= b). Count
the number of element names and pseudo-elements in the selector (= c).
Concatenating the three numbers a-b-c gives the specificity.
• https://www.smashingmagazine.com/2007/07/css-specificity-things-you-should-k
now
/