24个CSS新特性,不容错过!,如何学好web前端开发
CSS是网页样式设计的语言,新特性的学习和掌握对于提升开发者技能至关重要。以下是2023年应知应会的一些CSS新特性:
- CSS Clipper
.clipped {
clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
}
- CSS Exclusions
.excluded {
flow-root: flow-root(grid);
}
- CSS Layout
.container {
display: layout(grid);
}
- CSS Marquee
.marquee {
motion-path: path("M0,0 L100%,0");
motion-offset: 0%;
motion-rotation: auto 0deg;
}
- CSS Masking
.masked {
-webkit-mask-image: url(mask.png);
}
- CSS Nesting
.container :is(h1, h2, h3) {
color: blue;
}
- CSS Properties and Values API
CSS.registerProperty({
name: "--custom-property",
syntax: "<number>",
inherits: false,
initialValue: 0
});
- CSS Shapes
.shape {
shape-outside: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
}
- CSS Subgrid
.subgrid-item {
display: subgrid;
}
- CSS Typed Object Model
getComputedStyle(element).accumulate(true);
- Forced Colors
.forced {
forced-color-adjust: none;
}
- Grid Extent Sizing
.grid {
grid-template-rows: [start] 1fr [end];
}
- Image Rendering
img {
image-rendering: pixelated;
}
- Logical Properties
.box {
border-inline-start-width: 2px;
}
- MathML Accessibility
math {
speech: "math speech";
}
- New Properties and Values
.box {
aspect-ratio: 16 / 9;
}
- Paint API
const canvas = document.createElement("canvas");
const ctx = canvas.getContext("bitmaprenderer");
const img = new Image();
img.src = "image.png";
img.onload = () => {
ctx.transferFromImageBitmap(img);
};
- Pointer Events
.nopointer {
pointer-events: none;
}
- Regions
.region {
flow-into: "region-name";
}
- Resize Observer
new ResizeObserver(entries => {
for (let entry of entries) {
const cr = entry.contentRect;
console.log(`Element's size: width = ${cr.width}, height = ${cr.height}`
评论已关闭