admin管理员组文章数量:1391991
I am using PrimeVue with TailwindCSS and have defined a custom theme preset using definePreset from @primevue/themes. However, my custom background color for the primary button is not being applied unless I use !important.
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import PrimeVue from 'primevue/config'
import Aura from '@primevue/themes/aura'
import { definePreset } from '@primevue/themes'
const MyPreset = definePreset(Aura, {
components: {
button: {
label: {
font: {
weight: 'bold',
}
},
primary: {
background: '#b8e3ff', // Not applying unless I use !important
color: 'red',
hover: {
background: '#b8e3ff',
}
}
}
}
})
const app = createApp(App)
app.use(PrimeVue, {
theme: {
preset: MyPreset,
options: {
cssLayer: {
name: 'primevue',
order: 'tailwind-base, primevue, tailwind-utilities'
}
}
}
}).mount('#app')
Important to note that the fontWeight for label is working properly without important
.
The background: '#b8e3ff' on my primary button does not apply unless I add !important.
Is there a way to fix this issue without relying on !important?
I am using PrimeVue with TailwindCSS and have defined a custom theme preset using definePreset from @primevue/themes. However, my custom background color for the primary button is not being applied unless I use !important.
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import PrimeVue from 'primevue/config'
import Aura from '@primevue/themes/aura'
import { definePreset } from '@primevue/themes'
const MyPreset = definePreset(Aura, {
components: {
button: {
label: {
font: {
weight: 'bold',
}
},
primary: {
background: '#b8e3ff', // Not applying unless I use !important
color: 'red',
hover: {
background: '#b8e3ff',
}
}
}
}
})
const app = createApp(App)
app.use(PrimeVue, {
theme: {
preset: MyPreset,
options: {
cssLayer: {
name: 'primevue',
order: 'tailwind-base, primevue, tailwind-utilities'
}
}
}
}).mount('#app')
Important to note that the fontWeight for label is working properly without important
.
The background: '#b8e3ff' on my primary button does not apply unless I add !important.
Is there a way to fix this issue without relying on !important?
1 Answer
Reset to default 1The default Styled Mode classes are designed for the colorScheme
, so they are more strict than without it. Therefore, to override styles without using !important
, you need to define the override styles within the colorScheme
for both light and dark modes.
- Theming Component in Styled Mode - PrimeVue v4 Docs
In a way, it's logical that if you want to override the original colors, they will almost always differ between light and dark modes. So, you will likely need to customize both modes.
const { createApp, ref } = Vue;
const app = createApp();
const MyPreset = PrimeVue.definePreset(PrimeVue.Themes.Aura, {
components: {
button: {
primary: {
// weaker rule than the default button.colorScheme.*.primary.background
background: '#000',
},
colorScheme: {
light: {
label: {
font: {
weight: 'bold',
},
},
primary: {
// stronger rule then button.primary.background
background: '#b8e3ff',
color: 'red',
hover: {
background: '#b8e3ff',
},
},
},
dark: {
/* ... */
},
},
},
},
})
app.use(PrimeVue.Config, {
theme: {
preset: MyPreset,
},
});
appponent('p-button', PrimeVue.Button);
app.mount('#app');
<script src="https://unpkg/vue@3/dist/vue.global.prod.js"></script>
<script src="https://unpkg/primevue/umd/primevue.min.js"></script>
<script src="https://unpkg/@primevue/themes/umd/aura.min.js"></script>
<div id="app">
<p-button
label="test"
/>
</div>
Alternatively, you can use Unstyled Mode if you want full customization.
- Theming with Unstyled Mode - PrimeVue v4 Docs
本文标签: vuejsPrimeVue Theme StylesStack Overflow
版权声明:本文标题:vue.js - PrimeVue Theme Styles - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744656120a2617974.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论