css
css
CSS (Cascading Style Sheets) is a stylesheet language used to control the presentation of web
pages. It allows developers to separate content (HTML) from design and layout, making websites
more visually appealing and easier to maintain.
What is CSS?
CSS defines how HTML elements are displayed on the screen, paper, or other media. It is the
cornerstone of modern web design and development, enabling developers to apply styles like
colors, layouts, fonts, and animations.
Separation of Concerns: Keeps HTML focused on structure and CSS focused on styling.
CSS 2 (1998): Added positioning, media types, and advanced layout options.
CSS 3 (2012): Modularized development with advanced animations, transitions, and responsive
design tools.
CSS Today: Includes custom properties, grid, flexbox, and Houdini APIs.
HTML structures the content of a webpage, and CSS is applied to style it. CSS rules target HTML
elements using selectors to define the appearance of specific parts of the webpage.
Example:
HTML
```html
<h1>Hello, World!</h1>
```
CSS
```css
h1 {
color: blue;
text-align: center;
```
Output: A blue, center-aligned heading.
CSS relies on a simple syntax and a robust set of tools to style web pages effectively. Let’s explore
the foundational concepts of CSS.
CSS Syntax
```css
selector {
property: value;
```
Example:
```css
p {
font-size: 16px;
color: gray;
```
CSS Selectors
```css
h1 {
color: red;
```
```css
.highlight {
background-color: yellow;
```
```css
#header {
font-size: 24px;
```
input[type="text"] {
```
CSS properties define what aspect of the element to style, while values set the specific styling.
Units in CSS
Example:
```css
div {
width: 50%;
font-size: 2rem;
```
Applying CSS
```html
```
<style>
h1 {
color: blue;
</style>
```
```html
```
---
Chapter Summary
```css
h1 {
font-size: 24px;
font-weight: bold;
}
```
Properties:
```css
p {
text-align: center;
line-height: 1.6;
letter-spacing: 2px;
```
```css
div {
width: 300px;
padding: 10px;
margin: 15px;
```
Flexbox Layout
```css
.container {
display: flex;
justify-content: center;
align-items: center;
```
Chapter 5: Responsive Design
Media Queries
```css
body {
background-color: lightblue;
```
**Responsive Images**
```css
img {
max-width: 100%;
height: auto;
```
---
Color Values
Hex: `#ff5733`
Gradients
```css
div {
```
CSS Transitions
```css
button {
button:hover {
background-color: lightblue;
```
Keyframe Animations
```css
@keyframes move {
0% { transform: translateX(0); }
}
div {
```
Pseudo-classes
```css
a:hover {
color: red;
```
Pseudo-elements
```css
p::first-letter {
font-size: 2em;
color: blue;
```
Attribute Selectors
```css
input[type="text"] {
```
```scss
$primary-color: blue;
button {
background-color: $primary-color;
Benefits
Bootstrap
```html
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bootstrap/dist/css/bootstrap.min.css">
<div class="container">
</div>
```
Tailwind CSS
```html
</div>
```
Optimization
BEM Methodology
```css
.block__element--modifier {
color: red;
```
Atomic CSS
```css
.mt-4 {
margin-top: 4px;
```
CSS Houdini
Custom Properties
```css
:root {
--main-color: blue;
h1 {
color: var(--main-color);
```
Debugging Tools
Common Mistakes
This structure provides comprehensive coverage from basics to advanced CSS topics.