Menu

Log in

Sign up

From beginner to master of web design, coding, infrastructure operation, business development and marketing

  • COURSES
  • HTML & CSS Introduction
  • HTML & CSS Coding with AI
  • Linux Introduction
  • Docker Basics
  • Git & GitHub Introduction
  • JavaScript Coding with AI
  • Django Introduction
  • AWS Basics
  • Figma Introduction
  • SEO Tutorial for Beginners
  • SEO with AI
  • OTHERS
  • About
  • Terms of Service
  • Privacy Policy

© 2024 D-Libro. All Rights Reserved

HTML & CSS IntroductionChapter 8. CSS Basics

Chapter 8. CSS Basics

CSS Basics: An Introduction for Web Developers

In this chapter, we will dive into the basics of CSS (Cascading Style Sheets), which is the language used to style HTML elements. CSS allows you to control the layout, appearance, and presentation of web pages, providing the flexibility to design unique and user-friendly interfaces. By the end of this chapter, you will be familiar with the foundational concepts of CSS, how to apply styles to HTML elements, and how to use CSS selectors effectively.

What We Cover in This Chapter

The following topics are covered in this chapter:

What Is CSS?

In this section, we'll explore what CSS (Cascading Style Sheets) is and how it plays a crucial role in web design. CSS is a styling language used to define how HTML elements should appear on a webpage, including their layout, colors, fonts, and more. Without CSS, web pages would be bland and unstyled, lacking visual appeal and structure.

CSS Syntax

In this section, we'll cover the syntax used to write CSS rules. A CSS rule consists of a selector and a declaration block. The selector targets an HTML element, while the declaration block contains style properties and their values. For example, the rule p { color: red; } changes the color of all <p> elements to red.

Where To Type CSS?

Here, we’ll examine the different ways you can add CSS to your project. You can write CSS in an external stylesheet, within a <style> tag in your HTML document, or inline within individual HTML elements. We’ll focus on the recommended approach: writing CSS in an external stylesheet, which helps keep the structure of your HTML and CSS separate for better maintainability.

CSS Basic Selectors

