CSS :: .className和div.className之间的区别 [英] CSS :: Difference between .className and div.className
本文介绍了CSS :: .className和div.className之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< div class =box> Foo box< / div>
并写入像
.box {
width:400px;
height:40px;
颜色:红色;
text-align:center;
}
或
div.box {
width:400px;
height:40px;
颜色:红色;
text-align:center;
}
我想问一下,这两个css for box类与每个其他的。
解决方案
区别在于,在第一个类中,您告诉所有元素( code>,
p
, span
...) code>具有该属性。
像这样:
< span class =box>测试< / span>
< div class =box> test< / div>
< p class =box>测试< / p>
第二类意味着只有class box $ c $
< div class =box> test< / div>
在类之前的选择器
指定哪种类型的元素可以采用这个类
I write a html element as below ::
<div class="box"> Foo box </div>
and write css like
.box {
width: 400px;
height: 40px;
color: red;
text-align: center;
}
or
div.box {
width: 400px;
height: 40px;
color: red;
text-align: center;
}
I want to ask that how the both css for box class is different than each other.
解决方案
The difference is that in the first class you tell that all element (div
, p
, span
...) with class box
have that attribute.
Like this:
<span class="box">test</span>
<div class="box">test</div>
<p class="box">test</p>
The second class means that only div with class box
has that attribute
Only this elements get second class:
<div class="box">test</div>
The selector
before the class specify which type of elements can take this class
这篇关于CSS :: .className和div.className之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文