- Use: not () apply/deselect border on menu
- Add row height to body
- Everything is centered vertically
- comma-delimited List
- Use negative nth-child to select items
- Use SVG for icons
- Optimize display text
- Use Max-height for pure CSS Sliders
- Inherit box-sizing
- Table cell width
- Use Flexbox to get rid of the various hack of the outer margin
- Use the property selector for empty links
Use: not () apply/deselect border on menu
Add a border to each menu item first
/* add Border */li { #666;}
...... Then remove the last element ...
* Remove Border * *
Li: last-child { border-right:none;}
...... You can use the: not () pseudo-class to apply the element directly:
Li: Not (: Last-child) { #666;}
This makes the code clean, easy to read, and easy to Understand.
of course, If your new element has sibling elements, you can also use the generic sibling selector (~):
.. Nav Li:first-child ~ Li {
border-left:1px Solid #666;}
Add row height to body
You don't need to add line-height to each one separately <p> , . As long as you add to Body:
Body { 1;}
This allows text elements to be easily inherited from the Body.
Everything is centered verticallyTo center all the elements vertically, it's too simple:
Body { 100%; 0;} display:flex;}
look, isn't it simple.
Note: be careful flexbox in IE11.
comma-delimited ListMake the HTML list item look like a real, comma-delimited list:
Li: Not (: Last-child):: After { ",";}
Use the: not () pseudo-class for the last list Item.
Use negative nth-child to select itemsUse negative nth-child in CSS to select item 1 to Project N.
Li { display:none;} /* Select items 1 through 3 and display them*/li: nth-child (-n+3) { display:block;}
It's so Easy.
Use SVG for iconsThere is no reason for us not to use SVG for icons:
. logo { url ("logo.svg");}
SVG has good extensibility for all resolution types and allows all browsers to return to IE9. This avoids. png,. jpg, or. gif files.
Optimize display textsometimes, fonts don't get the best display on all devices, so you can have your device browser help you:
HTML { -moz-osx-font-smoothing:grayscale; -webkit-font-smoothing:antialiased; text-rendering:optimizelegibility;}
Note: Please use optimizelegibility responsibly. In addition, Ie/edge does not have text-rendering Support.
Use Max-height for pure CSS SlidersUse max-height and overflow hiding to implement only CSS Sliders:
UL { 0; overlow:hidden;} . Slidertransition:. 3s ease;}
Inherit box-sizingLet box-sizing inherit Html:
HTML { box-sizing:border-box;} *, *: before, *: After { box-sizing:inherit;}
This makes it easier to change the box-sizing in other components of the plug-in or leverage other Behaviors.
Table cell widthTables are cumbersome to work with, so be sure to use table-layout:fixed as much as possible to maintain the width of the cell:
. Calendar { table-layout:fixed;}
Use Flexbox to get rid of the various hack of the outer marginWhen you need to use the column delimiter, by flexbox the Space-between property, you can get rid nth- ,first- of, and last-child 的 hack out:
. List { display:flex; justify-content:space-between;} . Person { 23%;}
The list separator now appears at an evenly spaced position.
Use the property selector for empty linksWhen the <a> element does not have a text value, but the href attribute has a link, the link is displayed:
A[href^= "http"]: Empty:: before { attr (href);}
Very convenient.
SupportThese advanced techniques work effectively in chrome, Firefox, Safari, the current version of edge, and IE11.
Reprinted from: http://www.codeceo.com/article/12-css-protips.html
12 CSS Advanced Tips Summary [reprint]