CSS Course: Introduction to Advanced Concepts

1. Introduction to CSS

CSS (Cascading Style Sheets) is used to style HTML elements. It controls the layout, colors, and fonts of a webpage.

Select body


            body{
            backgrund-color:lightblue;
            }

            h1 {
                color: black;
                text-aligen:center;
            }

            p {
                font-family:verdana;
                font-size:20px;
            }

                
        
           
        

2. CSS Selectors

This is a paragraph with blue text (using element selector).

This paragraph has a yellow background (using class selector).

This text is larger (using ID selector).

3. Colors and Backgrounds

You can use color names, RGB, HEX values to define colors:

            body {
                background-color: #f4f4f4;
                color: #333;
            }
        

Background Image:

            body {
                background-image: url('background.jpg');
                background-size: cover;
            }
        

4. Text Styling

CSS allows you to modify the appearance of text:

            h1 {
                color: darkblue;
                font-size: 36px;
                text-align: center;
                text-transform: uppercase;
                line-height: 1.5;
            }
        

This is a styled Heading

5. CSS Box Model

Each HTML element is wrapped in a rectangular box. You can control the padding, border, and margin of this box:

            .box {
                padding: 20px;
                border: 2px solid black;
                margin: 10px;
            }
        
This is an example of CSS Box Model

6. CSS Layout

CSS layout properties control how elements are arranged on a webpage:

            .block {
                display: block;
            }
            .hidden {
                display: none;
            }
        
            .relative {
                position: relative;
                top: 20px;
                left: 10px;
            }
        
This is a block element.
This is a relatively positioned element.

7. Flexbox Layout

Flexbox is used to create flexible and responsive layouts:

            .container {
                display: flex;
                justify-content: space-between;
            }
            .item {
                padding: 20px;
                background-color: lightblue;
            }
        
Item 1
Item 2
Item 3

8. Grid Layout

CSS Grid allows for creating grid-based layouts:

            .grid-container {
                display: grid;
                grid-template-columns: repeat(3, 1fr);
                gap: 10px;
            }
            .grid-item {
                background-color: #b3e5fc;
                padding: 20px;
            }
        
Grid Item 1
Grid Item 2
Grid Item 3

9. Transitions and Animations

CSS allows you to add animations and transitions to elements:

            .box:hover {
                transform: scale(1.2);
                transition: transform 0.3s ease-in-out;
            }
        
Hover over me to see the animation

10. Pseudo-classes and Pseudo-elements

Pseudo-classes apply styles to elements in special states, and pseudo-elements allow targeting parts of an element.

            /* Pseudo-class example: */
            a:hover {
                color: red;
            }
    
            /* Pseudo-element example: */
            p::first-line {
                font-weight: bold;
            }
        

Hover over the link to see the effect.

This is a paragraph where the first line will be bold.

11. CSS Variables (Custom Properties)

CSS variables make your code more maintainable by allowing you to reuse values:

            :root {
                --main-color: #4CAF50;
                --padding: 10px;
            }
    
            body {
                background-color: var(--main-color);
                padding: var(--padding);
            }
        

12. Advanced Selectors

Advanced CSS selectors allow more precision when targeting elements:

            /* Example: */
            div > p {
                color: red;
            }
    
            input[type="text"] {
                border: 1px solid blue;
            }
        

13. CSS Media Queries

Media queries help you create responsive layouts that adapt to different screen sizes:

            @media screen and (max-width: 768px) {
                body {
                    background-color: lightgray;
                }
            }
    
            @media screen and (min-width: 769px) and (max-width: 1024px) {
                body {
                    background-color: lightblue;
                }
            }
        

14. CSS Transforms

CSS transforms let you manipulate the appearance of elements using rotate, scale, and translate:

            .rotate {
                transform: rotate(45deg);
            }
    
            .translate {
                transform: translate(50px, 100px);
            }
        
Rotated Box
Translated Box

15. CSS Transitions

The transition property allows smooth transitions between styles over a specific duration.

            .box {
                width: 100px;
                height: 100px;
                background-color: red;
                transition: background-color 0.5s ease;
            }
    
            .box:hover {
                background-color: blue;
            }
        
Hover me!

16. CSS Animations

