• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

CSS Inheritance

 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've looked up CSS Inheritance and cascading but am not finding an answer to my question. Is it possible to define a style that extends another style? For example, say I had a style for some red text. But I need another style with red text and bold. Can I create a style for the red and then cascade that style into the one for bold?

I know that is too simple an example, but that will answer what I am curious about. I also know about using class Selector, but this would be done without using any current HTML elements. Basically, it might look something like:



And then in my HTML



And Some Text would be red and bold.

Thanks.
 
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Gregg,

The short answer is no, you can't do that. Unfortunately that often makes CSS notation rather long-winded as you find yourself repeating things.

When structuring your HTML page to be CSS-friendly I would make a few of recommendations that you may find of use (if you're not doing it already ):
  • Use IDs for the logical sections of your page, e.g. banner, menu-panel, page-body, footer, etc. This makes it easier to apply different styles for the same elements in different sections
  • Try to avoid using classes as much as possible. If you can use a plain HTML element with a section ID qualifier, e.g. #menu-panel a:hover { }, then do so
  • Lastly, watch out for the specificity rules. If your style isn't working and you think it should be, whack it in the style attribute of the tag it's supposed to be acting on. If it doesn't work there, check the syntax. If it does then a more specific style is overriding it, so make it more specific.


  • I know that doesn't solve your problem, but I hope you find it to be some help.

    Jules
     
    author
    Posts: 15385
    6
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    you can apply 2 styles...

    class="rule1 rule2"

    Eric
     
    Time is mother nature's way of keeping everything from happening at once. And this is a tiny ad:
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic