Skip to content

Commit 7d567dc

Browse files
committed
Merge pull request joomla#57 from nternetinspired/gh-pages
A starting point for CSS code standards
2 parents 5a704c2 + 051ce67 commit 7d567dc

File tree

1 file changed

+218
-1
lines changed
  • manual/en-US/coding-standards/chapters

1 file changed

+218
-1
lines changed
Lines changed: 218 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,220 @@
11
## CSS
2+
These guidelines have been assembled following an examination of emerging practices, ideas and existing styleguides, namely:
23

3-
@TODO - Add style guide
4+
1. [OOCSS Code Standards](https://github.com/stubbornella/oocss-code-standards)
5+
2. [Oneweb Style Guide](https://github.com/nternetinspired/OneWeb/blob/master/STYLEGUIDE.md)
6+
3. [Idiomatic CSS](https://github.com/necolas/idiomatic-css)
7+
8+
9+
## Commenting
10+
11+
### Major sections
12+
Major code sections should be named in caps and within a full comment block, eg:
13+
```css
14+
/* ==========================================================================
15+
PRIMARY NAVIGATION
16+
========================================================================== */
17+
```
18+
19+
### Sub sections
20+
Subsections should be normally cased and within an open comment block.
21+
```css
22+
/* Mobile navigation
23+
========================================================================== */
24+
```
25+
26+
### Verbose comments
27+
```css
28+
/**
29+
* Short description using Doxygen-style comment format
30+
*
31+
* The first sentence of the long description starts here and continues on this
32+
* line for a while finally concluding here at the end of this paragraph.
33+
*
34+
* The long description is ideal for more detailed explanations and
35+
* documentation. It can include example HTML, URLs, or any other information
36+
* that is deemed necessary or useful.
37+
*
38+
* @tag This is a tag named 'tag'
39+
*
40+
* TODO: This is a todo statement that describes an atomic task to be completed
41+
* at a later date. It wraps after 80 characters and following lines are
42+
* indented by 2 spaces.
43+
*/
44+
```
45+
46+
### Basic comments
47+
```css
48+
/* Basic comment */
49+
```
50+
51+
### Uncompiled LESS/Scss comments
52+
```css
53+
// These are stripped on compile.
54+
```
55+
56+
## Class naming
57+
Use dashes to create compound class names:
58+
59+
```css
60+
/* Good - use dashes */
61+
.compound-class-name {…}
62+
63+
/* Bad - uses underscores */
64+
.compound_class_name {…}
65+
66+
/* Bad - uses camelCase */
67+
.compoundClassName {…}
68+
69+
/* Bad - does not use seperators */
70+
.compoundclassname {…}
71+
```
72+
73+
### Indentation
74+
Rules should be indented one tab (equal to 4 spaces):
75+
76+
```css
77+
/* Good */
78+
.example {
79+
color: #000;
80+
visibility: hidden;
81+
}
82+
83+
/* Bad - all on one line */
84+
.example {color: #000; visibility: hidden;}
85+
```
86+
87+
LESS/Scss should also be nested , with child selectors and rules indented again. Nested rules should also be spaced by one line:
88+
89+
```css
90+
/* Good */
91+
.example {
92+
93+
> li {
94+
float: none;
95+
96+
+ li {
97+
margin-top: 2px;
98+
margin-left: 0;
99+
}
100+
101+
}
102+
103+
}
104+
/* Bad - nested rules not indented */
105+
.example {
106+
107+
> li {
108+
float: none;
109+
110+
+ li {
111+
margin-top: 2px;
112+
margin-left: 0;
113+
}
114+
115+
}
116+
117+
}
118+
/* Bad - nested rules not spaced */
119+
.example {
120+
> li {
121+
float: none;
122+
+ li {
123+
margin-top: 2px;
124+
margin-left: 0;
125+
}
126+
}
127+
}
128+
```
129+
130+
### Alignment
131+
The opening brace must be on the same line as the last selector and preceded by a space. The closing brace must be on its own line after the last property and be indented to the same level as the opening brace.
132+
133+
```css
134+
/* Good */
135+
.example {
136+
color: #fff;
137+
}
138+
139+
/* Bad - closing brace is in the wrong place */
140+
.example {
141+
color: #fff;
142+
}
143+
144+
/* Bad - opening brace missing space */
145+
.example{
146+
color: #fff;
147+
}
148+
```
149+
150+
### Property Format
151+
Each property must be on its own line and indented one level. There should be no space before the colon and one space after. All properties must end with a semicolon.
152+
153+
```css
154+
/* Good */
155+
.example {
156+
background: black;
157+
color: #fff;
158+
}
159+
160+
/* Bad - missing spaces after colons */
161+
.example {
162+
background:black;
163+
color:#fff;
164+
}
165+
166+
/* Bad - missing last semicolon */
167+
.example {
168+
background: black;
169+
color: #fff
170+
}
171+
```
172+
173+
### HEX values
174+
HEX values must be declared in lowercase and shorthand:
175+
```css
176+
/* Good */
177+
.example {
178+
color: #eee;
179+
}
180+
181+
/* Bad */
182+
.example {
183+
color: #EEEEEE;
184+
}
185+
```
186+
187+
### Attribute selectors
188+
Always use double quotes around attribute selectors.
189+
190+
```css
191+
/* Good */
192+
input[type="button"] {
193+
...
194+
}
195+
196+
/* Bad - missing quotes */
197+
input[type=button] {
198+
...
199+
}
200+
201+
/* Bad - using single quote */
202+
input[type='button'] {
203+
...
204+
}
205+
```
206+
207+
### Zero value units
208+
Zero values should not carry units.
209+
210+
```css
211+
/* Good */
212+
.example {
213+
padding: 0;
214+
}
215+
216+
/* Bad - uses units */
217+
.example {
218+
padding: 0px;
219+
}
220+
```

0 commit comments

Comments
 (0)