Inline Styles #762
Replies: 3 comments 6 replies
-
As of now yes, the correct way to do what you are trying is:
And this can be taken further with
|
Beta Was this translation helpful? Give feedback.
-
These examples are extremely helpful. Commenting so I can follow updates as I am trying to do something similar. |
Beta Was this translation helpful? Give feedback.
-
I don't quite understand how the css components are supposed to work though. I understand that templ will generate a <style> element above the element that used the css component with a random class name. Every time i attempt to use it though the <style> element gets converted to a string and doesn't work. For example: this template: css stashBackground(stash model.UserStash) {
background-color: {"#" + stash.ColourHex};
}
templ StashList(stashes []model.UserStash, options model.StashOverviewItemsOptions) {
<select
name="stashId"
id="userStashes"
class="stash-item-criteria select select-bordered w-full max-w-xs h-full disabled:skeleton disabled:z-0"
if len(stashes) == 0 {
disabled
}
hx-get="/user/stashes/items"
hx-target="#stashItems"
hx-swap="outerHTML"
hx-params="*"
hx-indicator="#itemsSpinner"
>
<option disabled selected>Select a Stash Tab</option>
for _, stash := range stashes {
<option class={ stashBackground(stash) } value={ stash.Id }>{ stash.Name }</option>
}
</select>
} becomes this when generated: <select name="stashId" id="userStashes" class="stash-item-criteria select select-bordered w-full max-w-xs h-full disabled:skeleton disabled:z-0" hx-get="/user/stashes/items" hx-target="#stashItems" hx-swap="outerHTML" hx-params="*" hx-indicator="#itemsSpinner">
<option disabled selected>Select a Stash Tab</option>
<style type="text/css">
.stashBackground_43c3 {
background-color: #ffffff;
}
</style>
<option class="stashBackground_43c3" value="">Test</option>
</select> then the browser places it in the DOM like this: <select name="stashId" id="userStashes" class="stash-item-criteria select select-bordered w-full max-w-xs h-full disabled:skeleton disabled:z-0" hx-get="/user/stashes/items" hx-target="#stashItems" hx-swap="outerHTML" hx-params="*" hx-indicator="#itemsSpinner">
<option disabled="" selected="">Select a Stash Tab</option>
.stashBackground_43c3{background-color:#ffffff;}
<option class="stashBackground_43c3" value="" style="background-color: #ffffff;">Test</option>
</select> Then the styles dont get applied, |
Beta Was this translation helpful? Give feedback.
-
Hi,
I'm struggling to understand inline styles.
I would like to apply a width property aka `style="width: 50%"
I'm unsure why the docs indicate I need to use class names for styling?
Beta Was this translation helpful? Give feedback.
All reactions