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 11 of 11
  1. #1
    New to the CF scene
    Join Date
    May 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Can I descend from another css class?

    For example, let's say I have a CSS class called "StandardTable", but I'd like to customize it without changing the original code.

    Can I create a new CSS class which uses everything from StandardTable but allows me to enter new properties, etc.

    Along the same lines, can I modify a class defined in another stylesheet?

    Example: I have a CSS class called "Label" and it makes everything red, bold, and adds a border around it.

    Well, since my HTML already is using this class I don't want to make a new class and then change my HTML. Can I override my old class, but only indicate what I want to change?

    Thanks...

  • #2
    Senior Coder ahallicks's Avatar
    Join Date
    May 2006
    Location
    Lancaster, UK
    Posts
    1,134
    Thanks
    1
    Thanked 57 Times in 55 Posts
    OKay, not understanding this exactly. For the first one, you could just copy the code in StandardTable and call it StandardTable2, edit the lines you want to and then change the classes in the HTML that you want this to apply to to StandardTable2?

    For the second, if you put a style called label in a second stylesheet it would overwrite the first stylesheet as long as you put this second stylesheet AFTER the first in the HTML. So if you had a 'Label' class that you wanted to be blue in your page, and not red you could create a new style sheet, or add an inline style after the style sheet and change the font-color to blue?
    "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
    New to the CF scene
    Join Date
    May 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the reply...

    I understand what you're saying, but I'm trying to adjust a stylesheet without knowing the contents. I also don't want to add another style class to each element in my HTML document.

    Basically, let's say I have an HTML document which I can't change and an existing stylesheet which I can't change (and I can't even read it). However, in my HTML document I can add my own style tags. What I'd like to do is modify a style coming from a different stylesheet.

    I don't think this is possible, but it would allow me to change styles without modify the HTML or existing stylesheet in any way...

  • #4
    Senior Coder koyama's Avatar
    Join Date
    Dec 2006
    Location
    Copenhagen, Denmark
    Posts
    1,246
    Thanks
    1
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by sofakng View Post
    Basically, let's say I have an HTML document which I can't change and an existing stylesheet which I can't change (and I can't even read it).
    You can always read the styles. If the browser can read it so can you.

    Quote Originally Posted by sofakng View Post
    However, in my HTML document I can add my own style tags.
    Do you mean you can add <style type="text/css">...</style>, but you cannot add <link rel="stylesheet" href="..."> ?

    Quote Originally Posted by sofakng View Post
    I don't think this is possible, but it would allow me to change styles without modify the HTML or existing stylesheet in any way...
    I don't see why it shouldn't be possible. Do you have a live example showing what you are trying to do?

  • #5
    New to the CF scene
    Join Date
    May 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok, here's what I'd like to be able to do...

    <-- This is from an external stylesheet -->
    <script>
    .CoolLabel { padding-right: 50px; color: Red; margin-top: 10px }
    </script>

    <-- This is inside my HTML document -->
    <script>
    .CoolLabel { #include_old_CoolLabel; margin-top: 5px }
    </script>

    As you can see, I'm trying to re-define the CoolLabel CSS style and change the margin-top from 10px to 5px...

  • #6
    Senior Coder koyama's Avatar
    Join Date
    Dec 2006
    Location
    Copenhagen, Denmark
    Posts
    1,246
    Thanks
    1
    Thanked 5 Times in 5 Posts
    I think you mean style and not script ? This should do the trick. Or am I wrong?

    <-- This is from an external stylesheet -->
    <style type="text/css">
    .CoolLabel { padding-right: 50px; color: Red; margin-top: 10px }
    </style>

    <-- This is inside my HTML document -->
    <style type="text/css">
    .CoolLabel { margin-top: 5px }
    </style>

  • #7
    New to the CF scene
    Join Date
    May 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You're right, I meant <style> tags, sorry!

    In your example, wouldn't the 2nd CoolLabel CSS tag only have the margin-top 5px property? Wouldn't it lose the padding-right and color properties from the first definition of CoolLabel?

  • #8
    Senior Coder koyama's Avatar
    Join Date
    Dec 2006
    Location
    Copenhagen, Denmark
    Posts
    1,246
    Thanks
    1
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by sofakng View Post
    In your example, wouldn't the 2nd CoolLabel CSS tag only have the margin-top 5px property? Wouldn't it lose the padding-right and color properties from the first definition of CoolLabel?
    It wouldn't.

  • #9
    New to the CF scene
    Join Date
    May 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ahhh, so then let's say I had this:

    <style type="text/css">
    .CoolLabel { padding-right: 50px }
    .CoolLabel { margin-top: 10px }
    .CoolLabel { color: red }
    </script>

    You're saying that CoolLabel would have all three properties?

  • #10
    Senior Coder koyama's Avatar
    Join Date
    Dec 2006
    Location
    Copenhagen, Denmark
    Posts
    1,246
    Thanks
    1
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by sofakng View Post
    You're saying that CoolLabel would have all three properties?
    Yes, that is what I am saying.

  • #11
    New to the CF scene
    Join Date
    May 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hmm, I must be doing something else that is causing this not to work for me but I'll figure it out.

    Thanks for the help!!


  •  

    Posting Permissions

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