Monday, 14 October 2024

Css tutorial

 


Lesson 1: Understanding HTML Elements

This lesson will introduce HTML elements and how to create them.

Elements Covered:

  • <div>

  • <button>

  • <h1>

  • <body>

  • <header>

  • <footer>

Example:

html

Copy

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <title>HTML Elements</title>

</head>

<body>

    <header>This is the header</header>

    <div>This is a div</div>

    <button>Click me</button>

    <h1>This is a heading</h1>

    <footer>This is the footer</footer>

</body>

</html>


Lesson 2: Attributes

In this lesson, you will explain attributes like style, width, height, and class.

Example:

html

Copy


<div style="background-color: yellow; width: 100px; height: 100px;">Styled Div</div>


Lesson 3: Basic Styling

This lesson will cover basic styling such as background color, font color, and font size.

Example:

html

Copy


<div style="background-color: lightblue; color: navy; font-size: 20px;">Styled Text</div>


Lesson 4: CSS Selectors

Teach different types of CSS selectors: universal (*), element (div), ID (#id), and class (.class).

Example:

html

Copy


<style>

    * { color: red; }

    div { background-color: lightgrey; }

    #unique { font-size: 25px; }

    .highlight { background-color: yellow; }

</style>


<div>This is a div</div>

<div id="unique">This is a unique div</div>

<div class="highlight">This is a highlighted div</div>


Lesson 5: Box Model & Layout

Explain margin, padding, flex, and position with examples.

Example:

html

Copy


<style>

    .box {

        width: 100px;

        height: 100px;

        margin: 10px;

        padding: 20px;

        background-color: lightblue;

    }

    .container {

        display: flex;

        justify-content: center;

        align-items: center;

        height: 200px;

    }

</style>


<div class="container">

    <div class="box">Box with margin and padding</div>

</div>


Lesson 6: Creating a Login Box

HTML Structure:

html

Copy


<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Login Form</title>

    <link rel="stylesheet" href="styles.css">

</head>

<body>

    <div class="login-container">

        <h2>Login</h2>

        <form>

            <label for="username">Username</label>

            <input type="text" id="username" name="username" required>

            

            <label for="password">Password</label>

            <input type="password" id="password" name="password" required>

            

            <button type="submit">Login</button>

        </form>

    </div>

</body>

</html>


CSS Styling:

css

Copy


body {

    display: flex;

    justify-content: center;

    align-items: center;

    height: 100vh;

    background-color: #f0f0f0;

}


.login-container {

    background-color: white;

    padding: 20px;

    border-radius: 8px;

    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);

    width: 300px;

    text-align: center;

}


h2 {

    margin-bottom: 20px;

}


label {

    display: block;

    margin-bottom: 5px;

    text-align: left;

}


input {

    width: 100%;

    padding: 10px;

    margin-bottom: 20px;

    border: 1px solid #ccc;

    border-radius: 4px;

}


button {

    width: 100%;

    padding: 10px;

    background-color: #007bff;

    border: none;

    color: white;

    font-size: 16px;

    border-radius: 4px;

    cursor: pointer;

}


button:hover {

    background-color: #0056b3;

}


This example provides a basic login form with a username and password field, along with a submit button. The CSS styles ensure the form is centered on the page and gives it a clean, modern look.


Lesson 7: Centering a Login Box Using Flexbox and Positioning

HTML Structure:

html

Copy


<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Centered Login Form</title>

    <link rel="stylesheet" href="styles.css">

</head>

<body>

    <div class="login-container">

        <h2>Login</h2>

        <form>

            <label for="username">Username</label>

            <input type="text" id="username" name="username" required>

            

            <label for="password">Password</label>

            <input type="password" id="password" name="password" required>

            

            <button type="submit">Login</button>

        </form>

    </div>

</body>

</html>


CSS Styling with Flexbox:

css

Copy


body {

    display: flex;

    justify-content: center;

    align-items: center;

    height: 100vh;

    margin: 0;

    background-color: #f0f0f0;

}


.login-container {

    background-color: white;

    padding: 20px;

    border-radius: 8px;

    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);

    width: 300px;

    text-align: center;

}


h2 {

    margin-bottom: 20px;

}


label {

    display: block;

    margin-bottom: 5px;

    text-align: left;

}


input {

    width: 100%;

    padding: 10px;

    margin-bottom: 20px;

    border: 1px solid #ccc;

    border-radius: 4px;

}


button {

    width: 100%;

    padding: 10px;

    background-color: #007bff;

    border: none;

    color: white;

    font-size: 16px;

    border-radius: 4px;

    cursor: pointer;

}


button:hover {

    background-color: #0056b3;

}


CSS Styling with Positioning:

css

Copy


body {

    position: relative;

    height: 100vh;

    margin: 0;

    background-color: #f0f0f0;

}


.login-container {

    position: absolute;

    top: 50%;

    left: 50%;

    transform: translate(-50%, -50%);

    background-color: white;

    padding: 20px;

    border-radius: 8px;

    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);

    width: 300px;

    text-align: center;

}


h2 {

    margin-bottom: 20px;

}


label {

    display: block;

    margin-bottom: 5px;

    text-align: left;

}


input {

    width: 100%;

    padding: 10px;

    margin-bottom: 20px;

    border: 1px solid #ccc;

    border-radius: 4px;

}


button {

    width: 100%;

    padding: 10px;

    background-color: #007bff;

    border: none;

    color: white;

    font-size: 16px;

    border-radius: 4px;

    cursor: pointer;

}


button:hover {

    background-color: #0056b3;

}


With these methods, you can use either flexbox or absolute positioning to center the login box both horizontally and vertically.


Lesson 8: Positioning in CSS

Explanation:

This lesson will cover different CSS position properties: static, relative, absolute, fixed, and sticky.

Examples:

  1. Static Positioning:

  2. html

  3. Copy


<div style="position: static; background-color: lightblue;">Static Position</div>



  1. Relative Positioning:

  2. html

  3. Copy

<div style="position: relative; top: 10px; background-color: lightgreen;">Relative Position</div>


  1. Absolute Positioning:

  2. html

  3. Copy


<div style="position: absolute; top: 20px; left: 50px; background-color: lightcoral;">Absolute Position</div>



  1. Fixed Positioning:

  2. html

  3. Copy


<div style="position: fixed; bottom: 10px; right: 10px; background-color: lightgoldenrodyellow;">Fixed Position</div>



  1. Sticky Positioning:

  2. html

  3. Copy


<div style="position: sticky; top: 0; background-color: lightpink;">Sticky Position</div>



Lesson 9: Margin in CSS

Explanation:

This lesson will explain how to use margin in CSS to create space around elements.

Examples:

  1. Margin Top:

  2. html

  3. Copy


<div style="margin-top: 20px; background-color: lightblue;">Margin Top</div>



  1. Margin Right:

  2. html

  3. Copy


<div style="margin-right: 20px; background-color: lightgreen;">Margin Right</div>



  1. Margin Bottom:

  2. html

  3. Copy


<div style="margin-bottom: 20px; background-color: lightcoral;">Margin Bottom</div>



  1. Margin Left:

  2. html

  3. Copy


<div style="margin-left: 20px; background-color: lightgoldenrodyellow;">Margin Left</div>



  1. Margin All Sides:

  2. html

  3. Copy


<div style="margin: 20px; background-color: lightpink;">Margin All Sides</div>


Lesson 10: Padding in CSS

Explanation:

This lesson will demonstrate how to use padding to create space inside elements.

Examples:

  1. Padding Top:

  2. html

  3. Copy


<div style="padding-top: 20px; background-color: lightblue;">Padding Top</div>



  1. Padding Right:

  2. html

  3. Copy


<div style="padding-right: 20px; background-color: lightgreen;">Padding Right</div>



  1. Padding Bottom:

  2. html

  3. Copy


<div style="padding-bottom: 20px; background-color: lightcoral;">Padding Bottom</div>



  1. Padding Left:

  2. html

  3. Copy


<div style="padding-left: 20px; background-color: lightgoldenrodyellow;">Padding Left</div>



  1. Padding All Sides:

  2. html

  3. Copy

<div style="padding: 20px; background-color: lightpink;">Padding All Sides</div>


Lesson 11: CSS Transitions

Explanation:

CSS transitions allow you to change property values smoothly over a given duration.

