I'm trying to use this approach (In vue.js component, how to use props in css?) to put prop-based variables in my css code.
I have a component called TouchLayout
, and I would like to edit a css property belonging to a <main>
tag that is a grand parent of my component. Usually I put my css variables in :root, but for this task I think I can't do it.
So I am currently setting this computed prop in my component:
computed: {
cssProps() {
return {
'--main-padding-bottom': this.hasFooter ? '40px' : '20px'
}
}
}
and in template I use
<template>
<div class="h-full" :style="cssProps">
...
But my css var isn't recognized:
<style>
main.v-main {
padding-bottom: var(--main-padding-bottom);
Is it possible to set a css var in a child component and, by the magic of unscoped css, use it in a grand parent?