::root {
accent-color: deeppink;
}
.container img {
width: 100%;
aspect-ratio: 16 / 9;
}
@font-face {
font-family: "Size Adjusted Arial";
src: local(Arial);
size-adjust: 150%;
}
@layer layer_name {
h1 {
color: blue;
}
}
//创建匿名层
@layer {
h1 {
color: blue;
}
}
//先声明再定义
@layer base;
@layer base {
...
}
//一次性声明多个层
@layer theme, layout, utilities;
//@import导入文件时创建层
@import './theme.css' layer(theme);
/* 预先建立层顺序,从最低到最高优先级 */
@layer reset, theme, components, utilities;
/* 重置 */
@layer reset {}
/* 主题样式 */
@layer theme {}
/* 组件样式 */
@layer components {}
/* 功能样式 */
@layer utilities {}
//===其他文件使用==================================================
/* 预先定义层的顺序 */
@layer base,
theme,
layouts,
components,
utilities;
/* Base */
@import '../styles/base/normalize.css' layer(base); /* normalize or rest file */
@import '../styles/base/base.css' layer(base); /* body and base styles */
@import '../styles/base/theme.css' layer(theme); /* theme variables */
@import '../styles/base/typography.css' layer(theme); /* theme typography */
@import '../styles/base/utilities.css' layer(utilities); /* base utilities */
/* Layouts */
@import '../styles/components/post.css' layer(layouts); /* post layout */
/* Components */
@import '../styles/components/cards.css' layer(components); /* imports card */
@import '../styles/components/footer.css' layer(components); /* footer component */
contain有如下值:
layout:该元素的内部布局与页面的其他部分完全隔离,内部不受外界任何东西的影响,同时也影响不了外部。
paint:内部元素的绘制不会超出该元素,超出的部分会不可见。
size:该元素的渲染不用去检测内部元素,即跟内部元素的尺寸无关。
style(不常用):设置 counters 和 quotes两个属性不会影响到外部。
还有另外两个值,是其他属性的组合:
content: layout + paint的结合
strict: layout + paint + size的结合
content-visibility:visible; 默认值,不产生影响,元素正常渲染。
content-visibility:hidden; 该元素内容会被跳过。
content-visibility:auto; 当元素不可见(且没有交互操作)时会跳过元素内容的渲染,需要的时候再渲染。
<dialog id="dialog">
<form method="dialog">
<p>Hi, I'm a dialog.</p>
<button>OK</button>
</form>
</dialog>
<button onclick="dialog.showModal()">Open Dialog</button>
<input type="datetime-local">
const publicKeyCredentialCreationOptions = {
challenge: Uint8Array.from(
randomStringFromServer, c => c.charCodeAt(0)),
rp: {
name: "Duo Security",
id: "duosecurity.com",
},
user: {
id: Uint8Array.from(
"UZSL85T9AFC", c => c.charCodeAt(0)),
name: "lee@webauthn.guide",
displayName: "Lee",
},
pubKeyCredParams: [{alg: -7, type: "public-key"}],
authenticatorSelection: {
authenticatorAttachment: "cross-platform",
},
timeout: 60000,
attestation: "direct"
};
const credential = await navigator.credentials.create({
publicKey: publicKeyCredentialCreationOptions
});
const publicKeyCredentialRequestOptions = {
challenge: Uint8Array.from(
randomStringFromServer, c => c.charCodeAt(0)),
allowCredentials: [{
id: Uint8Array.from(
credentialId, c => c.charCodeAt(0)),
type: 'public-key',
transports: ['usb', 'ble', 'nfc'],
}],
timeout: 60000,
}
const assertion = await navigator.credentials.get({
publicKey: publicKeyCredentialRequestOptions
});
await Promise.resolve(console.log('🎉'));
// 新建 1KB 共享内存
const sharedBuffer = new SharedArrayBuffer(1024);
// 主线程将共享内存的地址发送出去
w.postMessage(sharedBuffer);
// 在共享内存上建立视图,供写入数据
const sharedArray = new Int32Array(sharedBuffer);
// Worker 线程
onmessage = function (ev) {
// 主线程共享的数据,就是 1KB 的共享内存
const sharedBuffer = ev.data;
// 在共享内存上建立视图,方便读写
const sharedArray = new Int32Array(sharedBuffer);
// ...
};
<img src="image.png" loading="lazy" alt="…" width="200" height="200">
优先级提示是对现有浏览器资源加载优先级的补充。浏览器计算资源的优先级时会考虑这些因素:
当以上因素对资源优先级控制的精细度不够时,就需要用到Priority Hints。Priority Hints可以认为是在同等优先级的基础上进行调整。
<script>
fetch('https://example.com/', {priority: 'low'})
.then(data => {
// Trigger a low priority fetch
});
</script>
lastIndex
属性;const myDeepCopy = structuredClone(myOriginal);