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

扶醉桌前 提交于 2019-12-05 11:06:19

问题


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.


回答1:


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;
}



回答2:


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.



来源:https://stackoverflow.com/questions/13778100/is-there-any-way-to-get-another-element-value-in-less

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!