In my Nuxt 2 app, I am attempting to create a component that includes a <style>
tag with CSS properties for styling. My aim is to set default CSS properties within the component that can then be overridden externally.
However, I have encountered an issue where the default values do not seem to take effect at all.
<style lang="scss" scoped>
:root {
--default-badge-color: linear-gradient(90deg, #1717ff 0%, #bc29e0 92%);
--default-badge-text-color: #fff;
--default-badge-font-size: 1.6rem;
--default-badge-padding: 0.6rem 1rem;
--default-badge-border-radius: 16px;
}
.badge {
display: inline-flex;
align-items: center;
justify-content: center;
padding: var(--badge-padding, var(--default-badge-padding));
border-radius: var(--badge-border-radius, var(--default-badge-border-radius));
background: var(--badge-color, var(--default-badge-color));
color: var(--badge-text-color, var(--default-badge-text-color));
font-size: var(--badge-font-size, var(--default-badge-font-size));
text-align: center;
}
</style>
Am I using the wrong syntax for this approach?
EDIT: I have now corrected the line to
padding: var(--badge-padding, var(--default-badge-padding))
. However, the CSS properties still do not apply unless defined directly inside the .badge
selector.