Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
I have html element:
<div style="grid-column: span 1">
I would like to use function to determine span size: I try something like this, but it doesn't render.
:style="{ 'grid-column: span': getColumnSize('string') }"
what is correct syntax?
use computed method. in computed method you can write a function that return your style as an object. then use it in your html.
computed
<div :style="getColumnSize"></div>
computed: { getColumnSize() { return { gridColumn: 'span 1' } } }
note: you should use camel case.
Add a comment
i would store the value of span in data then place the value in style like this
<div :style="`grid-column : span ${spanValue}`"> new div with grid</div>
you can do like this
<div :style="{ 'grid-column': `span ${getColumnSize('string')}` }"></div>
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.