feat: 添加 StyleLayer 组件,展示 @layer 优先级规则及样式示例;新增 style.page.vue 页面
This commit is contained in:
81
src/components/StyleLayer.vue
Normal file
81
src/components/StyleLayer.vue
Normal file
@ -0,0 +1,81 @@
|
||||
<template>
|
||||
<div b="1px solid #ccc" p="10px" mt="10px">
|
||||
<div class="layer-demo">这是一个测试@layer的元素</div>
|
||||
<div class="layer-nested">这是测试嵌套layer的元素</div>
|
||||
|
||||
<div class="layer-explanation">
|
||||
<h3>@layer 优先级规则:</h3>
|
||||
<ol>
|
||||
<li>后定义的layer比先定义的layer优先级高</li>
|
||||
<li>在同一个layer中遵循正常的CSS优先级规则</li>
|
||||
<li>没有在任何layer中的样式优先级高于所有layer</li>
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style lang="css">
|
||||
/* 测试 @layer */
|
||||
|
||||
/* 声明layer的顺序决定了优先级 - 越后声明的优先级越高 */
|
||||
@layer base, components, utilities;
|
||||
|
||||
/* base layer 包含基础样式 */
|
||||
@layer base {
|
||||
.layer-demo {
|
||||
color: blue;
|
||||
font-size: 18px;
|
||||
padding: 10px;
|
||||
border: 1px solid #ccc;
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
.layer-nested {
|
||||
color: blue;
|
||||
padding: 10px;
|
||||
border: 1px solid #ccc;
|
||||
margin: 10px 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* components layer 包含组件样式 */
|
||||
@layer components {
|
||||
.layer-demo {
|
||||
color: red; /* 这个会覆盖base中的blue,因为components在base之后声明 */
|
||||
background-color: #f0f0f0;
|
||||
}
|
||||
}
|
||||
|
||||
/* utilities layer 包含工具类样式 */
|
||||
@layer utilities {
|
||||
.layer-demo {
|
||||
font-weight: bold;
|
||||
color: green; /* 这个会覆盖components中的red,因为utilities优先级更高 */
|
||||
}
|
||||
}
|
||||
|
||||
/* 嵌套layer的示例 */
|
||||
@layer components {
|
||||
@layer special {
|
||||
.layer-nested {
|
||||
color: purple;
|
||||
font-weight: bold;
|
||||
}
|
||||
}
|
||||
|
||||
/* components.base 比 components.special 优先级低 */
|
||||
@layer base {
|
||||
.layer-nested {
|
||||
background-color: #eaeaea;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 不在任何layer中的样式优先级最高 */
|
||||
.layer-explanation {
|
||||
margin: 20px 0;
|
||||
padding: 15px;
|
||||
background-color: #f8f8f8;
|
||||
border-left: 4px solid #42b983;
|
||||
}
|
||||
</style>
|
@ -13,16 +13,14 @@
|
||||
><br />https://unocss-preset-chinese-playground.vercel.app/
|
||||
</p>
|
||||
|
||||
<div :class="$style.hero" mt-2>
|
||||
<div mt-2 b="1px solid pink">
|
||||
<h1><i>🔌</i> Vite Plugin Webfont DL <i>⚡</i></h1>
|
||||
<h2>Fonts are downloaded directly from Google Fonts</h2>
|
||||
<pre>{{ JSON.stringify({ $style }, null, 2) }}</pre>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style module>
|
||||
/* https://cn.vuejs.org/api/sfc-css-features#css-modules */
|
||||
<style scoped>
|
||||
h1 {
|
||||
font-family: 'Press Start 2P', cursive;
|
||||
color: #646cff;
|
||||
@ -32,8 +30,4 @@ h2 {
|
||||
font-family: 'Fira Code', monospace;
|
||||
background-color: #42b983;
|
||||
}
|
||||
|
||||
.hero {
|
||||
border: 1px solid #42b983;
|
||||
}
|
||||
</style>
|
||||
|
16
src/pages/Tool/style.page.vue
Normal file
16
src/pages/Tool/style.page.vue
Normal file
@ -0,0 +1,16 @@
|
||||
<script setup lang="ts"></script>
|
||||
|
||||
<template>
|
||||
<div :class="$style.hero" mt-2>
|
||||
<pre>{{ JSON.stringify({ $style }, null, 2) }}</pre>
|
||||
</div>
|
||||
<StyleLayer />
|
||||
</template>
|
||||
|
||||
<style module>
|
||||
/* https://cn.vuejs.org/api/sfc-css-features#css-modules */
|
||||
|
||||
.hero {
|
||||
border: 1px solid #42b983;
|
||||
}
|
||||
</style>
|
1
typed-router.d.ts
vendored
1
typed-router.d.ts
vendored
@ -30,6 +30,7 @@ declare module 'vue-router/auto-routes' {
|
||||
'ToolFonts': RouteRecordInfo<'ToolFonts', '/Tool/fonts', Record<never, never>, Record<never, never>>,
|
||||
'ToolI18n': RouteRecordInfo<'ToolI18n', '/Tool/I18n', Record<never, never>, Record<never, never>>,
|
||||
'ToolIcons': RouteRecordInfo<'ToolIcons', '/Tool/Icons', Record<never, never>, Record<never, never>>,
|
||||
'ToolStyle': RouteRecordInfo<'ToolStyle', '/Tool/style', Record<never, never>, Record<never, never>>,
|
||||
'ToolTsEnumUtil': RouteRecordInfo<'ToolTsEnumUtil', '/Tool/ts-enum-util', Record<never, never>, Record<never, never>>,
|
||||
'UIComponentsAntdV': RouteRecordInfo<'UIComponentsAntdV', '/UI-components/AntdV', Record<never, never>, Record<never, never>>,
|
||||
'UIComponentsInfiniteLoading': RouteRecordInfo<'UIComponentsInfiniteLoading', '/UI-components/infinite-loading', Record<never, never>, Record<never, never>>,
|
||||
|
Reference in New Issue
Block a user