The @keyframes rule allows you to create animations by gradually changing styles over time.

            @keyframes example {
                from {background-color: red;}
                to {background-color: yellow;}
            }
    
            .animate {
                width: 100px;
                height: 100px;
                background-color: red;
                animation: example 3s infinite;
            }
        
Animating Box

17. CSS Flexbox

Flexbox layout allows for responsive design by adjusting the distribution of space within a container.

            .container {
                display: flex;
                justify-content: center;
                align-items: center;
                height: 200px;
            }
    
            .item {
                background-color: lightblue;
                padding: 10px;
                margin: 5px;
            }
        
Item 1
Item 2
Item 3

18. CSS Grid

The CSS Grid layout provides a flexible way to organize content into rows and columns.

            .grid-container {
                display: grid;
                grid-template-columns: auto auto auto;
                gap: 10px;
            }
    
            .grid-item {
                background-color: lightgreen;
                padding: 20px;
                text-align: center;
            }
        
1
2
3
4
5
6

19. Responsive Design (Media Queries)

Media queries allow you to apply different styles depending on the screen size or device.

            @media only screen and (max-width: 600px) {
                .responsive-box {
                    background-color: lightblue;
                }
            }
    
            @media only screen and (min-width: 600px) {
                .responsive-box {
                    background-color: lightcoral;
                }
            }
        
Resize the screen!

20. CSS Z-Index and Stacking Context

The z-index property determines the stacking order of elements along the z-axis.

            .z-box1 {
                position: absolute;
                width: 100px;
                height: 100px;
                background-color: red;
                z-index: 2;
            }
    
            .z-box2 {
                position: absolute;
                width: 100px;
                height: 100px;
                background-color: blue;
                z-index: 1;
            }
        
Box 1
Box 2

21. CSS Shapes

The shape-outside property allows content to wrap around custom shapes.

            .shape {
                float: left;
                width: 200px;
                height: 200px;
                shape-outside: circle(50%);
                clip-path: circle(50%);
                background: lightcoral;
            }
        

This text will wrap around the circular shape. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

22. CSS Filters

Filters allow you to apply visual effects to elements, such as blur, brightness, and contrast.

            .filter-box {
                width: 200px;
                height: 200px;
                background-image: url('image.jpg');
                filter: blur(5px) brightness(0.8);
            }
        

23. CSS Variables (Custom Properties)

CSS variables allow you to define reusable values for properties.

            :root {
                --main-bg-color: lightblue;
                --main-text-color: navy;
            }
    
            .variable-box {
                background-color: var(--main-bg-color);
                color: var(--main-text-color);
                padding: 20px;
            }
        
This box uses CSS variables for background and text color.

24. CSS Positioning

CSS provides different positioning methods: static, relative, absolute, fixed, and sticky.

            .relative-box {
                position: relative;
                top: 20px;
                left: 20px;
                background-color: lightcoral;
                width: 100px;
                height: 100px;
            }
    
            .absolute-box {
                position: absolute;
                top: 50px;
                left: 50px;
                background-color: lightgreen;
                width: 100px;
                height: 100px;
            }
        
Relative
Absolute

25. CSS Pseudo-classes and Pseudo-elements

Pseudo-classes like :hover and pseudo-elements like ::before allow you to style elements based on their state or position.

            .hover-box:hover {
                background-color: lightgreen;
            }
    
            .before-box::before {
                content: "Before: ";
                color: red;
            }
        
Hover over me
This box has a pseudo-element

26. CSS Blend Modes

Blend modes determine how an element's content blends with the content behind it.

            .blend-box {
                background-image: url('image.jpg');
                background-color: red;
                background-blend-mode: multiply;
                width: 300px;
                height: 200px;
            }
        

27. CSS Object-fit and Object-position

The object-fit property controls how the content of a replaced element (such as an image or video) is resized to fit its container.

            .fit-box img {
                width: 300px;
                height: 200px;
                object-fit: cover;
            }
        
Example image

28. CSS Clipping and Masking

The clip-path and mask properties allow you to hide parts of an element in creative ways.

            .clip-box {
                width: 200px;
                height: 200px;
                background-color: lightblue;
                clip-path: circle(50%);
            }
        

29. CSS Writing Modes

Writing modes change the direction in which text is laid out. This is useful for vertical text or languages that are read top-to-bottom.

            .vertical-text {
                writing-mode: vertical-rl;
                text-orientation: upright;
                background-color: lightyellow;
                padding: 10px;
            }
        
This is vertical text!

30. CSS Counters

CSS counters allow you to create custom numbering for lists and other elements using counter-reset and counter-increment.

            ol {
                counter-reset: my-counter;
            }
    
            li {
                counter-increment: my-counter;
            }
    
            li::before {
                content: counter(my-counter) ". ";
                font-weight: bold;
            }
        
  1. First item
  2. Second item
  3. Third item

31. CSS Media Queries (Responsive Design)

Media queries allow you to apply different styles for different screen sizes, making your website responsive.

            .box {
                width: 100%;
                background-color: lightblue;
            }
    
            @media (min-width: 600px) {
                .box {
                    width: 50%;
                }
            }
        
Resize the window to see the effect

32. CSS Grid Layout

CSS Grid allows you to create complex grid layouts for your web pages.

            .grid-container {
                display: grid;
                grid-template-columns: auto auto auto;
                gap: 10px;
            }
    
            .grid-item {
                background-color: lightcoral;
                padding: 20px;
                text-align: center;
            }
        
1
2
3

33. CSS Subgrid

The subgrid value allows nested grid items to inherit the parent's grid lines, making it easier to create consistent layouts.

            .grid-container {
                display: grid;
                grid-template-columns: 1fr 1fr;
                gap: 10px;
            }
    
            .nested-grid {
                display: grid;
                grid-template-columns: subgrid;
            }
    
            .nested-item {
                background-color: lightgreen;
                padding: 10px;
                text-align: center;
            }
        
Nested 1
Nested 2

34. CSS Transitions

Transitions allow you to smoothly animate changes to CSS properties over time.

            .transition-box {
                width: 100px;
                height: 100px;
                background-color: lightblue;
                transition: background-color 0.5s ease;
            }
    
            .transition-box:hover {
                background-color: lightcoral;
            }
        
Hover me

35. CSS Animations

CSS animations allow you to create complex animations using keyframes that describe the stages of the animation.

            @keyframes slide {
                from {
                    transform: translateX(0);
                }
                to {
                    transform: translateX(100px);
                }
            }
    
            .animate-box {
                width: 100px;
                height: 100px;
                background-color: lightgreen;
                animation: slide 2s infinite alternate;
            }
        

36. CSS Flexbox

Flexbox is a layout module that allows items to align and distribute space within a container efficiently, even when their size is dynamic or unknown.

            .flex-container {
                display: flex;
                justify-content: space-around;
            }
    
            .flex-item {
                background-color: lightblue;
                padding: 10px;
                width: 100px;
                text-align: center;
            }
        
1
2
3

37. CSS Scroll Snap

CSS Scroll Snap allows you to control the snapping behavior during scrolling, creating more precise scroll points.

            .snap-container {
                scroll-snap-type: y mandatory;
                height: 300px;
                overflow-y: scroll;
            }
    
            .snap-item {
                height: 300px;
                scroll-snap-align: start;
                background-color: lightblue;
                padding: 20px;
                margin-bottom: 10px;
            }
        
Item 1
Item 2
Item 3

38. CSS Multi-Column Layout

The multi-column layout allows you to split content into multiple columns, similar to how content is presented in newspapers or magazines.

            .multi-column {
                column-count: 3;
                column-gap: 20px;
            }
        

This is some text that will be split into multiple columns. The layout automatically adjusts the content based on the number of columns.

39. CSS Object Fit and Object Position

Object Fit allows you to control how images or media are resized to fit their containers, while Object Position allows you to position the media inside its container.

            .fit-container {
                width: 300px;
                height: 200px;
                background-color: lightgray;
            }
    
            .fit-image {
                width: 100%;
                height: 100%;
                object-fit: cover;
            }
        
Object Fit Example

40. CSS Shapes

CSS Shapes allow you to wrap text around custom shapes rather than just rectangular boxes.

            .shape-container {
                float: left;
                shape-outside: circle(50%);
                width: 200px;
                height: 200px;
                background-color: lightblue;
                border-radius: 50%;
            }
        

