1. Multi-column Layout
CSS provides support for multi-column layouts. Support columns disposed layout ( column-count
), the flow rule how the content should be included between the spacing (between columns column-gap
) and the column division lines ( column-rule
style) of.
For example, the following waterfall effect can be achieved:
main styles:
.masonry {
width: 1440px;
margin: 20px auto;
columns: 4;
column-gap: 30px;
.item {
width: 100%;
break-inside: avoid;
margin-bottom: 30px;
img {
width: 100%;
}
}
}
2. Writing Modes
Writing Modes defines various international writing modes, such as left-to-right (Latin, Indian), right-to-left (Hebrew, Arabic), bidirectional (mixed left-to-right and right-to-left Language) and vertical (Chinese).
The following is a display of three writing methods:
key style:
.left-to-right {
direction: ltr;
}
.right-to-left {
direction: rtl;
}
.vertical {
writing-mode: vertical-rl;
}
Or, it can be used to implement a code rain of The Matrix:
3. aspect-ratio
attributes
aspect-ratio
property of CSS is used to set the preferred aspect ratio of the element, which can automatically calculate the width, height and other layout functions, eliminating the need to calculate the width and height at the same time.
For example, a video website can set the video playback window ratio to 16/9:
key style:
.video-box {
width: 70vw;
background-color: #000;
aspect-ratio: 16/9;
}
4. gap
attributes
gap
property of CSS is used to set the spacing between rows and columns during flex and grid layout. It is the abbreviation row-gap
and column-gap
In the past, when using flex layout, margin
and padding
were often used to control the interval between flex items. gap
would be more convenient to use 061ceb9bdcb2dc.
for example:
<div class="flex-box">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
.flex-box {
display: flex;
width: 400px;
flex-wrap: wrap;
gap: 20px;
}
.item {
width: 120px;
height: 60px;
background-color: c·rimson;
}
5. CSS Shapes
CSS Shapes are used to describe the geometric shapes of elements. The regular shape of an element is a rectangle. Using CSS Shapes, you can define an element as a circle, ellipse, or polygon.
For the Level 1 specification, CSS Shapes can be applied to floating elements. The specification defines different methods to define shapes on floating elements.
For example, to achieve the effect of the following text surrounding a circular picture:
key style:
img {
width: 300px;
float: left;
shape-outside: circle(50%);
}
6. object-fit
attributes
object-fit
attribute is used to set replaced element (for example, <img>
or <video>
) adapts to the size of its container.
For example, to adjust the display of a picture in the container:
7. filter
attributes
The filter
property of CSS applies image effect adjustments (blur, contrast, grayscale, hue, etc.) to elements. filter
is usually used to adjust the rendering of images, backgrounds and borders.
For example, on the National Memorial Day every year, many websites will adjust the color to black and white. You can do it with a line of code filter
8. backdrop-filter
attributes
Similar to filter
, the backdrop-filter
attribute applies graphic effects (such as blur or color shift) to the background area of the element. Because it applies to all the content behind the element, you need to set the element or its background to at least partly transparent to see the effect.
For example, you can use it to make a frosted glass effect:
key code:
<div class="box">
<p>
If I know what love is
<br />it is because of you
</p>
</div>
.box {
background: url(../images/roses.jpg) no-repeat;
}
p {
background-color: rgba(255, 255, 255, 0.3);
backdrop-filter: blur(20px);
color: white;
}
9. conic-gradient()
function
linear-gradient()
with the 061ceb9bdcb88a function in CSS. In addition, there are radial-gradient()
and conic-gradient()
in the gradient family. For more types, please refer to MDN-gradient .
conic-gradient()
function creates an image that is composed of gradient colors with colors rotating around the center point (rather than radiating from the center).
For example, a common gradient color dashboard chart can be drawn conic-gradient()
10. accent-color
attributes
accent-color
property of CSS is used to set the accent color of UI controls generated by certain elements. For example, the color checkbox
and radio
controls generated by the <input>
For example, change the accent color of the following elements:
key code:
<input type="checkbox" class="checkbox" checked />
<input type="radio" class="radio" checked />
<input type="range" class="range" />
<progress value="70" max="100" class="progress">70%</progress>
.checkbox {
width: 40px;
height: 40px;
accent-color: crimson;
}
.radio {
width: 40px;
height: 40px;
accent-color: dodgerblue;
}
.range {
width: 200px;
accent-color: lawngreen;
}
.progress {
width: 200px;
accent-color: coral;
}
11. Scroll Snap
CSS Scroll Snap introduces the capture of the scroll position, which enforces the position where the scroll port of the scroll container may end after the scroll operation is completed.
For example, I want to make the end of each scroll stop at the beginning of the next element to achieve the effect of scrolling and turning pages:
key code:
<article class="scroller">
<section>
<h2>Page one</h2>
</section>
<section>
<h2>Page two</h2>
</section>
<section>
<h2>Page three</h2>
</section>
<section>
<h2>Page four</h2>
</section>
</article>
.scroller {
overflow-y: scroll;
scroll-snap-type: y mandatory;
}
section {
scroll-snap-align: start;
}
12. overscroll-behavior
attributes
overscroll-behavior
property of CSS is used to define the behavior when the element scrolls to the border of the scrolling area. It is overscroll-behavior-x and overscroll-behavior-y .
The default behavior of the browser is: when the child element scrolls to the boundary, continue to scroll the mouse, it will trigger the scroll of the parent element. This behavior is called scroll chaining . Many times we don't need this behavior. For example, when we scroll the content in a pop-up window, we don't want the following pages to also scroll. This behavior can be modified by setting overscroll-behavior:contain
, without the need to monitor the scroll
event to prevent bubbling.
example : Codepen demo
Well, there are so many that can be thought of at the moment, I hope it will be helpful for everyone to draw pages more efficiently and elegantly😀!
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。