Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to get another element value in Less?

Tags:

css

less

I'm new to Less.

In my script, I'd like to use the width of box1 in box2.

Please review my script.

#box1
{
    width: 1000px;
    height: 500px;
}
#box2
{
    width: #box1.width - 100px;
}

Is it possible or not? If yes, please give me correct Less code.

like image 312
Jooxa Avatar asked Dec 08 '12 13:12

Jooxa


2 Answers

unfortunatly it is indeed not possible. You could work with variables and do something like this however:

@box1width: 1000px;
#box1
{
    width: @box1width;
    height: 500px;
}
#box2
{
    width: @box1width - 100;
}
like image 143
Pevara Avatar answered Dec 01 '22 21:12

Pevara


No, that's not possible. LESS processes the style sheet to produce CSS, and it doesn't have any knowledge of the elements in the page.

What you are looking for is CSS Expressions, but that was only supported in Internet Explorer, and support for that was dropped in IE8.

like image 37
Guffa Avatar answered Dec 01 '22 22:12

Guffa