5-CSS and Responsive Design
5-CSS and Responsive Design
c) CSS Selectors
CSS selectors allow you to target specific HTML elements for
styling. The most commonly used selectors are:
In HTML:
• ID Selector: Target an element with a specific ID.
In HTML:
b) Positioning
CSS positioning properties control the placement of elements
on a webpage. The key positioning types are:
1. Static: The default positioning. Elements are placed in the
normal flow of the document.
This CSS rule will apply a light blue background color when the
screen width is 768px or less, which is common for tablets
or smaller devices.
b) Flexible Grids and Layouts
Responsive layouts are often based on flexible grids that use
relative units like percentages rather than fixed widths. This
ensures that the layout scales appropriately across devices.
For example, setting widths as percentages:
This creates a 3-column layout where each column takes up
33.33% of the container’s width, ensuring that the columns
adjust dynamically with the size of the screen.
c) Viewport Units
Viewport units (vw, vh, vmin, vmax) are used to create layouts
that respond to the viewport size. For example, 1vw
represents 1% of the viewport's width, and 1vh represents
1% of the viewport's height.