-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inline Styles #213
Comments
Object syntax in inline styles is not supported at the moment. <div x-data="{ color: 'red' }">
<div :style="`background-color: ${color}`"></div>
</div> |
Ah, I see. So it's not a feature yet. Okay, no problem! By the way, this is quite an excellent framework. jQuery is good in terms of targeting elements without adding extra code to the DOM, but can get troubling with the query selectors (especially loops). VueJS is also good in terms of being a very robust framework, but might be too big for some cases. AlpineJS really delivers that mid-point front-end developers look for! |
Thanks for the kind words @bnikkhah Yeah, it's a feature that really should be added, I just haven't gotten to it. |
@calebporzio is it cool if I give this a shot? Any weird cases you're aware of? |
For anyone still looking/confused as to how to achieve this, I've found the It's installable from npm with You can then use it as follows: <div x-data="">
<div class="box" :style="styleNames({ backgroundColor: 'red' })"></div>
</div> |
I'll close this for now, the proposed changes aren't going into v2 and I'm supporting a package to achieve this kind of functionality outside of Alpine.js Feel free to comment and reopen. |
Hi, how about alpine dynamic inline style with conditional? someone knows here the syntax?
How do i insert the conditional . that it will just initialize once passed the condition |
Is it possible to have inline styles in AlpineJS? I've tried something on CodePen, but nothing was working. Consider the following code:
Assuming
.box
haswidth: 100px;
,height: 100px
, and abackground-color: 'blue'
, the code above should make the box the color ofred
, but it does not.I've tried the same code in VueJS and it did work with inline styles. Here is the same code in VueJS:
Is there an extra step to consider when working with inline styles in AlpineJS? I didn't see anything mentioned about inline styles in the GitHub documentation.
Thanks for the help!
The text was updated successfully, but these errors were encountered: