Author Topic: CSS Class Color  (Read 551 times)

Offline CygnusX

  • Level 24
  • *
  • Posts: 303
  • Reputation: +3/-2
    • View Profile
    • Lords of Midnight
CSS Class Color
« on: December 23, 2010, 09:52:42 AM »
I have a bit of CSS code that defines a basic color.  Something similar to:

.blue { color: #000099; }


Is there a way to reference this in a later part of my stylesheet?  I want to do something similar to:

#content .military .A1 { inherit .blue }

I'm sure there is something simple I missed along the way. 


Offline JGadrow

  • Level 35
  • **
  • Posts: 1,133
  • Reputation: +23/-2
    • View Profile
Re: CSS Class Color
« Reply #1 on: December 23, 2010, 11:12:39 AM »
Unless something new is in CSS3, you can't inherit styles from another selector. However you CAN include multiple classes on an element. Thus if you element was defined as:

Code: (html) [Select]
<div id="content">
    <div class="military">
        <a class="A1 blue">Text</a>
    </div>
</div>

Then it would benefit from both sets of classes. However, if the more specific rule contains a different value for a property declared in the less-specific selector, the more specific selector's value would override the less-specific one.

*Edit - minor grammar correction.
« Last Edit: December 23, 2010, 11:14:14 AM by JGadrow »
Idiocy - Never underestimate the power of stupid people in large groups.


Offline Harkins

  • Level 28
  • **
  • Posts: 424
  • Reputation: +11/-2
  • Coder, blogger, entrepreneur.
    • View Profile
    • Push CX - Blog
Re: CSS Class Color
« Reply #2 on: December 23, 2010, 11:53:09 AM »
CSS doesn't have a method for inheriting or including other bits of style. Either use multiple classes like JGadrow explained or use a higher-level language that compiles down to CSS like Sass.

Visit #bbg on irc.freenode.net to talk browser games anytime.

Offline Nox

  • Level 35
  • **
  • Posts: 767
  • Reputation: +12/-2
    • View Profile
Re: CSS Class Color
« Reply #3 on: December 23, 2010, 11:54:55 AM »
Maybe more used recently is LessCSS (or it's implementation variant LessPHP)
Meet us at an IRC irc.freenode.net #bbg as well
https://vimeo.com/36579366 (a must-watch) | Join BOINC - no longer a hype, but you can help never the less

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal