Category: html_css
css Responsive
Published on 29 Jun 2026
Explanation
Responsive design ensures a website looks good on desktops, tablets, and mobile devices by adapting its layout to different screen sizes.
Code:
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Explanation
Using relative units like %, rem, em, and vw allows elements to resize based on the screen size instead of fixed pixel values.
Code:
.container {
width: 90%;
max-width: 1200px;
}
Explanation
Flexible layouts using Flexbox automatically adjust the arrangement of elements for different screen sizes.
Code:
.container {
display: flex;
flex-wrap: wrap;
gap: 20px;
}
Explanation
Images should be responsive so they scale within their parent container without overflowing.
Code:
img {
max-width: 100%;
height: auto;
}
Explanation
Responsive design often combines flexible layouts, scalable images, and media queries to create user-friendly websites.
Code:
.card {
width: 100%;
padding: 20px;
}