gpt4 book ai didi

html - CSS::.className 和 div.className 的区别

转载 作者:太空狗 更新时间:2023-10-29 14:40:17 24 4
gpt4 key购买 nike

我写了一个html元素如下::

<div class="box"> Foo box </div>

像这样写css

.box {
width: 400px;
height: 40px;
color: red;
text-align: center;
}

or

div.box {
width: 400px;
height: 40px;
color: red;
text-align: center;
}

我想问一下盒子类的两个 css 有何不同。

最佳答案

区别在于,在第一个类中,您告诉所有元素(divpspan ...)类 box 具有该属性。像这样:

<span class="box">test</span>
<div class="box">test</div>
<p class="box">test</p>

第二个类意味着只有类 box 的 div 具有该属性

只有这个元素得到二等:

<div class="box">test</div>

class前的selector指定哪些类型的元素可以带这个class

关于html - CSS::.className 和 div.className 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20369749/

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