treehouse : what would you like to learn today?
Web Design Web Development iOS Development

LESS: Darken color of parent based on child

  • LESS noob here.

    Here's some fake markup hopefully illustrating what I'm trying to do:

    <row 1 darken(@charcoal, 10%) >
    <container 1 background: charcoal>
    </container 1>
    </row 1>

    <row 2 darken(@lightBlue, 10%)>
    <container 2 background: blue>
    </container 2>
    </row 2>

    <row 3 darken(@red, 10%)>
    <container 3 background: red>
    <container 3>
    </row>


    The element will pull the element's background color and darken it by a certain percentage. It will require the ability to expand out to dozens of colors, otherwise I'd just code them in manually. Plus, this is why I'm using LESS. (See, I'm already trying to convince myself it's worth it.)

    How do I define a series of colors for different elements, then darken each one by the same value?

    ADDED BONUS: It would be amazing if, say was darker than a certain value, then its font color would lighten, invert, become white, whatever.
  • I'm not sure if you can iterate through elements with LESS, but I know SCSS can... check out this CodePen by Chris

    http://codepen.io/chriscoyier/pen/nfpJk

  • Hm, interesting, but I'm not sure that's what I'd need even if LESS does allow for this.