This text will wrap around the circular shape, creating a more dynamic and visually interesting layout.

41. CSS Custom Properties (Variables)

CSS Custom Properties allow you to define reusable variables in your stylesheets, making it easier to maintain consistent design values.

            :root {
                --primary-color: lightblue;
                --secondary-color: lightcoral;
            }
    
            .variable-box {
                background-color: var(--primary-color);
                color: var(--secondary-color);
                padding: 20px;
            }
        
This box uses CSS variables!

42. CSS Box Alignment

Box Alignment in CSS allows you to align elements both horizontally and vertically within flex and grid layouts.

            .alignment-container {
                display: flex;
                justify-content: center;
                align-items: center;
                height: 200px;
                background-color: lightgray;
            }
    
            .alignment-item {
                padding: 20px;
                background-color: lightblue;
            }
        
Centered Item

43. CSS Pseudo-Classes and Pseudo-Elements

Pseudo-classes and pseudo-elements allow you to style elements based on their state or insert content before or after an element.

            a:hover {
                color: red;
            }
    
            p::before {
                content: "Note: ";
                font-weight: bold;
            }
        

Hover over the link to see the pseudo-class in action.

This paragraph demonstrates the ::before pseudo-element.

44. CSS Grid Layout

The CSS Grid Layout module allows you to create complex web layouts by using a two-dimensional grid system, offering flexibility in aligning content in rows and columns.

            .grid-container {
                display: grid;
                grid-template-columns: repeat(3, 1fr);
                gap: 20px;
            }
    
            .grid-item {
                background-color: lightcoral;
                padding: 20px;
                text-align: center;
            }
        
1
2
3

45. CSS Flexbox Layout

Flexbox is a one-dimensional layout method for laying out items in rows or columns. It simplifies the process of aligning and distributing space among items in a container.

            .flex-container {
                display: flex;
                justify-content: space-between;
            }
    
            .flex-item {
                background-color: lightgreen;
                padding: 20px;
                text-align: center;
            }
        
Item 1
Item 2
Item 3

46. CSS Animations

CSS Animations allow you to animate the transitions between various CSS properties, creating smooth, interactive experiences.

            .animate-box {
                width: 100px;
                height: 100px;
                background-color: lightcoral;
                animation: move 2s infinite;
            }
    
            @keyframes move {
                0% { transform: translateX(0); }
                50% { transform: translateX(100px); }
                100% { transform: translateX(0); }
            }
        

47. CSS Transitions

CSS Transitions make it easy to change the property values of an element smoothly over a specific duration.

            .transition-box {
                width: 100px;
                height: 100px;
                background-color: lightblue;
                transition: background-color 1s ease;
            }
    
            .transition-box:hover {
                background-color: lightgreen;
            }
        

48. CSS Grid vs. Flexbox

CSS Grid and Flexbox are both powerful layout systems, but they serve different purposes. Grid is best for 2D layouts, while Flexbox is for 1D layouts.

            /* Flexbox */
            .flex-container {
                display: flex;
                justify-content: space-around;
            }
    
            /* Grid */
            .grid-container {
                display: grid;
                grid-template-columns: repeat(3, 1fr);
            }
        
Flexbox Item 1
Flexbox Item 2
Flexbox Item 3
Grid Item 1
Grid Item 2
Grid Item 3

49. CSS Logical Properties and Values

CSS Logical Properties allow you to control layout and design in a language-independent way, useful for supporting right-to-left (RTL) or left-to-right (LTR) languages.

            .logical-box {
                inline-size: 200px;
                block-size: 100px;
                margin-inline: auto;
                padding-block: 20px;
                background-color: lightpink;
            }
        
Logical Properties Box

50. CSS Cascade and Specificity

The cascade and specificity in CSS determine how conflicting styles are resolved and which styles are applied to an element based on their importance.

            /* Specificity */
            p {
                color: blue; /* Low specificity */
            }
    
            .specific-class {
                color: red; /* Higher specificity */
            }
    
            #specific-id {
                color: green; /* Highest specificity */
            }
        

This text will be green due to CSS specificity.