What Is CSS?
CSS (Cascading Style Sheets) is the style language that determines how a page written in HTML looks. Colours, fonts, spacing, page layout and adaptation to different screen sizes are defined with CSS. Its first version was published in 1996.
Separating content and appearance
HTML carries the content, CSS carries the appearance. This way, by changing a single style file you can update the look of every page of the site at once.
Rule structure
A CSS rule consists of a selector and declarations:
h1 {
color: #0000a5;
font-size: 2rem;
}
.yan-kutu { border: 1px solid #dcdde5; }
#alt a:hover { color: #ffd84a; }
| Selector | What does it select? |
|---|---|
p | All paragraphs |
.class | Elements with the given class |
#id | The single element with the given ID |
a:hover | The link being hovered over |
The box model
Every element on the page is a box. From the inside out, the layers of the box are: content, padding, border and margin. Page layout is formed by arranging these boxes side by side and one below the other.
Layout: flexbox and grid
- Flexbox is used to align elements in a single row or column (for example, menus).
- Grid divides the page into a grid of rows and columns (for example, content and sidebar).
Responsive design
Media queries are used so that the same page looks right on a phone, a tablet and a desktop:
@media (max-width: 680px) {
#content { grid-template-columns: 1fr; }
}
For a good style sheet
- Define colours and sizes in one place with CSS variables (
--mavi: #0000a5;). - Leave enough colour contrast between text and background.
- Load fonts from your own server; it is better for both speed and privacy.
Read on: What Is HTML? · Web Design