Examples:

  1. Basic Transition:

  2. html

  3. Copy


<style>

    .box {

        width: 100px;

        height: 100px;

        background-color: lightblue;

        transition: background-color 2s;

    }

    .box:hover {

        background-color: lightgreen;

    }

</style>


<div class="box"></div>



  1. Transition Multiple Properties:

  2. html

  3. Copy


<style>

    .box {

        width: 100px;

        height: 100px;

        background-color: lightblue;

        transition: width 2s, height 2s;

    }

    .box:hover {

        width: 200px;

        height: 200px;

    }

</style>


<div class="box"></div>


  1. Timing Function:

  2. html

  3. Copy

<style>

    .box {

        width: 100px;

        height: 100px;

        background-color: lightblue;

        transition: width 2s ease-in-out;

    }

    .box:hover {

        width: 200px;

    }

</style>


<div class="box"></div>


  1. Delay Transition:

  2. html

  3. Copy

<style>

    .box {

        width: 100px;

        height: 100px;

        background-color: lightblue;

        transition: width 2s ease-in-out 1s;

    }

    .box:hover {

        width: 200px;

    }

</style>


<div class="box"></div>



  1. Multiple States:

  2. html

  3. Copy


<style>

    .box {

        width: 100px;

        height: 100px;

        background-color: lightblue;

        transition: background-color 1s, transform 1s;

    }

    .box:hover {

        background-color: lightgreen;

        transform: rotate(45deg);

    }

    .box:active {

        background-color: coral;

        transform: scale(1.2);

    }

</style>


<div class="box"></div>



Lesson 12: CSS Gradients

Explanation:

Gradients can be linear, radial, or conic. Here are 10 examples to illustrate different types and uses.

Examples:

  1. Simple Linear Gradient:

  2. css

  3. Copy

.simple-linear {

    background: linear-gradient(to right, red, yellow);

}


  1. Diagonal Linear Gradient:

  2. css

  3. Copy

.diagonal-linear {

    background: linear-gradient(to bottom right, blue, green);

}


  1. Repeating Linear Gradient:

  2. css

  3. Copy


.repeating-linear {

    background: repeating-linear-gradient(45deg, pink, pink 10px, purple 10px, purple 20px);

}



  1. Radial Gradient:

  2. css

  3. Copy


.radial {

    background: radial-gradient(circle, red, yellow, green);

}


  1. Elliptical Radial Gradient:

  2. css

  3. Copy

.elliptical {

    background: radial-gradient(ellipse at center, blue, green, yellow);

}


  1. Repeating Radial Gradient:

  2. css

  3. Copy

.repeating-radial {

    background: repeating-radial-gradient(circle, red, yellow 10%, green 15%);

}



  1. Conic Gradient:

  2. css

  3. Copy

.conic {

    background: conic-gradient(from 0deg, red, yellow, green, blue, purple, red);

}


  1. Gradient with Transparency:

  2. css

  3. Copy

.transparent-gradient {

    background: linear-gradient(to right, rgba(255, 0, 0, 0.5), rgba(0, 255, 0, 0.5));

}


  1. Gradient Border:

  2. css

  3. Copy

.gradient-border {

    border: 5px solid;

    border-image: linear-gradient(to right, red, yellow) 1;

}


  1. Text Gradient:

  2. css

  3. Copy


.text-gradient {

    background: linear-gradient(to right, red, yellow);

    -webkit-background-clip: text;

    color: transparent;

}



Lesson 13: CSS Borders and Transparency

Explanation:

This lesson will cover how to use borders, border-radius, and transparency with the opacity property.

Examples:

  1. Basic Border:

  2. html

  3. Copy

<div style="border: 2px solid black; width: 100px; height: 100px;">Basic Border</div>


  1. Rounded Border:

  2. html

  3. Copy

<div style="border: 2px solid black; border-radius: 15px; width: 100px; height: 100px;">Rounded Border</div>


  1. Dashed and Dotted Borders:

  2. html

  3. Copy

<div style="border: 2px dashed black; width: 100px; height: 100px;">Dashed Border</div>

<div style="border: 2px dotted black; width: 100px; height: 100px;">Dotted Border</div>


  1. Different Borders on Each Side:

  2. html

  3. Copy

