Detailed CSS Tutorial
Detailed CSS Tutorial
1. Introduction to CSS
- What is CSS?
CSS (Cascading Style Sheets) is used to style and layout web pages. It allows you to apply colors,
- CSS Syntax:
CSS is written in rulesets that consist of a selector and a declaration block. Example:
p{
color: blue; --> This changes the text color of <p> elements to blue.
font-size: 16px; --> This changes the font size of <p> elements to 16 pixels.
- Selectors:
CSS Selectors are patterns used to select HTML elements based on their name, id, class, and
attributes.
- Objective: Create a simple webpage and apply CSS to style the text, colors, and layout.
You can set the color of text using the 'color' property. Example:
p{
color: red;
- Fonts:
The 'font-family' property defines the font type. You can also use 'font-size' and 'font-weight' to
Example:
p{
font-size: 18px;
font-weight: bold;
- `padding`: Creates space inside elements, between the content and the border.
- Objective: Create a card component with styled text, borders, margins, and padding.
You can control the size of elements using the 'width' and 'height' properties.
Example:
div {
width: 200px;
height: 100px;
- Objective: Use the box model to design a webpage layout with content, padding, and margins.
- Positioning:
The 'position' property allows you to control how elements are positioned on the page.
'float' is used to allow elements to float next to each other. 'clear' is used to prevent elements from
- Objective: Use CSS positioning to create a fixed navigation bar at the top of the page.
5. CSS Flexbox
- What is Flexbox?
Flexbox is a layout model that allows you to create flexible and responsive layouts. Flex containers
- Example:
.container {
display: flex;
- Flex Properties:
- Objective: Use Flexbox to create a responsive photo gallery that adjusts based on the screen size.
6. CSS Grid Layout
CSS Grid is a powerful layout system that allows you to create complex and responsive grid-based
layouts.
.container {
display: grid;
.grid-item {
background-color: lightblue;
padding: 20px;
- Grid Properties:
- Objective: Use CSS Grid to build a multi-section webpage layout with headers, footers, and
sidebars.