I'm currently working on an header for some website. This header consists of two different designs:
Floating/horizontal header:
+-------------------------------------------------------------------------+
| +--------------+ +--------------------+ |
| | LOGO | | Menu | Menu | Menu | |
| +--------------+ +--------------------+ |
+-------------------------------------------------------------------------+
Centered header:
+-------------------------------------------------------------------------+
| +--------------------+ |
| | LOGO | |
| | Menu | Menu | Menu | |
| +--------------------+ |
+-------------------------------------------------------------------------+
The centered header should be used, when the browser width is smaller than some breakpoint value. Otherwise the horizontal header. This can be achieved via CSS media-queries
. My question is what the better code organisation would be for the header.css file:
- Only use code intersection of the two designs (
font-family
,container-width: 100%
, etc.) together with two media queries.
Pseudo code:
/* Code necessary for both designs */
@media-query (width < breakpoint) {
/* upgrade code to centered header */
}
@media-query (width >= breakpoint) {
/* upgrade code to floating header */
}
- Always use centered header +
media-query
to override necessary pieces:
Pseudo code:
/* Code necessary for centered designs */
@media-query (width >= breakpoint) {
/* Overwrite centered header code */
/* Insert floating header code */
}
My question is what are the pros/cons of these two css structures? How about code duplication. The first one always uses a media-query
to display anything useful. The second one needs to overwrite some of the first centered headers features.
I hope this doesn't get closed, because it's too subjective. I'm only asking for pros/cons, not what design to chose or which one is better...