In this section, we'll cover the basic CSS selectors that help you target and style specific HTML elements. The primary selectors include:

  • Element Selector: Targets all elements of a specific type (e.g., p for paragraphs).
  • Class Selector: Targets elements with a specific class attribute (e.g., .classname).
  • ID Selector: Targets elements with a specific ID attribute (e.g., #idname).

Descendant Selector

In this section, we'll explore the descendant selector, which targets elements nested inside other elements. The descendant selector is written with a space between two selectors. For example, div p { color: blue; } will apply the color blue to all <p> elements inside <div> elements.

Inheritance

CSS inheritance is the mechanism by which certain properties (like color and font) are passed down from parent elements to their child elements. In this section, we’ll explain how inheritance works, using an example where setting a color on the <body> element automatically applies that color to all text within it unless otherwise specified.

Specificity

In this section, we’ll cover how CSS specificity determines which styles are applied when conflicting rules are encountered. Specificity is calculated based on the types of selectors used. For instance, ID selectors are more specific than class selectors, and class selectors are more specific than element selectors. We'll dive into examples to help clarify how specificity works and why it’s important.

Reset CSS

Reset CSS is a technique used to eliminate the default browser styles that can cause inconsistencies. In this section, we’ll explain the importance of using a reset stylesheet to provide a consistent starting point for styling, ensuring that elements such as margins and padding are reset across different browsers.

Browser Developer Tools for CSS

In this section, we'll explore how browser developer tools can assist in inspecting and editing CSS directly within the browser. These tools are invaluable for testing styles in real-time, troubleshooting issues, and viewing how your page renders across different screen sizes and devices.

Comments in CSS Document

Finally, we’ll look at how to use comments in CSS to annotate your code. Comments are useful for documenting your work and explaining complex sections of code. They’re ignored by the browser and do not affect the rendering of the page. CSS comments are written between /* and */, like this: /* This is a comment */.

Learn offline for better focus!
A book for this course is available on Amazon.

HTML & CSS Visual Guide

Step By Step Manual for Complete Beginners with Zero Coding Experience to Build Stunning Websites from Scratch

Your browser does not support the video tag.
Get the Book Now

More Topics to Explore

CSS Styling Techniques: From Elements to Web Pages

Key Design Points by CSS

Website File Naming: File Name Rules & Best Practices

File Name Rules

Implementing Flex Box for Modern CSS Layouts

Chapter 15. CSS: Layout – Flex Box

Figma User Interface (UI) and Version Control

Figma User Interface (UI) and Version Control

How to Embed Images Using the <img> Tag

Embed Images – <img>

CSS Styling Techniques: From Elements to Web Pages

Key Design Points by CSS

Website File Naming: File Name Rules & Best Practices

File Name Rules

Implementing Flex Box for Modern CSS Layouts

Chapter 15. CSS: Layout – Flex Box

Figma User Interface (UI) and Version Control

Figma User Interface (UI) and Version Control

How to Embed Images Using the <img> Tag

Embed Images – <img>

Tags:

ResetCSS

Developer Tool

Inheritance

Selector

HTML & CSS Introduction
Course Content

Chapter 1. Overview of Website Development

How Websites Work?

Designing, Building and Publishing Websites

Designing Websites

Building Websites – Frontend and Backend Coding

Web App vs. Website

Frontend Coding

Web Framework and CMS

Publishing Websites (Hosting Services)

Chapter 2. Preparing for Website Coding

Two Key Tools to Start Coding Websites

How Browsers Display Web Pages

File Name Rules

Website Directory Structure

Absolute Path vs. Relative Path

Chapter 3. HTML Basics

What Is HTML?

HTML Element

Attribute

HTML Document Structure

Layout Semantics

Heading and Paragraph Tag

Text-Level Semantics

Space, Line-break and Tag in Content

Comments in HTML Document

Chapter 4. HTML: Add Links and Images

Overview of Adding Links and Images

Embed Images – <img>

Image File Format

Add Hyperlinks – <a>

Add Hyperlinks to Images

Add Hyperlinks to Specific Location on Web Page

Link Tag – <link>

Script Tag – <script>

Chapter 5. HTML: Create Lists and Tables

Create Lists

Create Tables

Combine Table Cells

Chapter 6. HTML: Create Forms

Create Forms

Create Text Input Forms and Submit Button

Radio Button and Checkbox

Select Box

Labels

Auto Complete and Disabled

Chapter 7. Bridging HTML and CSS

Block Element vs. Inline Element

Nesting Elements – Parent Elements and Child Elements

Div vs. Span

Global Attribute – Class, ID and Style

Accordion – <Details> and <Summary>

Chapter 8. CSS Basics

What Is CSS?

CSS Syntax

Where To Type CSS?

CSS Basic Selectors

Descendant Selector

Inheritance

Specificity

Reset CSS

Browser Developer Tools for CSS

Comments in CSS Document

Chapter 9. Web Design Basics

Design Element Representation in HTML and CSS

Key Design Points by CSS

Length

Color Code – HEX and RGB

Color Theme

Chapter 10. CSS: Sizing and Spacing

CSS Box Model

width and height

padding

margin

Margin and Padding for Specific Side

margin: auto

box-sizing

Chapter 11. CSS: Styling Text and Images

Text Styling Properties

font-size

color

font-family

Web Font and Google Font

font-weight and font-style

text-decoration

line-height and letter-spacing

text-align

vertical-align

Styling Images

float: left and right

Chapter 12. CSS: Styling Backgrounds

background-color

background-image

background-size

background-repeat

background-position

background-attachment

background (Multiple Properties)

Chapter 13. CSS: Styling Borders and Drawing Lines

border-style

border-color

border-width

border-radius

Border (Multiple Properties)

Borders on Specific Side

Border Radius on Specific Side

Chapter 14. CSS: Layout – Key Concepts and Display Property

Layout Before and After

Layout Key Design Points

Display Property

inline, block and inline-block

display: none

Chapter 15. CSS: Layout – Flex Box

Flex Box – display: flex

flex-direction

Main Axis and Cross Axis

flex-wrap

justify-content

align-items

align-content

align-self

flex-grow

flex-shrink

flex-basis

margin: auto with Flex Box

Inline Flex Box

Nested Flex Box

Chapter 16. CSS: Styling Lists

List Styling Properties

list-style-type

list-style-image

list-style-position

Chapter 17. Creating and Styling Components

Components and Layout

Buttons

Cards

Top Bar

Footer and Bottom Bar

Chapter 18. Completing Website Development

Website Structure Design

Live Server

Home (Landing) Page Development

Main (List) Page Development

Content (Detail) Page Development

Chapter 19. Publishing Websites

Key Steps to Publish Websites

Domain and DNS Server

Favicon

GitHub Pages

Chapter 20. Supplemental Topics

Horizontal Rule – <hr>

Line Break – <br>

Reserved Characters and HTML Entities

Non-breaking Space – &nbsp;

Chapter 1. Overview of Website Development

How Websites Work?

Designing, Building and Publishing Websites

Designing Websites

Building Websites – Frontend and Backend Coding

Web App vs. Website

Frontend Coding

Web Framework and CMS

Publishing Websites (Hosting Services)

Chapter 2. Preparing for Website Coding

Two Key Tools to Start Coding Websites

How Browsers Display Web Pages

File Name Rules

Website Directory Structure

Absolute Path vs. Relative Path

Chapter 3. HTML Basics

What Is HTML?

HTML Element

Attribute

HTML Document Structure

Layout Semantics

Heading and Paragraph Tag

Text-Level Semantics

Space, Line-break and Tag in Content

Comments in HTML Document

Chapter 4. HTML: Add Links and Images

Overview of Adding Links and Images

Embed Images – <img>

Image File Format

Add Hyperlinks – <a>

Add Hyperlinks to Images

Add Hyperlinks to Specific Location on Web Page

Link Tag – <link>

Script Tag – <script>

Chapter 5. HTML: Create Lists and Tables

Create Lists

Create Tables

Combine Table Cells

Chapter 6. HTML: Create Forms

Create Forms

Create Text Input Forms and Submit Button

Radio Button and Checkbox

Select Box

Labels

Auto Complete and Disabled

Chapter 7. Bridging HTML and CSS

Block Element vs. Inline Element

Nesting Elements – Parent Elements and Child Elements

Div vs. Span

Global Attribute – Class, ID and Style

Accordion – <Details> and <Summary>

Chapter 8. CSS Basics

What Is CSS?

CSS Syntax

Where To Type CSS?

CSS Basic Selectors

Descendant Selector

Inheritance

Specificity

Reset CSS

Browser Developer Tools for CSS

Comments in CSS Document

Chapter 9. Web Design Basics

Design Element Representation in HTML and CSS

Key Design Points by CSS

Length

Color Code – HEX and RGB

Color Theme

Chapter 10. CSS: Sizing and Spacing

CSS Box Model

width and height

padding

margin

Margin and Padding for Specific Side

margin: auto

box-sizing

Chapter 11. CSS: Styling Text and Images

Text Styling Properties

font-size

color

font-family

Web Font and Google Font

font-weight and font-style

text-decoration

line-height and letter-spacing

text-align

vertical-align

Styling Images

float: left and right

Chapter 12. CSS: Styling Backgrounds

background-color

background-image

background-size

background-repeat

background-position

background-attachment

background (Multiple Properties)

Chapter 13. CSS: Styling Borders and Drawing Lines

border-style

border-color

border-width

border-radius

Border (Multiple Properties)

Borders on Specific Side

Border Radius on Specific Side

Chapter 14. CSS: Layout – Key Concepts and Display Property

Layout Before and After

Layout Key Design Points

Display Property

inline, block and inline-block

display: none

Chapter 15. CSS: Layout – Flex Box

Flex Box – display: flex

flex-direction

Main Axis and Cross Axis

flex-wrap

justify-content

align-items

align-content

align-self

flex-grow

flex-shrink

flex-basis

margin: auto with Flex Box

Inline Flex Box

Nested Flex Box

Chapter 16. CSS: Styling Lists

List Styling Properties

list-style-type

list-style-image

list-style-position

Chapter 17. Creating and Styling Components

Components and Layout

Buttons

Cards

Top Bar

Footer and Bottom Bar

Chapter 18. Completing Website Development

Website Structure Design

Live Server

Home (Landing) Page Development

Main (List) Page Development

Content (Detail) Page Development

Chapter 19. Publishing Websites

Key Steps to Publish Websites

Domain and DNS Server

Favicon

GitHub Pages

Chapter 20. Supplemental Topics

Horizontal Rule – <hr>

Line Break – <br>

Reserved Characters and HTML Entities

Non-breaking Space – &nbsp;