有没有办法在Less中获得另一个元素值?

Joo*_*oxa 17 css less

我是新手Less.

在我的剧本,我想使用widthbox1box2.

请查看我的脚本.

#box1
{
    width: 1000px;
    height: 500px;
}
#box2
{
    width: #box1.width - 100px;
}
Run Code Online (Sandbox Code Playgroud)

有可能吗?如果是,请给我正确的Less代码.

Pev*_*ara 7

不幸的是,这确实是不可能的.您可以使用变量并执行类似这样的操作:

@box1width: 1000px;
#box1
{
    width: @box1width;
    height: 500px;
}
#box2
{
    width: @box1width - 100;
}
Run Code Online (Sandbox Code Playgroud)

  • @PetrPeller"确实"可能,但你如何根据`#box1`的宽度设置`#box2`的宽度.没有办法访问单个属性表单选择器(据我所知). (2认同)