gpt4 book ai didi

html - 只影响容器中的元素

转载 作者:行者123 更新时间:2023-11-27 23:57:16 25 4
gpt4 key购买 nike

我有一个巨大的 CSS/bootstrap 文件,它不仅影响元素。我希望它这样做,但 css 会影响整个页面。我无法将每个元素名称更改为 [name].slider。那么有没有一种简单的方法让它只影响容器内的元素呢?

<head>
<!--the stuff in here is also affected-->
</head>

<div>
<!--Stuff to get affected-->
</div>

最佳答案

当然,在目标 div 上放置一个 id 或 class,并将该 id 或 class 添加到 css 文件的开头。如果您使用的是 Less 或 Sass,您可以将整个文件的内容嵌套在带有 id 或 class 的规则中。

.my-styled-section h3 {
color: green;
}

.my-styled-section {
color: red;
}
<head>
<!--the stuff in here is no longer affected-->
<h3>Test</h3>
<p>Test</p>
</head>

<div class="my-styled-section">
<!--Stuff to get affected-->
<h3>Test</h3>
<p>Test</p>
</div>

关于html - 只影响容器中的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56196860/

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