CSS Reset can maintain a consistent style style on different browsers. You can use the CSS Reset library normalize, etc., or you can use a more streamlined reset method:
Property.
Center any element verticallyNo! This is not black magic, really can be vertically centered on any element:
Body { %; 0;} Flex;}
That's not enough? Vertical direction, horizontal direction? Any element, any time, any place? Css-tricks has a good article about the various centering techniques.
Note: IE11 support for Flexbox is a bit of a bug.
Comma separated listMake each item of the list separated by commas:
Li: Not (: last-child)",";}
Pseudo-class can be used because the last item does not have a comma :not() .
Note: This technique is not ideal for accessibility, especially for screen readers. and copying and pasting does not take away CSS-generated content, you need to be aware.
Use a negativenth-childTo select an elementUse negative to nth-child select between 1 and n elements.
Li { none;} */li: Nth-child (block;}
Perhaps you have mastered how to use :not() this technique and try this:
*/li: Not (: Nth-child (none;}
So simple!
Using the SVG iconThere is no reason not to use the SVG icon:
. logo { url ("Logo.svg");}
SVG scales well at all resolutions and supports all IE9 later browsers, discarding your. png,. jpg, or. gif-jif-whatev file.
Note: For icons-only buttons, the following styles are useful for accessibility if SVG is not loaded successfully:
. icon-only: After { attr (aria-label);}
Use the "Owl-shaped" selectorThe name may be unfamiliar, but the Universal selector ( * ) is used with the neighboring sibling selector ( + ) for extraordinary results:
* { 1.5em;}
In this example, all adjacent sibling elements in the document flow will be margin-top: 1.5em styled.
More "owl-shaped" selector, can refer to a List Apart above Heydon Pickering article
Usemax-heightTo create a plain CSS slidermax-heightTo create a plain CSS slider with overflow hidden:
. slider { px; px;} . SliderScroll;}
The max-height overflow section can be displayed by increasing its value when the mouse is moved into the slider element.
Back to Catalog
Create Grid-width tablestable-layout: fixedAllows each lattice to remain equal width:
. calendar { fixed;}
Painless table layout.
Use Flexbox to remove excess marginInstead of using nth- , first- and last-child removing the extra gap between columns, use the Flexbox space-between property:
. list { flex; Space-between;} %;}
The gap between columns is always evenly equal.
Use the property selector to select an empty linkWhen an <a> element has no textual content, but has href attributes, it displays its href properties:
a[href^="http"]: Emptyattr (href);}
Quite simple.
Define a style for the "default" linkDefine a style for the default link:
a[href]: not ([class]) { underline;}
Links inserted through CMS systems, usually without class attributes, can be screened by the above styles without affecting other styles.
Consistent vertical RhythmThe universal selector ( * ) is used with elements to maintain a consistent vertical rhythm:
* { 1.25rem;}
Consistent vertical rhythm provides visual aesthetics and enhances readability of content.
Fixed proportional boxTo create a box with a fixed scale, all you need to do is set a padding for the DIV:
.container {height: 0; padding-bottom: 20%; position: relative;} .container div {border: 2px dashed #ddd; height: 100%; left: 0; position: absolute; top: 0; width: 100%;}
Use 20% padding-bottom to make the box equal to the height of 20% of its width. Regardless of viewport width, the sub-element's div retains its aspect ratio (100%/20%= 5:1).
Defining styles for broken imagesJust a little bit of CSS can beautify broken images:
img { block; %;}
To display a reference to the user information and URL by adding a pseudo-element rule:
IMG: Before { "We ' re sorry, the image below is broken:(;} imgattr (")px;}
Learn more about this style of Ire Aderinokun's original posts.
UseremTo adjust the global size;emTo adjust the local sizeAfter the root element is set to the base font size ( html { font-size: 100%; } ), use em the font size to set the text element:
H2 { 2em;} p { 1em;}
Then set the module's font size to rem :
Article { 1.25rem;} . 9rem;}
Now, each module becomes independent, easier and more flexible to maintain.
Hide movies that don't mute, autoplayThis is a good technique for customizing user style sheets. Avoid playing automatically when the page loads. If it is not muted, the video is not displayed:
video[AutoPlay]: not ([muted]) { none;}
Again, we took advantage :not() of the advantages.
Using selectors:rootTo control font elasticityIn a responsive layout, the font size should be adjusted according to the different viewports. You can calculate the font size and width depending on the height of the viewport, which you need :root :
: root { calc (11. 5vmin);}
You can now use theroot em
Body { 1rem/sans-serif;}
Set the font size for a form element for a better mobile experience<select>to avoid zooming in the form element on the mobile browser (IOS Safari, etc.) when the drop-down list is triggered, plus font-size :
input[Type="Text"],input[type="Number"],Select, px;}
Support situationThese tips apply to the latest versions of Chrome, Firefox, Safari, Opera, Edge, and IE11.
CSS Professional Tips