Forum Moderators: not2easy

Message Too Old, No Replies

css selection, same element both times, adding class refines

css selects element, adding class seems to really refine its selection..

         

broniusm

2:47 pm on Apr 6, 2006 (gmt 0)

10+ Year Member



I thought this was odd. But now that I'm posting, maybe it's the order in which css is applied.

For brevity, let's say my style has a class definition and an ID definition. My HTML has a number of elements with the class, and one element with the ID and the class:


<style>
.icon { float:left; }
#linksbox { float: right; border: solid; }
</style>
<html>
<body>
<div id="linksbox" class="icon">something</div>
<div class="icon">something</div>
<div class="icon">something</div>
<div class="icon">something</div>
</body>
</html>

In this configuration, my #linksbox element does nothing out of the ordinary. However, when I specify #linksbox.icon, then the element floats to the right.

I have observed this in both IE and FireFox. In my understanding, an ID should override the world. Other styles within the #linksbox definition still apply both ways.

Fotiman

3:59 pm on Apr 6, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




In this configuration, my #linksbox element does nothing out of the ordinary. However, when I specify #linksbox.icon, then the element floats to the right.

I'm not sure what you're asking here? In your example, the first block should be floated to the right because of the ID rules. Were you expecting something different?


I have observed this in both IE and FireFox. In my understanding, an ID should override the world. Other styles within the #linksbox definition still apply both ways.

Again, not sure what you're getting at. First, an ID does not necessarily override the world... it depends on the specificity. See the specs:
[w3.org...]

And I don't get what you mean by "still apply both ways". Can you clarify what your question is?

broniusm

4:11 pm on Apr 6, 2006 (gmt 0)

10+ Year Member



the first block should be floated to the right because of the ID rules

Exactly what I would expect, as well. What I'm observing, however, is that all styles other than float were applied (in this example, only border) as if the float in .icon was not getting overridden. But if instead of #linksbox I wrote #linksbox.icon, then everything floats as expected.

I can see how I've confused you, however: I executed my sample code just now, and it executes perfectly as expected. I suspect there must be something else with my actual rules and document structure that I'm overlooking. If I narrow it down, I'll share it in a followup.

(My actual document structre is more complex, with a container shell with some text-align's and what-not.)

thanks

Fotiman

4:14 pm on Apr 6, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yeah, I was going to say the example you gave works exactly as expected. :) So it's probably another rule somewhere else over riding it.