Having an issue with applying a specific style to one of my div elements. When using the following code:
:style="(index + 1) % 2 == (0) && type.Liste.length === indexVin + 1 ? `margin-left : calc((100% - (100% / ${type.Liste.length})) + 6rem);` : null"
The style attribute appears to remain empty, as shown in the screenshot below:
https://i.sstatic.net/NHxVq.png
However, if I change the margin-left
to either margin-right
or padding-left
, it works as expected:
https://i.sstatic.net/QNp8H.png
https://i.sstatic.net/hHr9g.png
After reading up on some documentation, I found that margin-left
should be in camelCase. Despite trying this, the issue persists. What's strange is that both margin-right
and padding-left
, which are in kebab-case, work perfectly fine.
I have made sure there are no conflicting CSS styles applied to the div element besides the one mentioned here. Unfortunately, this did not resolve the problem either.
If you have any insight into why specifically margin-left
is causing these issues, please let me know.
Edit: Upon further investigation, I discovered that although console.log functions correctly based on the conditions provided, applying margin-left
within the if(even)
block does not produce the desired result. However, when placed inside the else if(odd)
block, it works properly. A similar behavior was observed for margin-right
, yet with opposite outcomes. Any thoughts on why this might be happening?
Check out the additional code snippet below:
methods : {
computedStyle(index , type , indexVin ) {
if ((index + 1) % 2 == (0) && type.Liste.length === indexVin + 1) {
console.log('even and last')
return `margin-left : calc((100% - (100% / ${type.Liste.length})) + 6rem);`
} else if (type.Liste.length === indexVin + 1) {
console.log('odd and last')
return `margin-right : calc((100% - (100% / ${type.Liste.length})) + 6rem);`
} else {
console.log('nothing special')
return null
}
},
}
<div class="padding-block-1" v-for="(type , index) in TypesDeVins" :key="index">
<div class="tw-flex tw-items-end slider-top"
:class="[LeftOrRight(index) , FlexDirection(index)]">
<div class="colonnes-resp-2 tw-flex-shrink-0" :class="LeftOrRightMargin(index , 2)">
<h4 class="tw-uppercase tw-font-bold text-1-2 letter-spacing-3"
:class="ColorTitle(index)">Les appellations</h4>
<h2 class="tw-uppercase tw-text-white tw-font-bold text-2-4 tw-mb-12 letter-spacing-4">{{ type.Nom }}</h2>
</div>
<div class="swiper-container" :class="`slider-top-${index}`" :dir="rtl(index)">
<div class="swiper-wrapper">
<div class="nom-vin swiper-slide" v-for="(vin , indexVin) in type.Liste"
:key="indexVin"
:class="slideDir(index)"
:style="computedStyle(index , type , indexVin)"
>
<h3 class="tw-text-white tw-font-bold tw-uppercase letter-spacing-3 text-1-2 tw-pb-12">{{ vin.title.rendered }}</h3>
</div>
</div>
</div>
</div>
</div>