Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you create multiple box-shadow values in LESS CSS

Tags:

css

less

Read This

There are several "correct" answers. Since this question gets a lot of traffic, I figured I should keep up with what (I think) the best answer is (based on the LESS documentation) as the LESS project matures, and change my accepted answer accordingly.


I'm using LESS and I haven't been able to find a fix for allowing multiple CSS3 box-shadows. I have the following mixin:

.box-shadow(@arguments) {     -webkit-box-shadow: @arguments;     -moz-box-shadow: @arguments;     box-shadow: @arguments; } 

and I'm attempting this:

.box-shadow(     inset 0 0 50px rgba(0,0,0,0.3),     0 0 10px rgba(0,0,0,0.5); ); 

This works in normal CSS3, but fails when running from a LESS file. I've read somewhere that the comma separating the 2 shadows is what causes the issue in the LESS parser.

Does anyone know how to make this work? The only workaround I can think of is creating an additional CSS file that contains my multiple box-shadow properties.

like image 370
Mike McLin Avatar asked Feb 10 '12 16:02

Mike McLin


People also ask

Can you have multiple box shadows in CSS?

You can comma separate box-shadow any many times as you like.

Can you specify more than one box shadow to an element?

Box shadows can use commas to have multiple effects, just like with background images (in CSS3). While you can apply multiple shadows, applying inset shadows, I've found, is a special case.

How do you add shadows to items in CSS?

In CSS, shadows on the boxes of elements are created using the box-shadow property (if you want to add a shadow to the text itself, you need text-shadow ). The box-shadow property takes a number of values: The offset on the x-axis. The offset on the y-axis.


1 Answers

This works with newer LESS versions:

.box-shadow(2px 2px 3px rgba(0,0,0,.4), 0px 0px 5px rgba(0,0,0,.8););                                   // this semicolon is important! ^ 

And this uglier version works even with older LESS versions:

.box-shadow(~"2px 2px 3px rgba(0,0,0,.4), 0px 0px 5px rgba(0,0,0,.8)"); 

Update: LESS evolved, so this answer was updated and is now correct again. Thanks Michał Rybak

like image 197
iamnotsam Avatar answered Sep 20 '22 14:09

iamnotsam