Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS Colors in css

  • This topic is empty.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #40709
    eins
    Member

    if a page contains 10 elements for example
    every element has it’s own color and it’s different each other

    how to write the css to keep it clean..

    i mean i want to know is there any other way than written it like this

    .color1{color:gray;}
    .color2{color:red;}
    .
    .
    .
    .

    #113784
    Paulie_D
    Member

    I know 10 was just an example but if you are using that many…it’s too many.

    Sometimes, though, you just have to go with class names that actually aren’t ‘general’ just to keep things straight.

    If you want that many colors then I would actually do something like:

    .bg-red {
    background:red;
    }

    .bg-green {
    background:green;
    }

    or

    .text-red {
    color:red;
    }

    .text-green {
    color:green;
    }

    #113876
    cnwtx
    Member

    Or even .red, .green, etc.

    #113879
    Paulie_D
    Member

    I considered

    .red

    but it’s too generic.

    What properties would you assign to it?

    If you do

    .red {
    background:red;
    color:red;
    }

    you can’t use it for

    p .red

    because it would change the bg color too?

    #113918
    TreeRoot
    Participant

    Just an idea. You may want to use class names that denote emotion rather than colors:

    .anger {
    color: red;
    }
    .envy {
    color: green;
    }
    .sunny {
    color: yellow;
    }
    .sad {
    color: gray;
    }
    .bruised {
    color: navy;
    }
    .embarrased {
    color: pink;
    }

    I know, kinda silly, but if you’re feeling icky about hard-coding color class names into your HTML, this could be an escape hatch.

    #113920
    Paulie_D
    Member

    He wanted to know about how to keep his CSS clean…giving them names like than color1, green or apple won’t help because although it’s descritive (or not in the case of color1) it’s not informative about WHAT it does.

    .red

    means nothing by itself but xxx-red does, if you see what I mean.

    .bg-red, bg-angry
    .border-red, .border-angry
    .text-red, .text-angry

    These do…and are ‘cleaner’, it seem to me at least.

    Whatever, 10 is too many. :)

    #114164
    eins
    Member

    i know 10 is too many.. but it’s just an example..
    by the way, thanks for the help :)

Viewing 7 posts - 1 through 7 (of 7 total)
  • The forum ‘CSS’ is closed to new topics and replies.