HTML CSS SQL Meta tag Generator ScrollBar design Generator Encode Decode images

CSS Basics

Introduction Syntax Selectors Attribute Selectors Specificity Combinators !important Comments Colors

CSS Need to Know

Box Model Pseudo-class Pseudo-element Inline-block Math Functions Max and Min Opacity Outline Overflow Z-index Float

Most used

Align Backgrounds Borders Text Units Padding Margins Position Tables Display Fonts Lists Height and Width

CSS Reference

CSS Properties reference CSS Pseudo-Classes reference CSS Pseudo-Elements reference CSS Selector reference

Understanding CSS @media Queries

CSS @media queries are a cornerstone of responsive web design, allowing content to adapt to different conditions such as screen sizes, orientations, and resolutions. This tutorial explores how @media queries work and lists all the possible conditions you can test for.

What are @media Queries?

@media queries in CSS allow you to apply styles based on the result of one or more media feature queries. They enhance the flexibility and responsiveness of a website by making it adapt to the user's device characteristics.

How @media Queries Work

A media query consists of a media type and can contain one or more expressions, which resolve to either true or false. The styles inside the media query are applied if the expression(s) evaluate to true. The basic syntax is:


@media [media-type] and (media-feature-rule) {
    /* CSS rules here */
}

Media types include all, print, screen, and speech. However, most modern usage of @media queries focuses on features rather than types.

List of All Possible Media Features

Examples of @media Queries in Action


/* Example: Adjusting layout for small screens */
@media screen and (max-width: 600px) {
    .container {
        padding: 10px;
    }
}

/* Example: Applying styles for print */
@media print {
    body {
        font-size: 12pt;
    }
    .navigation {
        display: none;
    }
}

/* Example: Prefer dark mode */
@media (prefers-color-scheme: dark) {
    body {
        background-color: #333;
        color: white;
    }
}

These examples demonstrate how @media queries can target different media features and types to apply specific CSS styles under certain conditions, enhancing the user experience across various devices and environments.

Conclusion

Understanding and utilizing @media queries is essential for any web developer looking to create responsive and adaptive web designs. By mastering the use of different media features, you can ensure that your website provides an optimal viewing experience on all devices and in various contexts.

.australia  {
   transform: rotateY(180deg);
}