Sugarcube: Element width tied to variable?

What’s the best way to style an element’s width according to a variable (an integer)? i.e, the element’s width is changed dynamically (or at least at passage load) to match the variable.

Since you’re using SugarCube, you can use the attribute directive to do that. For example:

<<set $wid = 100>>\
<img src="image.jpeg" @style="'width: ' + $wid + 'px;'">

Though I’d recommend that, instead of using “width”, you use “max-width”. That way you won’t scale up any images, which can make them look pixelated.

Enjoy! :slight_smile: