Support the ongoing development of Laravel.io →
posted 10 years ago
Views
Last updated 2 years ago.
0

One way would be inline styles or styles in <head>. I don't think you can use variables in .css file

Last updated 2 years ago.
0

You'd need to run the CSS files through PHP for something like:

<?= $item->variable ?>

to work. You won't get blade structures in there like your example. However, this is not recommended. What you should do is instead use Sass to generate multiple static stylesheets, then use a session setting to send the right one with the view. At least until CSS variables are in more browsers and you can start using those client-side with JS to manipulate it on-the-fly.

Last updated 2 years ago.
0
Solution

One way of doing it would be to have a default background color set in your css file, then in your view page just do:

// foreach product { 

   <div class="product" style="background-color: {{ $product->color }}">

// }
Last updated 2 years ago.
0

Yes as per new update in CSS version and Browser flexibility. The developer can create a variable in CSS.

As per reference of create variable in CSS file we can make it happen.

It can be done with two steps:

  • Declare variable in root
  • Use that variable in code
:root  {
     --border-color: #e8e8e8;
    --h2-color:#1A237E;
}

Now, we create --border-color variable that we have to apply in div tag.

div { 
     border: 2px solid var(--border-color);
}
0

@GuruQuest That was awesome! Tks!

0

Sign in to participate in this thread!

Eventy

Your banner here too?

jonaweb jonaweb Joined 22 Apr 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.