Reputation: 10146
Ok so this may be a very simple/obvious question, so I apologize if its a dumb question but didnt know where else to ask. But when using CSS and media queries for a responsive layout, should I re-use CSS code inside the media queries? For example:
h1 {
font-size:14px;
margin:0;
padding:0;
}
@media (min-width:768px) {
h1 {
font-size:12px;
margin:0;
padding:0;
}
}
Or is this the proper method?
h1 {
font-size:14px;
margin:0;
padding:0;
}
@media (min-width:768px) {
h1 {
font-size:12px;
}
}
And with grouping css properties with regards to breakpoints. Should I group all CSS properties for each breakpoint? Or just do it as needed? For example:
First method
h1 {
font-size:14px;
margin:0;
padding:0;
}
h2 {
font-size:12px;
margin:0;
padding:0;
}
@media (min-width:768px) {
h1 {
font-size:12px;
margin:0;
padding:0;
}
h1 {
font-size:10px;
margin:0;
padding:0;
}
}
//Other CSS properties for this page/site
#page-footer .footer-bot {
background-color:#24262b;
font-family:'PT Sans',sans-serif;
font-weight:400;
text-transform:uppercase;
font-size:10px;
color:#adadad;
letter-spacing:.3px;
line-height:18px;
padding-top:5px;
padding-bottom:5px;
}
@media (min-width:768px) {
#page-footer .footer-bot {
line-height:25px;
padding-top:0;
padding-bottom:0;
}
}
Or in the second method, wait till the end of the CSS script and do all the breakpoint changes at the very end in one group for each breakpoint I want to use?
h1 {
font-size:14px;
margin:0;
padding:0;
}
h2 {
font-size:12px;
margin:0;
padding:0;
}
#page-footer .footer-bot {
background-color:#24262b;
font-family:'PT Sans',sans-serif;
font-weight:400;
text-transform:uppercase;
font-size:10px;
color:#adadad;
letter-spacing:.3px;
line-height:18px;
padding-top:5px;
padding-bottom:5px;
}
//Other CSS properties for this page/site
@media (min-width:768px) {
h1 {
font-size:12px;
margin:0;
padding:0;
}
h1 {
font-size:10px;
margin:0;
padding:0;
}
#page-footer .footer-bot {
line-height:25px;
padding-top:0;
padding-bottom:0;
}
}
Upvotes: 0
Views: 59
Reputation: 1876
This is the right method to use media query breakpoints.
h1 {
font-size:14px;
margin:0;
padding:0;
}
@media (min-width:768px) {
h1 {
font-size:12px;
}
}
Only add that code which you want to make changes in breakpoints. No need to repeat same code in media query.
About grouping CSS you can use both the method. If you have used First method your code will be so long. So, my suggestion is you should go for second method
Upvotes: 1