Share 12 awesome CSS skills
Mar 21, 2017 pm 05:36 PMThe following CSS advanced skills
Use :not() to apply/unapply borders on menu
Add line height to body
Everything is centered vertically
Comma separated list
Use negative nth-child to select items
Use SVG
for icons Optimize display text
For pure CSS sliders use max-height
Inheritance box-sizing
TableUniform width of cells
Use Flexbox to get rid of various hacks of margins
Use attribute selector for empty link
Use :not() to apply/unapply borders on menu
First add a border to each menu item
1 2 3 4 |
|
...and then remove the last element...
//* remove border */
1 2 3 |
|
...You can directly use the :not() pseudo-class to apply elements:
1 2 3 |
|
This way the code is clean, readable, and easy to understand.
Of course, if your new element has sibling elements, you can also use the universal sibling selector (~):
..nav li:first-child ~ li {
1 2 |
|
Add line height to body
You don't need to add line-height separately to each <p>, <h*>, etc. Just add it to body:
1 2 3 |
|
This way text elements can easily inherit from body .
Everything is centered vertically
To center all elements vertically, it's too easy:
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Look, isn't it very simple?
Note: Be careful with flexbox in IE11.
Comma separated list
Make HTML list items look like a real, comma-separated list:
1 2 3 |
|
Use the :not() pseudo-class for the last list item.
Use negative nth-child to select items
Use negative nth-child in CSS to select item 1 to item n.
1 2 3 4 5 6 7 8 |
|
It's that easy.
Use SVG
for icons There is no reason not to use SVG for icons:
1 2 3 |
|
SVG has good scalability for all resolution types and supports all browsers returning to IE9. This way you can avoid .png, .jpg or .gif files.
Optimize display text
Sometimes fonts don't display optimally on all devices, so let your device browser help you:
1 2 3 4 5 |
|
Note: Please use optimizeLegibility responsibly. Additionally, IE/Edge has no text-rendering support.
Use max-height
for pure CSS sliders Use max-height and overflow hiding to implement a CSS-only slider:
1 2 3 4 5 6 7 8 9 |
|
Inherit box-sizing
Let box-sizing inherit html:
1 2 3 4 5 6 7 |
|
This makes it easier to change box-sizing in plugins or other components that leverage other behaviors.
Table cells are of equal width
Tables are cumbersome to work with, so be sure to use table-layout: fixed to keep cells of equal width:
1 2 3 |
|
Various hacks to get rid of margins using Flexbox
When you need to use column separators, you can get rid of the nth-, first-, and last-child hacks through flexbox's space-between property:
1 2 3 4 5 6 7 8 |
|
List separators will now appear at evenly spaced positions.
Use attribute selector for empty links
Display the link when the <a> element has no text value but the href attribute has a link:
1 2 3 |
|
Quite convenient.
support
These advanced techniques work effectively in current versions of Chrome, Firefox, Safari, and Edge, as well as IE11.
The above is the detailed content of Share 12 awesome CSS skills. For more information, please follow other related articles on the PHP Chinese website!

Hot tools Tags

Hot Article

Hot tools Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

What language is the browser plug-in written in?
