CSS
Course Overview
Course Title: CS2212 – Web Systems II
Instructor: Dr. Krishnendu Guha
Affiliation: School of Computer Science and Information Technology, University College Cork
Objectives of the Course
Understanding the motivation for CSS and its historical context.
Learning CSS syntax, semantics, and styling placement through examples.
Familiarization with common types of property values and their formats.
Structuring, commenting, and formatting style sheets effectively.
Understanding CSS selectors, particularly
idandclass.Exploring legacy HTML5 grouping elements such as
divandspan.
HTML5 Semantic Elements
Introduction to new HTML5 elements:
mainheaderfooternavarticlesectionaside
Discussion on inheritance and the cascade in CSS.
Learning to validate CSS styles.
Investigation of the CSS box model for layout.
Crafting simple CSS page layouts using floating elements.
Importance of CSS reset for consistent styling across browsers.
Styling the Nature's Source website with CSS.
Brief overview of responsive design principles.
Fundamentals of CSS
Definition: CSS (Cascading Style Sheets) is a language designed for presenting web pages, focusing on formatting and layout rather than HTML tagging.
Historical Insight: The realization of the benefits of CSS evolved from the early to late 1990s based on the work of Bert Bos and Håkon Wium Lie.
CSS Versions Overview
CSS 1 (1996): The initial W3C recommendation for CSS.
CSS 2 (1998): A superset of CSS 1.
CSS 2.1 (2011): Simplified CSS 2 by removing poorly-supported features and adding implemented browser extensions.
CSS 3 (1999 onwards): A modular standard, consisting of over 50 modules, with evolving support across browsers.
Style Sheets and Style Rules
Style sheets are collections of rules dictating how HTML elements should be displayed.
Benefits of using style sheets include:
Quick changes across an entire website by modifying a single style sheet.
Default styles applied to unstyled HTML elements via browser settings.
Simple Style Rules Examples
Example 1:
body {background-color: yellow;}sets background color.Example 2:
h1 {color: blue;}sets header text color.
Style Rule Syntax and Terminology
Selector: Identifies the HTML element to be styled (e.g.,
h1).Declarations: Properties and their values (e.g.,
color: blue;).Best Practices: Always end declarations with a semicolon.
Style Rule Placement Options
External: Recommended approach, linking multiple HTML documents to a single style sheet.
Document Level: Placing styles within the HTML document's head.
Inline: Not recommended as it applies styles only to a single element.
Connecting HTML and CSS
Link HTML to CSS using the
linkelement:
<link rel="stylesheet" type="text/css" href="css/simple.css"> Essential attributes include:
rel: Describes the relationship.type: Specifies the stylesheet type.href: Points to the CSS file path.
Sample HTML File with CSS Link
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Nature's Source</title>
<link rel="stylesheet" type="text/css" href="css/simple.css">
</head>
<body>
<h1>Welcome to the Website of Nature's Source!</h1>
<p>This is our first foray onto the World Wide Web...</p>
</body>
</html>Simple CSS Style File Example
/* simple.css */
body {background-color: yellow;}
h1 {color: blue;}Display Results in Browser
Demonstrates how styled HTML appears in browsers.
More Style Rule Syntax Examples
Comma-Separated Selectors: E.g.,
h1, h2, h3 {color: blue;}applies to all specified headers.Property Value Lists: E.g.,
body {font-family: Verdana, Arial, sans-serif;}searches for a suitable font.Descendant Selectors: E.g.,
ul li {font-style: italic;}targets specific list items.
Generic Font Families
Serif: Times,