零维
每个人都开始将CSS与包含所有样式的单个文件一起使用。
style.css
一维
很快,它变得笨重,决定将CSS按页面元素分组在多个文件中:
html_elements.css
header.css
main-area.css
footer.css
有些人可能觉得这不够方便,并按功能对样式进行分组:
typography.css
layout.css
sticky-footer.css
(包含许多元素的声明,而不仅仅是页脚)
2D
When a project has a lot of CSS, it might require using both groupings simultaneously. CSS files structure becomes two-dimensional:
layout/
grid-system.css
header.css
sidebars.css
look/
typography/
main.css
headers.css
lists.css
backgrounds/
html_elements.css
header.css
main-area.css
footer.css
Okay, the example is fabricated, but you sure do understand what i mean.
Up to this point everything is fine.
Enter Media Query
This is where my CSS structure gets funked up.
In addition to the 2D structure described above, i have to structure my code by media queries:
- Some of my styles are universal (applied everywhere)
- Some are applied to certain screen size only:
- small;
- medium;
- large;
- extra large.
- Some are applied to certain groups of screen sizes:
- everything except small (non-mobile styles);
- small and medium (where sidebars aren't at the sides)
- large and xlarge (where you do have sidebars)
I tried to overcome the issue by scattering media queried styles among existing CSS files. The breakpoint Compass extension helps a lot, but the stylesheets become too messy. Finding a certain style when it's not portrayed in the files structures a lot of pain.
I tried grouping by media queries, then by elements and function. But files structure is two dimensional, so you can't add a new dimension, you can only add another level of hierarchy. So, it's not graceful. Also, it's very bulky.
So i end up with a 2D structure with media queries on one axis and an ugly mix of elements and functions on the other axis.
I'm absolutely not satisfied with that but i just fail to come up with a graceful solution. Please suggest one.
我最终要做的是您的2D解决方案(尽管我的解决方案还有更多的嵌套功能),并在需要时使用Breakpoint在线编写媒体查询。我们需要处理的事情之一是我们的输出CSS看起来不会和我们的手写代码相同,这是使用CSS预处理器并专门抽象处理周围事物的现实。很快,Google Chrome浏览器的开发工具将附带内置的Sass部分支持,并且 Firefox的FireSass可以帮助您确定样式的来源。
希望这些帮助!