CSS中属性排序
来源:互联网 发布:智阳网络有年终奖吗 编辑:程序博客网 时间:2024/05/29 16:56
From: http://markdotto.com/2011/11/29/css-property-order/
CSS property order
November 29, 2011CSS property order matters, especially on larger teams with several engineers and designers all contributing code. I know it’s been discussed, but frankly there’s always room for improvement and alternate approaches. In a few projects at Twitter, we added the constraint of consistent CSS property order to make onboarding new folks easier, debugging faster, and expectations of what exactly a block of CSS does that much clearer (without viewing it in the browser).
High level overview
At a high level, here’s our breakdown:
position
display
and box modelfont
, leading,color
, textbackground
andborder
- CSS3 properties like
border-radius
andbox-shadow
- and a handful of other purely visual properties
We hadn’t really seen an approach like this in any other projects we’ve worked on. It mixes the common structural and alphabetical approaches into one in an effort to ensure our property order is logical, scannable, and all-encompassing. We wanted an order that mapped to how we mentally visualized DOM elements and—to an extent—how Webkit’s Inspector presents properties.
Show me!
Getting more specific, here are some blocks of CSS might look with this property order in mind.
Here you can see positioning, box model (height
and padding
), and visual (background-color
, border-bottom
and box-shadow
) in their proper order. This flows in such a way that you can discern that this is a fixed dark gray bar with a drop shadow–you know exactly what it is you’re dealing with as you read line-by-line.
In this example, we have only box model and visual. Notice that for box model, we have dimensions first with min-height
and padding
(as that adds to the overall width of an element). For the visual elements,background-color
and border
come first because those inform you how this element starts to look (e.g., a gray box witha border). border-radius
and box-shadow
follow that because those are additional visual treatments that add to the base look and feel.
Use what works for your team
This approach seems to work well for us and our teams without adding too much overhead. All you need to do is create a series of rules and stick to them with your team and this because a very successful tactic for organizing and maintaining CSS. No one solution is teh best, so keep that in mind and adjust as you go.
- CSS中属性排序
- CSS中Display属性
- CSS中behavior属性
- css中clip属性
- CSS中float属性
- css中auto属性
- CSS中float 属性
- CSS中float属性
- css中clip属性
- css中display属性
- CSS中position属性
- CSS中overflow属性
- css中position属性
- css中属性积累
- CSS中属性选择器
- css中display属性
- Css中属性继承
- css中float属性
- Java之Socket与HTTP区别
- 欢迎使用CSDN-markdown编辑器
- IOS基本类方法与实例方法之日期总结
- qemu网络配置
- 【C#基础】重载和重写(覆盖)
- CSS中属性排序
- Spring 源码分析(一) —— 迈向Spring之路
- Oracle断开正在连接的用户
- 使用Jmeter针对ActiveMQ JMS POINT TO POINT压力测试
- 2016年春节前最后一天工作
- 使用jetty热部署运行maven+j2ee项目
- 108. Convert Sorted Array to Binary Search Tree
- LA2757
- PICT测试工具的安装及使用