gpt4 book ai didi

css - 是否可以在 .less 组件中放置重复的样式

转载 作者:行者123 更新时间:2023-12-04 10:37:06 25 4
gpt4 key购买 nike

是否可以将某些 css 样式放在组件中并在不同位置重复使用?在下面的示例中,我对 .navigation 重复相同的样式类(class):


.container-1 {
.navigation {
width: 100%;
}
}

@media (max-width:991px) {
.container-1 {
.navigation {
margin-top: 0px; // <-- repeated
background-color: #252525; // <-- repeated
width: 250px; // <-- repeated
}
}
}

.container-2 {
.navigation {
margin-top: 0px; // <-- repeated
background-color: #252525; // <-- repeated
width: 250px; // <-- repeated
}
}

最佳答案

在较少的情况下,您可以使用 Mixins为了这:

.navigation-styles {
margin: 0;
padding: 0;
list-style: none;
}

@media (max-width:991px) {
.container-1 {
.navigation {
.navigation-styles();
}
}
}

.container-2 {
.navigation {
.navigation-styles();
}
}

请查看文档 here

关于css - 是否可以在 .less 组件中放置重复的样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60122987/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com