weird issue with css and styling links

Joined
12 Feb 2006
Posts
17,384
Location
Surrey
ok just to make sure i'm right with what i'm thinking, styling is cascaded using css, so the latest styling that is set will be the styling that is used?

the problem i some reason have is i styled the .content div link to have padding and background colour but now every single link within the content div takes it's styling from that and not of one that is lower.

bascially what i have.
Code:
<div content>
   <div header>
      <a href="#">something</a>
   </div>
</div>

so i have the content with a rule for what a link should be, but i also have one for header, but the one that rules overall is the content and not header.

any reason it doesn't cascade like it should?

thanks
 
bump in hope someone can answer this?

also while i have this thread, is there any way to limit the amount of characters selected from a database for a specific field? wanting to select only the first 100 or so characters of the description but figured it would be quicker to only select the first 100 characters rather then select the whole description and then display only the first 100 characters.

thanks
 
Last edited:
I believe that if you do not specify a background color, the default color of a div is transparent, and thus the background from the outer div will show through.

As for the padding, the padding will force the inner divs the same as the outer div. I'm not sure what you are trying to achieve here.
 
I believe that if you do not specify a background color, the default color of a div is transparent, and thus the background from the outer div will show through.

but then reset to transparent, or even different colour it still is same as above

As for the padding, the padding will force the inner divs the same as the outer div.
so if i set outer div to 5px padding, then inner div to 10px padding, the outer div will also have 10px instead of the 5px? how come?

I'm not sure what you are trying to achieve here.

im trying to get it so the outer div has one set of rules for everything inside it unless the thing inside it has it's own rule, so in this case every link be red, and when hovered over turn green, but then the header i want to be blue and when hovered over green.

Would have thought this would work fine as the rule is cascading, but it isn't
 
ok just to make sure i'm right with what i'm thinking, styling is cascaded using css, so the latest styling that is set will be the styling that is used?
No, that's not right - the only time that the latest styling is used is when two selectors have the same specificity. All other times, a mind-meltingly complicated set of rules - "specificity", as I've just alluded to - determines which styling declarations take priority.

See here: http://www.smashingmagazine.com/2007/07/27/css-specificity-things-you-should-know/

[...] the problem i some reason have is i styled the .content div link to have padding and background colour but now every single link within the content div takes it's styling from that and not of one that is lower

[...]

so i have the content with a rule for what a link should be, but i also have one for header, but the one that rules overall is the content and not header [...]

As others have pointed out, some declarations are assumed/inherited unless specifically declared. So in this instance you'd have to add {background-color: transparent; padding: 0} to your .header a {...existing declarations...}

If that doesn't solve it, post the relevant CSS so we can have a gander.
 
Last edited:
Back
Top Bottom