我可以在CSS中一起使用DIV类和ID吗? [英] Can I use DIV class and ID together in CSS?

查看:84
本文介绍了我可以在CSS中一起使用DIV类和ID吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在CSS中一起使用DIV类和ID吗?
例如:

 < div class =xid =y> 
-
< / div>


解决方案

是的,可以。

  #yx {
/ *将选择id =y的元素,也具有class =x* /
}

同样地:

  .x#y {
/ *将选择同样具有id =y的元素class =x* /
}
id
在文档中是唯一的。但是,如果您使用类进行用户互动,则 有用。


Can I use DIV Class and ID together in CSS? For example:

<div class="x" id="y">
    --
</div>

解决方案

Yes, yes you can.

#y.x {
 /* will select element of id="y" that also has class="x" */
}

Similarly:

.x#y {
 /* will select elements of class="x" that also have an id="y" */
}

Incidentally this might be useful in some use cases (wherein classes are used to represent some form of event or interaction), but for the most part it's not necessarily that useful, since ids are unique in the document anyway. But if you're using classes for user-interaction then it can be useful to know.

这篇关于我可以在CSS中一起使用DIV类和ID吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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