Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jan 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    CSS class concat

    how do i join 2 classes into a single one?

    like say i've got..

    .strRed { color:red; }
    .bgBlack { background:#000; }

    i want to do something like

    .Combined strRed bgBlack { border:1px solid orange; }

    it will join those 2 classes, and add a border. how do i do that?

  • #2
    Senior Coder ahallicks's Avatar
    Join Date
    May 2006
    Location
    Lancaster, UK
    Posts
    1,134
    Thanks
    1
    Thanked 57 Times in 55 Posts
    You can apply as many classes to one element as you wish:

    <div class="strRed bgBlack">Your div</div>

    So you could create a class for that border, or to simplify it why don't you just create a new one that has all of the style rules you need, rather than using bits and pieces from other styles to build an element that follows a different style set?
    "write it for FireFox then hack it for IE."
    Quote Originally Posted by Mhtml View Post
    Domains are like women - all the good ones are taken unless you want one from some foreign country.
    Reputation is your friend

    Development & SEO Tools

  • #3
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,387
    Thanks
    32
    Thanked 288 Times in 282 Posts
    Quote Originally Posted by Pyrofire View Post
    how do i join 2 classes into a single one?
    To match an element that must have two class names, you would use the code shown below.

    Code:
    .className1.className2 { /* declarations */ }
    Do note that this CSS feature is not supported in Internet Explorer 6. My memory is hazy, but I believe that the above rule would match all elements with .className2, regardless of whether or not they are also in .className1, in that browser.

    Quote Originally Posted by Pyrofire View Post
    like say i've got..

    .strRed { color:red; }
    .bgBlack { background:#000; }
    Presentational class names are bad. If you’re going to do that, you may as well just put the CSS inline with the HTML or not use CSS at all, since you’ll end up having to change both the CSS selector and HTML class attribute every time that you want to change the presentation. Use class names that describe content, not presentation.
    For every complex problem, there is an answer that is clear, simple, and wrong.

  • #4
    New Coder
    Join Date
    Jan 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i very well know i can do it on the html object, but i want to do it in the CSS.

  • #5
    Regular Coder Jutlander's Avatar
    Join Date
    Jun 2007
    Location
    In my own sick little world :P
    Posts
    425
    Thanks
    1
    Thanked 12 Times in 12 Posts
    Join them? Like this or what?

    Code:
    .newclassname {
    color: red;
    background: #000;
    }
    .
    .


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •