gpt4 book ai didi

css - 什么时候应该在其他类选择器定义中定义 CSS 类选择器?

转载 作者:行者123 更新时间:2023-12-04 14:03:13 24 4
gpt4 key购买 nike

编辑 1根据建议,我尝试了这个:

.lower-container {
justify-content: center;
position: absolute;
width: 92vw;
// height: 46vh; <--- no height defined

/* nested for adding classes to change position and height of lower-container */
.lower-container.lower-full {
height: 92vh;
top: 0;
}

.lower-container.lower-mid {
height: 46vh;
top: 46vh;
}

.lower-container.lower-closed {
height: 1vh;
top: 91vh;
}
}

在元素面板中我看到: enter image description here

但是在样式面板中我有: enter image description here

因此,虽然我正在应用附加类,但高度没有设置,附加类也没有显示在样式中。


原始问题我正在像这样在其他类中定义一些类:

.lower-container {
height: 46vh;
display: flex;
justify-content: center;
...

.lower-full {
height: 92vh;
}
}

然后当需要改变我正在做的高度时:

    lowerContainerElement.classList.add('lower-full')

但在控制台上,该元素在样式面板中没有 .lower-full 样式,即使在元素面板中显示 class="{other classes} lower-full"

我做错了什么?

最佳答案

您不能仅使用原始 CSS 在另一个选择器中定义 CSS 选择器,您需要像 SASS 这样的预处理器。

使用 CSS,您可以指定元素何时只有 .lower-container 或两者都有的属性。这将等同于您尝试在原始代码中完成的工作。

.lower-container {
height: 46vh;
display: flex;
justify-content: center;
...
}

.lower-container.lower-full {
height: 92vh;
}

如果您已经在使用 SCSS 文件,那么您使用的语法不正确

.lower-container {
height: 46vh;
display: flex;
justify-content: center;
...

&.lower-full {
height: 92vh;
}
}

根据最新编辑进行编辑:代码应如下所示:

.lower-container {
justify-content: center;
position: absolute;
width: 92vw;
// height: 46vh; <--- no height defined

/* nested for adding classes to change position and height of lower-container */
&.lower-full {
height: 92vh;
top: 0;
}

&.lower-mid {
height: 46vh;
top: 46vh;
}

&.lower-closed {
height: 1vh;
top: 91vh;
}
}

关于css - 什么时候应该在其他类选择器定义中定义 CSS 类选择器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69331035/

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