Div width based on variable?

33 views
Skip to first unread message

David Allen

unread,
Dec 26, 2019, 1:50:35 PM12/26/19
to TiddlyWiki
How do I style a div so that its width as well as its left and right margins are set by variables?

<$set name="span_percent" value="50">

<div style="????????">

</div>

</$set>


Eric Shulman

unread,
Dec 26, 2019, 2:06:16 PM12/26/19
to tiddl...@googlegroups.com
You want to use a macro to construct the style definition.  Something like this:

\define setWidth() width:$(width)$;margin-left:$(margin_left)$;margin-right:$(margin_right)$;

<$vars width="50%" margin_left="25%" margin_right="25%">
<div style=<<setWidth>>>
   content goes here
</div>
</
$vars>

notes:
* $vars does the same thing as $set but supports setting multiple variables in the same widget
* I used a "one line macro", which includes the name and definition all on the same line, and thus doesn't need a \end
* I include the "%" symbol in the variable values so that the macro can be used with other type of measurements, e.g.:
<$vars width="20em" margin_left="10em" margin_right="auto">

enjoy,
-e
Eric Shulman

Reply all
Reply to author
Forward
0 new messages