CSS Notes
CSS Notes
Table of Contents
Introduction
Selectors
Properties and Values
Colors
Fonts
Box Model
Positioning
Flexbox
Grid
Responsive Design
Introduction
CSS (Cascading Style Sheets) is a stylesheet language used to describe the presentation of a
document written in HTML. It controls the layout of multiple web pages all at once.
Selectors
CSS selectors are used to "find" (or select) the HTML elements you want to style. Common
types of selectors include:
Element Selector: Selects all elements of a specific type (e.g., p for all paragraphs).
Class Selector: Selects elements with a specific class attribute (e.g., .class-name).
ID Selector: Selects a single element with a specific id attribute (e.g., #id-name).
Universal Selector: Selects all elements (*).
Attribute Selector: Selects elements based on an attribute or attribute value (e.g.,
[type="text"]).
Colors
CSS colors can be specified in different ways:
Fonts
CSS font properties allow you to style text. Some common font properties include:
Box Model
The CSS box model describes the rectangular boxes generated for elements in the document
tree and is made up of:
Positioning
CSS positioning allows you to control the layout of an element in a document. The different
positioning types include:
Static: The default positioning; elements are positioned according to the normal flow
of the document.
Relative: Positioned relative to its normal position.
Absolute: Positioned relative to its nearest positioned ancestor.
Fixed: Positioned relative to the browser window.
Sticky: A hybrid of relative and fixed positioning.
Flexbox
CSS Flexbox is a layout module designed to provide a more efficient way to lay out, align,
and distribute space among items in a container. Some key properties include:
Grid
CSS Grid Layout is a two-dimensional layout system for the web. Some key properties
include:
Responsive Design
Responsive design ensures that web pages look good on all devices by using flexible layouts,
flexible images, and media queries. Key techniques include:
Media Queries: Allow you to apply styles based on the device's characteristics, such
as width and height (e.g., @media (max-width: 600px) { ... }).
Fluid Grids: Use percentage-based widths for layout elements instead of fixed
widths.
Flexible Images: Use CSS to ensure images scale correctly within their containers.