Skip to content

Commit 95a2e9a

Browse files
authored
Update headers to markdown format
1 parent 53a0acd commit 95a2e9a

1 file changed

Lines changed: 25 additions & 12 deletions

File tree

  • wordpress-coding-standards

wordpress-coding-standards/css.md

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
Like any coding standard, the purpose of the WordPress CSS Coding Standards is to create a baseline for collaboration and review within various aspects of the WordPress open source project and community, from core code to themes to plugins. Files within a project should appear as though created by a single entity. Above all else, create code that is readable, meaningful, consistent, and beautiful.
44

55
Within core stylesheets, inconsistencies will often be found. We are working on addressing these and make every effort to have patches and commits from this point forward follow the CSS coding standards. More information on the above and contributing to UI/front-end development will be forthcoming in a separate set of guidelines.
6-
<h2>Structure</h2>
6+
7+
## Structure
8+
79
There are plenty of different methods for structuring a stylesheet. With the CSS in core, it is important to retain a high degree of legibility. This enables subsequent contributors to have a clear understanding of the flow of the document.
810
<ul>
911
<li>Use tabs, not spaces, to indent each property.</li>
@@ -32,7 +34,8 @@ Incorrect:
3234
#selector-1 { background: #fff; color: #000; }
3335
```
3436

35-
<h2>Selectors</h2>
37+
## Selectors
38+
3639
With specificity, comes great responsibility. Broad selectors allow us to be efficient, yet can have adverse consequences if not tested. Location-specific selectors can save us time, but will quickly lead to a cluttered stylesheet. Exercise your best judgement to create selectors that find the right balance between contributing to the overall style and layout of the DOM.
3740
<ul>
3841
<li>Similar to the <a href="https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/#naming-conventions">WordPress PHP Coding Standards</a> for file names, use lowercase and separate words with hyphens when naming selectors. Avoid camelcase and underscores.</li>
@@ -76,7 +79,8 @@ input[type=text] { /&042; Should be [type="text"] &042;/
7679
}
7780
```
7881

79-
<h2>Properties</h2>
82+
## Properties
83+
8084
Similar to selectors, properties that are too specific will hinder the flexibility of the design. Less is more. Make sure you are not repeating styling or introducing fixed dimensions (when a fluid solution is more acceptable).
8185
<ul>
8286
<li>Properties should be followed by a colon and a space.</li>
@@ -106,7 +110,8 @@ Incorrect:
106110
}
107111
```
108112

109-
<h3>Property Ordering</h3>
113+
### Property Ordering
114+
110115
<blockquote>"Group like properties together, especially if you have a lot of them."
111116
-- Nacin</blockquote>
112117
Above all else, choose something that is meaningful to you and semantic in some way. Random ordering is chaos, not poetry. In WordPress Core, our choice is logical or grouped ordering, wherein properties are grouped by meaning and ordered specifically within those groups. The properties within groups are also strategically ordered to create transitions between sections, such as background directly before color. The baseline for ordering is:
@@ -119,7 +124,7 @@ Above all else, choose something that is meaningful to you and semantic in some
119124
</ul>
120125
Things that are not yet used in core itself, such as CSS3 animations, may not have a prescribed place above but likely would fit into one of the above in a logical manner. Just as CSS is evolving, so our standards will evolve with it.
121126

122-
Top/Right/Bottom/Left (TRBL/trouble) should be the order for any relevant properties (e.g. `margin`), much as the order goes in values. Corner specifiers (e.g. `border-radius-*-*`) should be `top-left`, `top-right`, `bottom-right`, `bottom-left`. This is derived from how shorthand values would be ordered.
127+
Top/Right/Bottom/Left (TRBL/trouble) should be the order for any relevant properties (e.g. margin), much as the order goes in values. Corner specifiers (e.g. border-radius-*-*) should be top-left, top-right, bottom-right, bottom-left. This is derived from how shorthand values would be ordered.
123128

124129
Example:
125130

@@ -147,7 +152,8 @@ Example:
147152
}
148153
```
149154

150-
<h3>Vendor Prefixes</h3>
155+
### Vendor Prefixes
156+
151157
Updated on 2/13/2014, after <a href="https://core.trac.wordpress.org/changeset/27174">[27174]</a>:
152158

153159
We use <a href="https://github.com/postcss/autoprefixer">Autoprefixer</a> as a pre-commit tool to easily manage necessary browser prefixes, thus making the majority of this section moot. For those interested in following that output without using Grunt, vendor prefixes should go longest (-webkit-) to shortest (unprefixed). All other spacing remains as per the rest of standards.
@@ -160,7 +166,8 @@ We use <a href="https://github.com/postcss/autoprefixer">Autoprefixer</a> as a p
160166
}
161167
```
162168

163-
<h2>Values</h2>
169+
## Values
170+
164171
There are numerous ways to input values for properties. Follow the guidelines below to help us retain a high degree of consistency.
165172
<ul>
166173
<li>Space before the value, after the colon.</li>
@@ -226,7 +233,8 @@ Incorrect:
226233
}
227234
```
228235

229-
<h2>Media Queries</h2>
236+
## Media Queries
237+
230238
Media queries allow us to gracefully degrade the DOM for different screen sizes. If you are adding any, be sure to test above and below the break-point you are targeting.
231239
<ul>
232240
<li>It is generally advisable to keep media queries grouped by media at the bottom of the stylesheet.
@@ -244,7 +252,8 @@ Example:
244252
}
245253
```
246254

247-
<h2>Commenting</h2>
255+
## Commenting
256+
248257
<ul>
249258
<li>Comment, and comment liberally. If there are concerns about file size, utilize minified files and the SCRIPT_DEBUG constant. Long comments should manually break the line length at 80 characters.</li>
250259
<li>A table of contents should be utilized for longer stylesheets, especially those that are highly sectioned. Using an index number (1.0, 1.1, 2.0, etc.) aids in searching and jumping to a location.</li>
@@ -274,7 +283,8 @@ For inline:
274283
}
275284
```
276285

277-
<h2>Best Practices</h2>
286+
## Best Practices
287+
278288
Stylesheets tend to grow in length and complexity, and as they grow the chance of redundancy increases. By following some best practices we can help our CSS maintain focus and flexibility as it evolves:
279289
<ul>
280290
<li>If you are attempting to fix an issue, attempt to remove code before adding more.</li>
@@ -284,9 +294,12 @@ Stylesheets tend to grow in length and complexity, and as they grow the chance o
284294
<li>Do not restate default property &amp; value combinations (for instance <code>display: block;</code> on block-level elements).</li>
285295
</ul>
286296

287-
<h3>WP Admin CSS</h3>
297+
### WP Admin CSS
298+
288299
Check out the <a href="https://wordpress.github.io/css-audit/public/wp-admin">WP Admin CSS Audit</a>, a report generated to document the health of the WP Admin CSS code. Read more in <a href="https://github.com/WordPress/css-audit/blob/trunk/README.md">the repository's README</a>.
289-
<h2>Related Links</h2>
300+
301+
## Related Links
302+
290303
<ul>
291304
<li>Principles of writing consistent, idiomatic CSS: <a href="https://github.com/necolas/idiomatic-css">https://github.com/necolas/idiomatic-css</a></li>
292305
</ul>

0 commit comments

Comments
 (0)