M.

Home / Software Development Content

HTML Beginner Course

  1. CSS Introduction
  2. CSS Syntax
  3. CSS Integration HTML Document
  4. CSS Colors
  5. CSS Backgrounds
  6. CSS Borders
  7. CSS Paddings
  8. CSS Margins
  9. CSS Outline
  10. CSS Selectors
  11. CSS Alignment (Text/Image/content)
  12. CSS Width and Height
  13. CSS Text and Fonts
  14. CSS Links
  15. CSS Buttons
  16. CSS Flex Box
  17. CSS Forms
  18. CSS Lists
  19. CSS Media Queries

CSS Introduction

Syntax:


            selector {
              property: value;
            }
            

Code Example:

body {
              background-color: lightblue;
            }
            

Exercise:


CSS Syntax

Syntax:

selector {
              property: value;
            }
            

Code Example:

h1 {
              color: red;
              font-size: 24px;
            }
            

Exercise:


CSS Integration HTML Document

Syntax:

<!DOCTYPE html>
            <html>
            <head>
              <link rel="stylesheet" href="styles.css">
            </head>
            <body>
              <h1>This is a Heading</h1>
              <p>This is a paragraph.</p>
            </body>
            </html>
            

Code Example:

/* styles.css */
            h1 {
              color: blue;
            }
            
            p {
              color: green;
            }
            

Exercise:


CSS Colors

Syntax:

p {
              color: #ff6347; /* Tomato */
            }
            
            h2 {
              color: rgb(0, 255, 0); /* Lime */
            }
            
            div {
              color: rgba(0, 0, 255, 0.5); /* Semi-transparent Blue */
            }
            
            span {
              color: hsl(120, 100%, 50%); /* Green */
            }
            

Exercise:


CSS Backgrounds

Syntax:

div {
              background-color: lightgray;
              background-image: url('background.jpg');
              background-repeat: no-repeat;
              background-position: center;
              background-size: cover;
            }
            

Exercise:


CSS Borders

Syntax:

div {
              border-width: 2px;
              border-style: solid;
              border-color: black;
            }
            

Code Example:

p {
              border: 1px solid red;
            }
            

Exercise:


CSS Paddings

Syntax:

div {
              padding: 20px; /* All sides */
              padding-top: 10px; /* Top side only */
              padding-right: 15px; /* Right side only */
            }
            

Code Example:

section {
              padding: 15px;
            }
            

Exercise:


CSS Margins

Syntax:

div {
              margin: 30px; /* All sides */
              margin-bottom: 20px; /* Bottom side only */
            }
            

Code Example:

article {
              margin: 20px;
            }
            

Exercise:


CSS Outline

Syntax:

div {
              outline-width: 3px;
              outline-style: dotted;
              outline-color: blue;
              outline-offset: 5px;
            }
            

Code Example:

input {
              outline: 2px dashed green;
            }
            

Exercise:


CSS Selectors

Syntax:

/* Element Selector */
            p {
              color: blue;
            }
            
            /* Class Selector */
            .button {
              background-color: yellow;
            }
            
            /* ID Selector */
            #header {
              font-size: 24px;
            }
            
            /* Attribute Selector */
            input[type="text"] {
              border: 1px solid gray;
            }
            

Code Example:

h2 {
              color: purple;
            }
            
            .highlight {
              background-color: yellow;
            }
            
            #unique {
              margin: 10px;
            }
            

Exercise:


CSS Alignment (Text/Image/Content)

Syntax:

/* Text Alignment */
            p {
              text-align: center; /* Options: left, right, center, justify */
            }
            
            /* Vertical Alignment */
            img {
              vertical-align: middle; /* Options: baseline, sub, super, top, middle, bottom */
            }
            
            /* Image Alignment */
            img {
              float: left; /* Options: left, right, none */
            }
            

Code Example:

h1 {
              text-align: right;
            }
            
            img {
              vertical-align: top;
              float: right;
            }
            

Exercise:


CSS Width & Height

Syntax:

div {
              width: 50%; /* Percentage */
              height: 200px; /* Pixels */
            }
            

Code Example:

.container {
              width: 100vw; /* Full viewport width */
              height: 100vh; /* Full viewport height */
            }
            

Exercise:


CSS Text & Fonts

Syntax:

p {
              font-family: Arial, sans-serif;
              font-size: 16px;
              font-weight: bold; /* Options: normal, bold, bolder, lighter, or numerical values */
              line-height: 1.5;
              text-transform: uppercase; /* Options: uppercase, lowercase, capitalize, none */
            }
            

Code Example:

h2 {
              font-family: 'Georgia', serif;
              font-size: 24px;
              text-transform: capitalize;
            }
            

Exercise:


Syntax:

a:link {
              color: blue; /* Unvisited link */
            }
            
            a:visited {
              color: purple; /* Visited link */
            }
            
            a:hover {
              color: red; /* Mouse over link */
            }
            
            a:active {
              color: orange; /* Clicked link */
            }
            

Code Example:

a {
              text-decoration: none; /* Remove underline */
            }
            
            a:hover {
              text-decoration: underline; /* Underline on hover */
            }
            

Exercise:


CSS Buttons

Syntax:

button {
              background-color: blue;
              color: white;
              border: none;
              padding: 10px 20px;
              font-size: 16px;
              cursor: pointer; /* Change cursor on hover */
            }
            
            button:hover {
              background-color: darkblue;
            }
            
            button:active {
              background-color: navy;
            }
            

Code Example:

.btn-primary {
              background-color: green;
              border-radius: 5px; /* Rounded corners */
            }
            
            .btn-primary:hover {
              background-color: darkgreen;
            }
            

Exercise:


CSS Flex Box

Syntax:

.container {
              display: flex;
              flex-direction: row; /* or column */
              justify-content: center;
              align-items: center;
            }
            

Code Example:

.flex-container {
              display: flex;
              flex-direction: column;
              justify-content: space-between;
              align-items: center;
            }
            
            .flex-item {
              margin: 10px;
            }
            

Exercise:


CSS Forms

Syntax:

input, textarea, select, button {
              padding: 10px;
              border: 1px solid #ccc;
              font-size: 16px;
            }
            

Code Example:

input[type="text"] {
              border-radius: 5px; /* Rounded corners */
            }
            
            textarea {
              resize: vertical; /* Allow vertical resizing only */
            }
            
            button {
              background-color: #4CAF50; /* Green */
              color: white;
            }
            

Exercise:


CSS Lists

Syntax:

ul {
              list-style-type: circle;
              list-style-position: inside;
            }
            
            ol {
              list-style-type: decimal;
            }
            
            ul.custom {
              list-style-image: url('bullet.png');
            }
            

Code Example:

ul {
              list-style-type: square;
              padding-left: 20px;
            }
            
            ol {
              list-style-type: lower-alpha;
            }
            

Exercise:


CSS Media Queries

Syntax:

/* Styles for devices with a max-width of 600px */
            @media (max-width: 600px) {
              body {
                background-color: lightyellow;
              }
            
              .container {
                padding: 10px;
              }
            }
            
            /* Styles for devices with a min-width of 601px */
            @media (min-width: 601px) {
              body {
                background-color: lightblue;
              }
            }
            

Code Example:

@media (max-width: 768px) {
              .sidebar {
                display: none; /* Hide sidebar on small screens */
              }
            }
            
            @media (min-width: 769px) {
              .sidebar {
                display: block; /* Show sidebar on larger screens */
              }
            }
            

Exercise: