原子化css |
互动样式 |
样式参考 |
Tailwind CSS |
颜色样式 |
加深理解inline、block、inline-block
可以认为Unocss兼具了TailwindCSS 和 Windicss的优点,同时还具有自身的定制性和灵活性。按需引入,体积小,速度快。
1. 基本使用,可以直接在class中定义。在Unocss省略class直接写样式也是可以的,而且有代码提示。
<div class="bg-blue-200"> Index Page</div>
<div bg-pink-200 text-cyan>我的国家</div>
2. 在style中定义
<div class="text"> Index Page</div>
<style>
.text {
@apply text-xs text-red-300 hover:bg-zinc-900;
}
.btn {
@apply text-red-700 border border-red-500 !rounded-full; // rounded-full !important
}
</style>
3. 混合的写法也是可以的
.test {
color: white;
font-size: 2rem;
@apply bg-blue;
}
4. 属性模式(Attributify Mode)
<button
bg="blue-400 hover:blue-500 dark:blue-500 dark:hover:blue-600"
text="sm white"
font="mono light"
p="y-2 x-4"
border="2 rounded blue-200"
>
Button
</button>
5. `uno.config.ts`中定义 rules 或 shortcuts
rules: [
['custom-rule', { color: 'red' }],
['main2', { margin: '0.25rem', padding: '2rem', color: 'red',
'background-color': 'blue'}],
],
shortcuts: {
// shortcuts to multiple utilities
'custom-shortcut': 'text-lg text-orange hover:text-teal',
'btn': 'py-2 px-4 font-semibold rounded-lg shadow-md',
'btn-green': 'text-white bg-green-500 hover:bg-green-700',
// single utility alias
'red': 'text-red-100'
}
RE: Nuxt开发指南