You can use media queries, flexbox, grid layout, and fluid units to make a responsive layout using CSS.
Here are the steps in brief:
Fluid Layouts (percentages or vw/vh units):
Use relative units instead of fixed widths like px. Relative units are percentages, em, or viewport-based units like vw, vh to make elements resize according to the screen size.
Media Queries:
By using media queries, you can define different CSS styles for different screen sizes.
Example:
@media (max-width: 586px) { /* Styles for devices with screen width 586px or less */
.container { flex-direction: column; }}
Flexbox Layout:
Flexbox is ideal for responsive design as it enables dynamic space distribution across elements.
Example:
.container { display: flex; flex-wrap: wrap;}.item { flex: 2 2 200px;}
Grid Layout:
CSS Grid is a powerful two-dimensional layout system that helps you create complex layouts with ease.
Example:
.container { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 2fr));}