Add Border ...
... Then remove the border of the last element ...
... Use pseudo-classes to :not()
apply styles to only the elements you need:
CSS
123 |
body { line-height: 1; } |
In this way, text elements can be easily body
inherited from.
Center any element verticallyNo, it's not black magic, you can really center any element vertically:
CSS
123456789101112 |
html, body { height: 100%; margin: 0; }body { -webkit-align-items: Center; -ms-flex-align: Center; align-items: Center; display: -webkit-flex; display: flex; } |
Want to center other elements? Vertical, Horizontal ... Any thing, any time, any position? There is a good article on css-tricks to do it all.
Note: Some defective behavior of flexbox on IE11.
Comma-separated listMake the list look more like a real comma-separated list:
CSS
123 |
ul > Li:not (: Last-child):: After { content: ","; } |
Use pseudo :not()
-classes so that the last element is not added as a comma.
Use negativenth-child
Select elementUse negative nth-child in CSS to select elements from 1 to n.
CSS
123456789 |
Li { display: none; } / * Select elements from 1 to 3 and display * /li:nth-child (-n+3) { display : Block; } |
Or, you've learned something about using :not()
, try:
CSS
1234567 |
/ * Select items 1 through 3 and display them * / / * Select elements from 1 to 3 and display * / Li:not (: Nth-child (-n+3)){ display: none; } |
It's simple.
Using the SVG iconThere is no reason not to use the SVG icon:
CSS
123 |
. logo { background: url("Logo.svg"); } |
SVG has good scalability for all resolution types and is supported by all browsers above IE9. So give up any files such as png,.jpg or Gif-jif.
Note: If you use the SVG icon button while SVG fails to load, the following can help you maintain accessibility:
CSS
123 |
. No-svg. icon-only:after { content: attr(aria-label); } |
Text Display optimizationSome fonts are not optimally displayed on all devices, so let the device browser help:
CSS
12345 |
html { -moz-osx-font-smoothing: grayscale -webkit-font-smoothing : antialiased text-rendering< Span class= "Crayon-sy" >: optimizelegibility |
Note: please use the optimizeLegibility
. At the same time, Ie/edge does not support text-rendering
.
Used on the content slider of a pure CSS implementationmax-height
Use on the content slider of the pure CSS implementation max-height
, and set overflow hidden:
CSS
123456789 |
. Slider ul { max-height: 0; overlow: hidden; }. Slider:hover ul { max-height: 1000px; transition: . 3s ease; / * Animate to Max-height * /} |
Inheritedbox-sizing
From html
inheritance box-sizing
:
CSS
1234567 |
html { box-sizing: border-box; } ,: Before, *:after { box-sizing: inherit; } |
This makes it easy for plugins or components that use other behaviors to change box-sizing
.
Table cell widthUsing a table can be painful, so use it table-layout:fixed
to maintain the same width of the cell:
CSS
123 |
. Calendar { table-layout: fixed; } |
Painless table layout.
Use Flexbox to get rid of the border hackWhen using column constraints, you can discard nth-
, first-
and last-child的
hacks, and use the properties of Flexbox space-between
:
CSS
12345678 |
< Span class= "Crayon-k" >.list { display: flex justify-content: space-between } .list. Person { flex-basis: 23% |
Column constraints are now always present at equal intervals.
Use the property selector to select an empty linkShow links with no text values but href
attributes that have linked a
elements:
CSS
123 |
a[href^= "http"]:empty::before { content: attr(href); } |
It is convenient to do so.
Browser supportThese tips are available in the current version of Chrome,firefox, Safari, and Edge, and IE11 can work.