在CSS中使用.Class或#ElementId有什么区别? [英] Whats the difference between using .Class or #ElementId in CSS?

查看:262
本文介绍了在CSS中使用.Class或#ElementId有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在想...在创建一个样式类和应用它一个元素之间,或者创建一个样式与#elementId符号(除了能够分配一个类到不同的元素)之间有什么区别? / p>

例如...

 #div1 
{
background-color:Yellow;
}

< div id =div1>
Hello world!
< / div>

  .div1 
{
background-color:Yellow;
}

< div class =div1>
Hello world!
< / div>

谢谢! :)

解决方案

ID 在文档中必须是唯一的。 课程可以任意数量和组合使用。因此,您可以在一个元素上对多个元素和多个类使用一个类。


Ive been wondering... in CSS are there any differences between creating a style class and applying it an element, or creating a style with the #elementId notation (apart from being able to assign a class to different elements)?

For example...

#div1
{
 background-color: Yellow;
}

<div id="div1">
    Hello world!
</div>

Or

.div1
{
 background-color: Yellow;
}

<div class="div1">
    Hello world!
</div>

Thanks! :)

解决方案

An ID must be unique in a document. Classes can be used in any number and combination. So you can use one class on multiple elements and multiple classes on one element.

这篇关于在CSS中使用.Class或#ElementId有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