To use media queries for different devices in CSS, you can follow these steps:
- Define the CSS rules for your default layout that will be applied to all devices.
- Identify the breakpoints where you want your layout to change for different devices. Common breakpoints are based on screen widths, such as 480px, 768px, 1024px, etc.
- Use media queries to apply specific CSS rules for different devices based on their screen size or other characteristics.
Here’s an example of how you can implement media queries in CSS:
/* Default CSS rules */ body { font-size: 16px; color: #333; } /* Media query for devices with a maximum width of 480px */ @media (max-width: 480px) { body { font-size: 14px; } } /* Media query for devices with a minimum width of 768px */ @media (min-width: 768px) { body { font-size: 18px; } } /* Media query for devices with a minimum width of 1024px */ @media (min-width: 1024px) { body { font-size: 20px; } }
In this example, the default font size is set to 16px for all devices. However, when the screen width is less than or equal to 480px, the font size is changed to 14px. For screen widths between 768px and 1023px, the font size is increased to 18px. And for screen widths equal to or greater than 1024px, the font size is further increased to 20px.
By using media queries, you can customize your CSS rules based on the characteristics of different devices, allowing your website or application to adapt and provide an optimal user experience across various screen sizes.