What is the mobile first approach in CSS?
In the mobile first approach you write the base CSS for phones, and then use min-width media queries to add changes for bigger screens.
.cards { display: grid; grid-template-columns: 1fr; } /* phone */
@media (min-width: 768px) {
.cards { grid-template-columns: repeat(2, 1fr); } /* tablet */
}
@media (min-width: 1100px) {
.cards { grid-template-columns: repeat(3, 1fr); } /* desktop */
}
Phones load simpler CSS, and the code stays easier to manage. See CSS Media Queries.
Learn more about the similar topics:
| Tutorials |
|---|
| CSS Media Queries |
| Exercises & Assignments |
|---|
| Write CSS to make an image responsive and round |
| Interview Questions & Answers |
|---|
| What are media queries in CSS? |
| What is the mobile first approach in CSS? |