bg_image
header

Media Queries

CSS Media Queries are a technique in CSS that allows a webpage layout to adapt to different screen sizes, resolutions, and device types. They are a core feature of Responsive Web Design.

Syntax:

@media (condition) {
    /* CSS rules that apply only under this condition */
}

Examples:

1. Adjusting for different screen widths:

/* For screens with a maximum width of 600px (e.g., smartphones) */
@media (max-width: 600px) {
    body {
        background-color: lightblue;
    }
}

2. Detecting landscape vs. portrait orientation:

@media (orientation: landscape) {
    body {
        background-color: lightgreen;
    }
}

3. Styling for print output:

@media print {
    body {
        font-size: 12pt;
        color: black;
        background: none;
    }
}

Common Use Cases:

Mobile-first design: Optimizing websites for small screens first and then expanding for larger screens.
Dark mode: Adjusting styles based on user preference (prefers-color-scheme).
Retina displays: Using high-resolution images or specific styles for high pixel density screens (min-resolution: 2dppx).


Responsive Design

What is Responsive Design?

Responsive Design is a web design approach that allows a website to automatically adjust to different screen sizes and devices. This ensures a seamless user experience across desktops, tablets, and smartphones without needing separate versions of the site.

How Does Responsive Design Work?

Responsive Design is achieved using the following techniques:

1. Flexible Layouts

  • Websites use percentage-based widths instead of fixed pixel values so that elements adjust dynamically.

2. Media Queries (CSS)

  • CSS Media Queries adapt the layout based on screen size. Example:
@media (max-width: 768px) {
    body {
        background-color: lightgray;
    }
}
  • → This changes the background color for screens smaller than 768px.

  • 3. Flexible Images and Media

    • Images and videos automatically resize with:
img {
    max-width: 100%;
    height: auto;
}

4. Mobile-First Approach

  • The design starts with small screens first and then scales up for larger displays.

Benefits of Responsive Design

Better user experience across all devices
SEO advantages, as Google prioritizes mobile-friendly sites
No need for separate mobile and desktop versions, reducing maintenance
Higher conversion rates, since users can navigate the site easily

Conclusion

Responsive Design is now the standard in modern web development, ensuring optimal display and usability on all devices.

 

Random Tech

Leaner Style Sheets - LESS


800px-LESS_Logo.svg.png