www.webdeveloper.com
Results 1 to 6 of 6

Thread: Is it possible to create a style rule for an element w/ 2 classes

  1. #1
    Join Date
    Mar 2010
    Posts
    281

    Is it possible to create a style rule for an element w/ 2 classes

    Seems like i should know this..

    i have an element like this
    PHP Code:
    <span class="one two">Text here</span
    am trying to access. i tried this but didn't work

    PHP Code:
    .one .two {
    font-size:32px;
    color:red'


  2. #2
    Join Date
    Mar 2011
    Posts
    1,139
    No, you can't specify a rule for elements with two specific classes. You could use the CSS you posted if you changed the HTML to:
    Code:
    <span class="one"><span class="two">Text here</span></span>
    But generally, it would probably be best to simply define another class entirely to keep the mark-up cleaner and easier to maintain.
    Rick Trethewey
    Rainbo Design

  3. #3
    Join Date
    Mar 2010
    Posts
    281
    thank you very much,

    really good to know, thanks

  4. #4
    Join Date
    Aug 2012
    Posts
    155
    Yes you can apply more than one class to a div but only if the 2 classes have different style properties.

    in your code, for example
    Code:
    .one .two { 
    font-size:32px; 
    color:red;
    }
    Means that you want two classes with the same formatting (not sure why as classes can be re-used as many times as you like in a page unless each class has other styling separately within your CSS) and you are then applying both to your html which is completely unnecessary, however
    Code:
    .one { 
    font-size:32px; 
    color:red;
    }
    .two {
    font-weight: bold;
    }
    Means you are setting two different classes which have different properties and then you may need to apply both to your span as you have done.

  5. #5
    Join Date
    May 2005
    Location
    Gold Coast (MS)
    Posts
    2,211
    You actually can have as many class rules as you wish as long as they are different and separated by spaces, i.e. class="one two third four". Suggest you limited the number of classes used for an element though. Might use CSS Lint Cleaner. Also...

    CSS Formatter and Optimiser

    The Greatest tool for sorting CSS properties in specific order

  6. #6
    Join Date
    Nov 2012
    Location
    France
    Posts
    4
    Thank you for another fantastic post. Where else could anybody get that kind of info in such an ideal way of writing? I have a presentation next week, and I'm on the look for such information. wish you luck

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles