-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcss.html
executable file
·590 lines (513 loc) · 17.4 KB
/
css.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Grappus Style Guide</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link
rel="stylesheet"
href="bower_components/normalize.css/normalize.css"
/>
<link
rel="stylesheet"
href="bower_components/font-awesome/css/font-awesome.min.css"
/>
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Roboto:300|Roboto+Condensed:400,700|Inconsolata"
/>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<nav>
<ul>
<li><a href="index.html">HTML</a></li>
<li><a href="css.html" class="active">CSS</a></li>
<li><a href="javascript.html">JavaScript</a></li>
<!-- <li><a href="react.html">React</a></li>
<li><a href="vue.html">Vue Js</a></li> -->
<li><a href="git.html">Git</a></li>
</ul>
</nav>
<h1>Grappus Frontend Style Guide</h1>
<section>
<h2>Introduction</h2>
<p>
This style guide acts as the official guide to follow in your projects.
Grappus evaluators will use this guide to grade your projects. There are
many opinions on the "ideal" style in the world of Front-End Web
Development. Therefore, in order to reduce the confusion on what style
developer should follow during development of their projects, we urge
all developers to refer to this style guide for their projects.
</p>
</section>
<section>
<h2>General Formatting Rules</h2>
<article>
<h3>
<a href="#capitalization" id="capitalization"
><i class="fa fa-link"></i
></a>
Capitalization
</h3>
<p>Use only lowercase.</p>
<p>
All code has to be lowercase. This applies to CSS selectors,
properties and property values (with the exception of strings).
</p>
<h4 class="not-recommended">Not Recommended:</h4>
<pre><code class="not-recommended">color: #E5E5E5;</code></pre>
<h4 class="recommended">Recommended:</h4>
<pre><code class="recommended">color: #e5e5e5;</code></pre>
</article>
<article>
<h3>
<a href="#whitespace" id="whitespace"><i class="fa fa-link"></i></a>
Trailing Whitespace
</h3>
<p>Remove trailing white spaces.</p>
<p>Trailing white spaces are unnecessary and can complicate diffs.</p>
<h4 class="not-recommended">Not Recommended:</h4>
<pre><code class="not-recommended">border: 0;__</code></pre>
<h4 class="recommended">Recommended:</h4>
<pre><code class="recommended">border: 0;</code></pre>
<p>
If using Sublime Text, this can be done automatically each time you
save a file by adding the following to your User Settings JSON file
(you should be able to find this within Sublime Text's menu):
</p>
<pre><code>"trim_trailing_white_space_on_save": true</code></pre>
</article>
<article>
<h3>
<a href="#indentation" id="indentation"><i class="fa fa-link"></i></a>
Indentation
</h3>
<p>
Indentation should be consistent throughout the entire file. Whether
you choose to use tabs or spaces, or 2-spaces vs. 4-spaces - just be
consistent!
</p>
</article>
</section>
<section>
<h2>General Meta Rules</h2>
<article>
<h3>
<a href="#encoding" id="encoding"><i class="fa fa-link"></i></a>
Encoding
</h3>
<p>Use UTF-8 (no BOM).</p>
<p>
Make sure your editor uses UTF-8 as character encoding, without a byte
order mark. Do not specify the encoding of style sheets as these
assume UTF-8.
</p>
</article>
<article>
<h3>
<a href="#comments" id="comments"><i class="fa fa-link"></i></a>
Comments
</h3>
<p>Explain code as needed, where possible.</p>
<p>
Use comments to explain code: What does it cover, what purpose does it
serve, and why is the respective solution used or preferred?
</p>
</article>
<article>
<h3>
<a href="#action-items" id="action-items"
><i class="fa fa-link"></i
></a>
Action Items
</h3>
<p>Mark todos and action items with <code>TODO:</code>.</p>
<p>
Highlight todos by using the keyword <code>TODO</code> only, not other
formats like <code>@@</code>. Append action items after a colon like
this: <code>TODO: action item</code>.
</p>
<h4 class="recommended">Recommended:</h4>
<pre><code class="recommended">/* TODO: add button elements */</code></pre>
</article>
</section>
<section>
<h2>CSS Style Rules</h2>
<article>
<h3>
<a href="#validity" id="validity"><i class="fa fa-link"></i></a>
CSS Validity
</h3>
<p>Use valid CSS.</p>
<p>
Using valid CSS is a measurable baseline quality that ensures proper
CSS usage and allows you to spot CSS code that may not have any effect
and can be removed.
</p>
</article>
<article>
<h3>
<a href="#naming" id="naming"><i class="fa fa-link"></i></a>
ID and Class Naming
</h3>
<p>Use meaningful or generic ID and class names.</p>
<p>
Instead of presentational of cryptic names, always use ID and class
names that reflect the purpose of the element in question or that are
otherwise generic.
</p>
<p>
Names that are specific and reflect the purpose of the element should
be preferred as these are most understandable and the least likely to
change.
</p>
<p>
Generic names are simply a fallback for elements that have no
particular meaning different from their siblings. They are typically
needed as helpers.
</p>
<h4 class="not-recommended">Not Recommended:</h4>
<pre><code class="not-recommended">.p-998 { … }
.btn-green { … }</code></pre>
<h4 class="recommended">Recommended:</h4>
<pre><code class="recommended">.gallery { … }
.btn-default { … }</code></pre>
</article>
<article>
<h3>
<a href="#type-selectors" id="type-selectors"
><i class="fa fa-link"></i
></a>
Type Selectors
</h3>
<p>Avoid qualifying ID and class names with type selectors.</p>
<p>
Unless necessary (for example, with helper classes), do not use
element names in conjunction with IDs or classes. Avoiding unnecessary
ancestor selectors is useful for performance reasons.
</p>
<p>
It is also considered bad practice to use IDs in your CSS files. There
are no situations where IDs provide a benefit over classes. If you
need to use a unique name for an element, use a class. (The only
benefit IDs provide is speed, and is only beneficial on pages with
thousands of similar elements.)
</p>
<h4 class="not-recommended">Not Recommended:</h4>
<pre><code class="not-recommended">ul#example { … }
div.error { … }</code></pre>
<h4 class="recommended">Recommended:</h4>
<pre><code class="recommended">.example { … }
.error { … }</code></pre>
</article>
<article>
<h3>
<a href="#shorthand" id="shorthand"><i class="fa fa-link"></i></a>
Shorthand Properties
</h3>
<p>Shorthand should be used.</p>
<p>
CSS offers a variety of shorthand properties (like
<code>padding</code> rather than explicitly setting
<code>padding-top</code>, <code>padding-bottom</code>, etc.) that
should be used whenever possible, with the exception of font
properties and properties intended to override properties of the same
name in a framework such as Bootstrap.
</p>
<p>
Using shorthand properties is useful for code efficiency and
understandability. The <code>font</code> shorthand property is
recommended when setting all font related properties but is not
required when making minor modifications. When using the font
shorthand property, keep in mind that if font size and family are not
included browsers will ignore entire font statement.
</p>
<h4 class="not-recommended">Not Recommended:</h4>
<pre><code class="not-recommended">border-top-style: none;
font-family: palatino, georgia, serif;
font-size: 100%;
line-height: 1.6;
padding-bottom: 2em;
padding-left: 1em;
padding-right: 1em;
padding-top: 0;</code></pre>
<h4 class="recommended">Recommended:</h4>
<pre><code class="recommended">border-top: 0;
font: 100%/1.6 palatino, georgia, serif;
padding: 0 1em 2em;</code></pre>
</article>
<article>
<h3>
<a href="#units" id="units"><i class="fa fa-link"></i></a>
0 and Units
</h3>
<p>Omit unit specification after <code>0</code> values.</p>
<h4 class="not-recommended">Not Recommended:</h4>
<pre><code class="not-recommended">margin: 0em;
padding: 0px;</code></pre>
<h4 class="recommended">Recommended:</h4>
<pre><code class="recommended">margin: 0;
padding: 0;</code></pre>
</article>
<article>
<h3>
<a href="#leading-zeroes" id="leading-zeroes"
><i class="fa fa-link"></i
></a>
Leading 0s
</h3>
<p>
Include leading <code>0</code>s in decimal values for readability.
</p>
<h4 class="not-recommended">Not Recommended:</h4>
<pre><code class="not-recommended">font-size: .8em;</code></pre>
<h4 class="recommended">Recommended:</h4>
<pre><code class="recommended">font-size: 0.8em;</code></pre>
</article>
<article>
<h3>
<a href="#hex" id="hex"><i class="fa fa-link"></i></a>
Hexadecimal Notation
</h3>
<p>Use 3-character hexadecimal notation where possible.</p>
<h4 class="not-recommended">Not Recommended:</h4>
<pre><code class="not-recommended">color: #eebbcc;</code></pre>
<h4 class="recommended">Recommended:</h4>
<pre><code class="recommended">color: #ebc;</code></pre>
</article>
<article>
<h3>
<a href="#delimiters" id="delimiters"><i class="fa fa-link"></i></a>
ID and Class Name Delimiters
</h3>
<p>
Separate words in ID and class names by a hyphen (<code>-</code>).
</p>
<p>
Use hyphens to concatenate words and abbreviations in selectors in
order to improve understanding and scannability.
</p>
<p>
One exception: underscores (<code>_</code>) are also acceptable
separators when writing
<a href="http://getbem.com/" target="_blank"
>BEM style CSS selectors</a
>.
</p>
<h4 class="not-recommended">Not Recommended:</h4>
<pre><code class="not-recommended">.demoimage { … }
.errorStatus { … }</code></pre>
<h4 class="recommended">Recommended:</h4>
<pre><code class="recommended">.demo-image { … }
.error-status { … }</code></pre>
</article>
<article>
<h3>
<a href="#hacks" id="hacks"><i class="fa fa-link"></i></a>
Hacks
</h3>
<p>
Avoid user agent detection as well as CSS "hacks"—try a different
approach first.
</p>
<p>
It's tempting to address styling difference over user agent detection
or special CSS filters, workaround and hacks. Both approaches should
be considered an absolute last resort in order to achieve and maintain
an efficient and manageable code base. Consider if the intended style
is absolutely critical to the functionality of your application or can
the "offending" user agent "live without it".
</p>
</article>
</section>
<section>
<h2>CSS Formatting Rules</h2>
<article>
<h3>
<a href="#block-content" id="block-content"
><i class="fa fa-link"></i
></a>
Block Content Indentation
</h3>
<p>
Indent all block content, that is rules within rules as well as
declarations to reflect hierarchy and improve understanding.
</p>
<h4 class="recommended">Recommended:</h4>
<pre><code class="recommended">@media screen, projection {
html {
background: #fff;
color: #444;
}
}</code></pre>
</article>
<article>
<h3>
<a href="#declaration-stops" id="declaration-stops"
><i class="fa fa-link"></i
></a>
Declaration Stops
</h3>
<p>
Use a semicolon after every declaration for consistency and
extensibility reasons.
</p>
<h4 class="not-recommended">Not Recommended:</h4>
<pre><code class="not-recommended">.test {
display: block;
height: 100px
}</code></pre>
<h4 class="recommended">Recommended:</h4>
<pre><code class="recommended">.test {
display: block;
height: 100px;
}</code></pre>
</article>
<article>
<h3>
<a href="#prop-name-stops" id="prop-name-stops"
><i class="fa fa-link"></i
></a>
Property Name Stops
</h3>
<p>
Always use a space after a property name's colon, but no space between
property and colon, for consistency reasons.
</p>
<h4 class="not-recommended">Not Recommended:</h4>
<pre><code class="not-recommended">font-weight:bold;
padding : 0;
margin :0;</code></pre>
<h4 class="recommended">Recommended:</h4>
<pre><code class="recommended">font-weight: bold;
padding: 0;
margin: 0;</code></pre>
</article>
<article>
<h3>
<a href="#block-separation" id="block-separation"
><i class="fa fa-link"></i
></a>
Declaration Block Separation
</h3>
<p>
Always use a single space between the last selector and the opening
brace that begins the declaration block.
</p>
<h4 class="not-recommended">Not Recommended:</h4>
<pre><code class="not-recommended">.video-block{
margin: 0;
}
.audio-block
{
margin: 0;
}</code></pre>
<h4 class="recommended">Recommended:</h4>
<pre><code class="recommended">.video-block {
margin: 0;
}
.audio-block {
margin: 0;
}</code></pre>
</article>
<article>
<h3>
<a
href="#selector-declaration-separation"
id="selector-declaration-separation"
><i class="fa fa-link"></i
></a>
Selector and Declaration Separation
</h3>
<p>Always start a new line for each selector and declaration.</p>
<h4 class="not-recommended">Not Recommended:</h4>
<pre><code class="not-recommended">h1, h2, h3 {
font-weight: normal; line-height: 1.2;
}</code></pre>
<h4 class="recommended">Recommended:</h4>
<pre><code class="recommended">h1,
h2,
h3 {
font-weight: normal;
line-height: 1.2;
}</code></pre>
</article>
<article>
<h3>
<a href="#rule-separation" id="rule-separation"
><i class="fa fa-link"></i
></a>
Rule Separations
</h3>
<p>Always put a blank line (two line breaks) between rules.</p>
<h4 class="recommended">Recommended:</h4>
<pre><code class="recommended">html {
background: #fff;
}
body {
margin: auto;
width: 50%;
}</code></pre>
</article>
<article>
<h3>
<a href="#quotes" id="quotes"><i class="fa fa-link"></i></a>
CSS Quotation Marks
</h3>
<p>
Use double quotation marks for attribute selectors or property values.
Do not use quotation marks in URI values ( <code>url()</code>).
</p>
<h4 class="not-recommended">Not Recommended:</h4>
<pre><code class="not-recommended">@import url("css/links.css");
html {
font-family: 'Open Sans', arial, sans-serif;
}</code></pre>
<h4 class="recommended">Recommended:</h4>
<pre><code class="recommended">@import url(css/links.css);
html {
font-family: "Open Sans", arial, sans-serif;
}</code></pre>
</article>
</section>
<section>
<h2>CSS Meta Rules</h2>
<article>
<h3>
<a href="#section-comments" id="section-comments"
><i class="fa fa-link"></i
></a>
Section Comments
</h3>
<p>
If possible, group style sheet sections together by using comments.
Separate sections with new lines.
</p>
<h4 class="recommended">Recommended:</h4>
<pre><code class="recommended">/* Header */
.header {
…
}
.header-nav {
…
}
/* Content */
.gallery {
…
}
.gallery-img {
…
}
/* Footer */
.footer {
…
}
.footer-nav {
…
}
</code></pre>
</article>
</section>
</body>
</html>