<div style="border-top: 2px solid black; border-right: 2px dashed black; border-bottom: 2px dotted black; border-left: 2px solid black; width: 100px; height: 100px;">Different Borders</div>


  1. Transparent Background with Border:

  2. html

  3. Copy


<div style="border: 2px solid black; background-color: rgba(0, 0, 0, 0.1); width: 100px; height: 100px;">Transparent Background</div>



  1. Opacity:

  2. html

  3. Copy


<div style="opacity: 0.5; background-color: lightblue; width: 100px; height: 100px;">50% Opacity</div>



  1. Border and Opacity Combined:

  2. html

  3. Copy

<div style="border: 2px solid black; opacity: 0.5; background-color: lightblue; width: 100px; height: 100px;">Border & Opacity</div>


  1. Border Radius with Transparency:

  2. html

  3. Copy


<div style="border: 2px solid black; border-radius: 50%; opacity: 0.7; background-color: lightgreen; width: 100px; height: 100px;">Rounded & Transparent</div>



  1. Fancy Border and Transparency:

  2. html

  3. Copy


<div style="border: 4px double red; border-radius: 10px; opacity: 0.8; background-color: lightcoral; width: 100px; height: 100px;">Fancy Border</div>



  1. Transparent Text with Border:

  2. html

  3. Copy

<div style="border: 2px solid black; color: rgba(0, 0, 0, 0.5); width: 100px; height: 100px;">Transparent Text</div>


Lesson 14: CSS Animations

Explanation:

This lesson will cover the basics of CSS animations, including defining keyframes and using the animation property.

Examples:

  1. Simple Animation:

  2. css

  3. Copy



@keyframes changeColor {

    from { background-color: red; }

    to { background-color: yellow; }

}

.simple-animation {

    width: 100px;

    height: 100px;

    background-color: red;

    animation: changeColor 2s infinite;

}



  1. Move Element:

  2. css

  3. Copy

@keyframes moveRight {

    from { transform: translateX(0); }

    to { transform: translateX(100px); }

}

.move-element {

    width: 100px;

    height: 100px;

    background-color: blue;

    animation: moveRight 2s infinite;

}


  1. Rotate Element:

  2. css

  3. Copy


@keyframes rotate {

    from { transform: rotate(0deg); }

    to { transform: rotate(360deg); }

}

.rotate-element {

    width: 100px;

    height: 100px;

    background-color: green;

    animation: rotate 2s infinite;

}


  1. Fade In and Out:

  2. css

  3. Copy

@keyframes fadeInOut {

    0% { opacity: 0; }

    50% { opacity: 1; }

    100% { opacity: 0; }

}

.fade-element {

    width: 100px;

    height: 100px;

    background-color: pink;

    animation: fadeInOut 3s infinite;

}


  1. Scale Element:

  2. css

  3. Copy


@keyframes scaleUp {

    from { transform: scale(1); }

    to { transform: scale(1.5); }

}

.scale-element {

    width: 100px;

    height: 100px;

    background-color: purple;

    animation: scaleUp 2s infinite;

}




human body with dividing header, body and footer


a complete picture of a human body with a stylish dress, showing the head and foot without covering dress


a stylish dress for a man, showing the head and foot without covering the dress


a human with a stylish dress covering the body except the head and foot

HTML Structure:

html

Copy

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Styled Man</title>

    <link rel="stylesheet" href="styles.css">

</head>

<body>

    <div class="man-container">

        <div class="head"></div>

        <div class="body"></div>

        <div class="feet"></div>

    </div>

</body>

</html>


CSS Styling:

css

Copy


body {

    display: flex;

    justify-content: center;

    align-items: center;

    height: 100vh;

    background-color: #f0f0f0;

    margin: 0;

}


.man-container {

    display: grid;

    grid-template-rows: auto 1fr auto;

    width: 200px;

    text-align: center;

}


.head {

    background-color: #ffd700; /* Golden head */

    height: 50px;

}


.body {

    background-color: #87cefa; /* Stylish blue clothes */

    height: 300px;

}


.feet {

    background-color: #d2b48c; /* Skin-colored feet */

    height: 50px;

}