将类选择器与ID组合 [英] Combining a Class selector with an ID

查看:143
本文介绍了将类选择器与ID组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下css:

  / * style.css * / 
#someId {
background-color:red;
}
#someId.medium {
width:300px;
}
#someIdllarge {
width:500px;
}

使用html:

 <! -  medium.html  - > 
< div id =someIdclass =medium> hello,world< / div>

 <! -  large.html  - > 
< div id =someIdclass =large> hello,world< / div>

我知道上面的工作很好在FireFox和Opera,



我的问题是:



上面的CSS是否根据CSS规范(我在哪里可以找到这个具体问题)正确?



什么浏览器(在什么平台上)&不支持此功能?






更新: >
ID是每页唯一的。我试图通过 medium.html large.html 来传达,但显然不够明显。 / p>

更新2:

上面的代码示例只是为了说明我的问题。它不是生产代码的一部分,它并不意味着完整。总之,它只是一个例子来演示一个非常具体的解决方案的问题。

解决方案

quirksmode 有一个表格,其中选择器(除其他外)浏览器支持。不幸的是,没有组合选择器的测试。
,但作为ie6失败多个类,这并不奇怪。



w3c css规格说明如何css选择器应该工作,有一个 DIV.warning E#myid 这不完全像你的,但建议它应该工作(也许它的解释在页面我没有读所有);)


I use the following css:

/* style.css */
#someId {
   background-color: red;
}
#someId.medium {
   width: 300px;
}
#someId.large {
   width: 500px;
}

with the html:

<!-- medium.html -->
<div id="someId" class="medium">hello, world</div>

and

<!-- large.html -->
<div id="someId" class="large">hello, world</div>

I know the above works fine on FireFox and Opera, and, it does not work on IE6 (surprise, surprise).


My questions are:

  Is the above CSS correct according to the CSS-specifications (and where can I find this specific issue)?

  What browsers (on what platform) do & do not support this?


Update:
The IDs are unique per page. I tried to communicate that by having medium.html and large.html but apparently it wasn't obvious enough.

Update 2:
The code example above was just written to illustrate my question. It is not part of production code and it is not meant to be complete. In short, it is just an example to demonstrate a problem with a very specific solution.

解决方案

quirksmode have a table of which selector (among other things) browser supports. unfortunaltly, there is not test for combining selector. but as ie6 fail multiple classes it's not that surprising.

w3c css specification explains how css selector should works, there is a DIV.warningand E#myid which are not exactly like yours but suggest it should work (maybe it's explain in the page I didn't read it all ;) )

这篇关于将类选择器与ID组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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