-
Notifications
You must be signed in to change notification settings - Fork 125
A starting point for CSS code standards #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,220 @@ | ||
| ## CSS | ||
| These guidelines have been assembled following an examination of emerging practices, ideas and existing styleguides, namely: | ||
|
|
||
| @TODO - Add style guide | ||
| 1. [OOCSS Code Standards](https://github.com/stubbornella/oocss-code-standards) | ||
| 2. [Oneweb Style Guide](https://github.com/nternetinspired/OneWeb/blob/master/STYLEGUIDE.md) | ||
| 3. [Idiomatic CSS](https://github.com/necolas/idiomatic-css) | ||
|
|
||
|
|
||
| ## Commenting | ||
|
|
||
| ### Major sections | ||
| Major code sections should be named in caps and within a full comment block, eg: | ||
| ```css | ||
| /* ========================================================================== | ||
| PRIMARY NAVIGATION | ||
| ========================================================================== */ | ||
| ``` | ||
|
|
||
| ### Sub sections | ||
| Subsections should be normally cased and within an open comment block. | ||
| ```css | ||
| /* Mobile navigation | ||
| ========================================================================== */ | ||
| ``` | ||
|
|
||
| ### Verbose comments | ||
| ```css | ||
| /** | ||
| * Short description using Doxygen-style comment format | ||
| * | ||
| * The first sentence of the long description starts here and continues on this | ||
| * line for a while finally concluding here at the end of this paragraph. | ||
| * | ||
| * The long description is ideal for more detailed explanations and | ||
| * documentation. It can include example HTML, URLs, or any other information | ||
| * that is deemed necessary or useful. | ||
| * | ||
| * @tag This is a tag named 'tag' | ||
| * | ||
| * TODO: This is a todo statement that describes an atomic task to be completed | ||
| * at a later date. It wraps after 80 characters and following lines are | ||
| * indented by 2 spaces. | ||
| */ | ||
| ``` | ||
|
|
||
| ### Basic comments | ||
| ```css | ||
| /* Basic comment */ | ||
| ``` | ||
|
|
||
| ### Uncompiled LESS/Scss comments | ||
| ```css | ||
| // These are stripped on compile. | ||
| ``` | ||
|
|
||
| ## Class naming | ||
| Use dashes to create compound class names: | ||
|
|
||
| ```css | ||
| /* Good - use dashes */ | ||
| .compound-class-name {…} | ||
|
|
||
| /* Bad - uses underscores */ | ||
| .compound_class_name {…} | ||
|
|
||
| /* Bad - uses camelCase */ | ||
| .compoundClassName {…} | ||
|
|
||
| /* Bad - does not use seperators */ | ||
| .compoundclassname {…} | ||
| ``` | ||
|
|
||
| ### Indentation | ||
| Rules should be indented one tab (equal to 4 spaces): | ||
|
|
||
| ```css | ||
| /* Good */ | ||
| .example { | ||
| color: #000; | ||
| visibility: hidden; | ||
| } | ||
|
|
||
| /* Bad - all on one line */ | ||
| .example {color: #000; visibility: hidden;} | ||
| ``` | ||
|
|
||
| LESS/Scss should also be nested , with child selectors and rules indented again. Nested rules should also be spaced by one line: | ||
|
|
||
| ```css | ||
| /* Good */ | ||
| .example { | ||
|
|
||
| > li { | ||
| float: none; | ||
|
|
||
| + li { | ||
| margin-top: 2px; | ||
| margin-left: 0; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } | ||
| /* Bad - nested rules not indented */ | ||
| .example { | ||
|
|
||
| > li { | ||
| float: none; | ||
|
|
||
| + li { | ||
| margin-top: 2px; | ||
| margin-left: 0; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } | ||
| /* Bad - nested rules not spaced */ | ||
| .example { | ||
| > li { | ||
| float: none; | ||
| + li { | ||
| margin-top: 2px; | ||
| margin-left: 0; | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### Alignment | ||
| 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. | ||
|
|
||
| ```css | ||
| /* Good */ | ||
| .example { | ||
| color: #fff; | ||
| } | ||
|
|
||
| /* Bad - closing brace is in the wrong place */ | ||
| .example { | ||
| color: #fff; | ||
| } | ||
|
|
||
| /* Bad - opening brace missing space */ | ||
| .example{ | ||
| color: #fff; | ||
| } | ||
| ``` | ||
|
|
||
| ### Property Format | ||
| 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. | ||
|
|
||
| ```css | ||
| /* Good */ | ||
| .example { | ||
| background: black; | ||
| color: #fff; | ||
| } | ||
|
|
||
| /* Bad - missing spaces after colons */ | ||
| .example { | ||
| background:black; | ||
| color:#fff; | ||
| } | ||
|
|
||
| /* Bad - missing last semicolon */ | ||
| .example { | ||
| background: black; | ||
| color: #fff | ||
| } | ||
| ``` | ||
|
|
||
| ### HEX values | ||
| HEX values must be declared in lowercase and shorthand: | ||
| ```css | ||
| /* Good */ | ||
| .example { | ||
| color: #eee; | ||
| } | ||
|
|
||
| /* Bad */ | ||
| .example { | ||
| color: #EEEEEE; | ||
| } | ||
| ``` | ||
|
|
||
| ### Attribute selectors | ||
| Always use double quotes around attribute selectors. | ||
|
|
||
| ```css | ||
| /* Good */ | ||
| input[type="button"] { | ||
| ... | ||
| } | ||
|
|
||
| /* Bad - missing quotes */ | ||
| input[type=button] { | ||
| ... | ||
| } | ||
|
|
||
| /* Bad - using single quote */ | ||
| input[type='button'] { | ||
| ... | ||
| } | ||
| ``` | ||
|
|
||
| ### Zero value units | ||
| Zero values should not carry units. | ||
|
|
||
| ```css | ||
| /* Good */ | ||
| .example { | ||
| padding: 0; | ||
| } | ||
|
|
||
| /* Bad - uses units */ | ||
| .example { | ||
| padding: 0px; | ||
| } | ||
| ``` | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be indented to match the expectation stated above.