SitePoint Sponsor

User Tag List

Results 1 to 21 of 21
  1. #1
    SitePoint Enthusiast mike7896's Avatar
    Join Date
    Jun 2004
    Location
    New Bedford, MA
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    <P> Class not applying color to <A> element

    This is probably some kind of very basic CSS knowledge that I am just clueless on.

    I use classes to define font color and and size for different paragrahs. Like if I want 14pt navy blue text, 12pt red, whatever. So typically I will write code like this:

    Code:
    <p class="navy14">This is my 14pt navy blue text <a href="http://www.example.com"> I want to put a link here with the same color</a></p>
    The link always shows up in the default blue we are used to seeing on most browsers. I always have to put <a class="navy14"... to get the link color to match the paragraph it is contained in.

    My CSS is this:

    Code:
    .navy14 {
    	FONT-SIZE: 14pt; COLOR: #0A0593; margin-bottom: 0px; margin-top: 0px;
    }
    What am I doing wrong? I want the link to automatically get the color of whatever paragraph it is contained in.

  2. #2
    SitePoint Enthusiast
    Join Date
    Jun 2006
    Location
    Utrecht (Netherlands, the)
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this:

    Code:
    a { color: inherit; }
    Hippopotomonstrosesquippedaliophobia - Fear of long words

  3. #3
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It won't work, because there will be a User Agent Style Sheet (i.e., the built-in default style in the browser) that is more specific than your rule.

    In compliant browsers, you can achieve it like this:
    Code:
    .navy14 a {background:transparent; color:inherit}
    IE won't play ball, since it doesn't understand the inherit keyword. You can do it like this instead:
    Code:
    .navy 14, .navy14 a {color:#0a0593}
    .navy14 {...the other rules for that class...}
    (BTW, 'navy14' is not the greatest class name you could choose. What if you decide to redesign and want to make those elements have maroon text instead? A friendly hint is to use more semantic class names, that indicate what those elements are rather than how they look.)
    Birnam wood is come to Dunsinane

  4. #4
    SitePoint Enthusiast mike7896's Avatar
    Join Date
    Jun 2004
    Location
    New Bedford, MA
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks.

    Yep as you said, inherit didn't work in IE, so I used
    Code:
    .navy 14, .navy14 a {color:#0a0593}
    And it worked just fine.
    Quote Originally Posted by AutisticCuckoo
    (BTW, 'navy14' is not the greatest class name you could choose. What if you decide to redesign and want to make those elements have maroon text instead? A friendly hint is to use more semantic class names, that indicate what those elements are rather than how they look.)
    Yeah, I considered that, but my site isn't very big so I figure I'd just use a find and replace tool if I ever want to change color schemes. It was just easier for me to do it that way when I was first learning CSS.

    Thanks!

    -Mike

  5. #5
    Non-Member
    Join Date
    Jul 2005
    Posts
    606
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    (BTW, 'navy14' is not the greatest class name you could choose. What if you decide to redesign and want to make those elements have maroon text instead? A friendly hint is to use more semantic class names, that indicate what those elements are rather than how they look.)
    Don't be such a snob. There is nothing wrong with that name.

  6. #6
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not a snob. I presented a valid argument for why 'navy14' is not a good choice for a class name.

    If you don't understand why it's not so good, I guess you don't have much experience of web site maintenance.
    Birnam wood is come to Dunsinane

  7. #7
    Non-Member
    Join Date
    Jul 2005
    Posts
    606
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes no experience at all - I've only worked with Converse, Oakley, Microsoft, O2, the British government etc. etc..

    Anyone moaning about non-semantic names are part off this poofy new-guard group that think everyone has to follow the same rules - it's construct and its utter balls. If it works that is all that matters.

  8. #8
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please re-read the part that you quoted. It was a friendly hint, based on my personal experience, meant to possibly help someone avoid creating a maintenance problem further on. It was not 'moaning'. It was not about 'rules'.

    If you think it's OK to edit a large number of files to change class names when you redesign, it's up to you. Separating structure from presentation is considered best practice by most experienced designers/developers, but it's not the law.

    If you think it's OK to have a class named 'navy14' for maroon text, that's up to you, too. I just hope I'll never have to maintain or redesign one of your sites.
    Birnam wood is come to Dunsinane

  9. #9
    Non-Member
    Join Date
    Jul 2005
    Posts
    606
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm better than you. Fact.

  10. #10
    SitePoint Enthusiast
    Join Date
    Jun 2006
    Location
    Utrecht (Netherlands, the)
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Bob Carologees
    If it works that is all that matters.
    Let me guess. This is something you learned while working for MS?

    I agree with AutisticCuckoo, you should always try to keep your code as maintainable as possible, especially when working for big companies like you just mentioned. People come and go, but development continues. You could save someone hours of work (which will cost extra money) simply by using consistent code. But of course that's not your problem anymore once you're gone, right?
    Hippopotomonstrosesquippedaliophobia - Fear of long words

  11. #11
    Non-Member
    Join Date
    Jul 2005
    Posts
    606
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But of course that's not your problem anymore once you're gone, right?
    Exactly. Web development is all about money at the end of the day - if you forget that you will never be succesful. As long as you get the job done and get your money - the performance of the business is irrelevant as it's no longer your problem.

  12. #12
    Non-Member
    Join Date
    Jan 2005
    Location
    Netherlands
    Posts
    4,300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello

    You are maybe in the money side, others are here for the fun of helping the best they can, its just HTML + CSS nothing to get in Trouble about

  13. #13
    SitePoint Addict
    Join Date
    Mar 2005
    Location
    Toronto
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Bob Carologees
    Exactly. Web development is all about money at the end of the day - if you forget that you will never be succesful. As long as you get the job done and get your money - the performance of the business is irrelevant as it's no longer your problem.
    I would like to help fix your pipe hole with a tiny piece of tape to hold it for a day for $100, what do you say?

  14. #14
    Non-Member
    Join Date
    Jul 2005
    Posts
    606
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would like to help fix your pipe hole with a tiny piece of tape to hold it for a day for $100, what do you say?
    If it holds it for a day, you get your money and a good reference before it breaks then in my mind you've done a smart business deal. The world is cut-throat, NO-ONE is your friend don't forget that.

  15. #15
    Non-Member
    Join Date
    Jan 2005
    Location
    Netherlands
    Posts
    4,300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Bob Carologees
    NO-ONE is your friend don't forget that.
    Hallo

    Zoals de waard is, vertrouwt hij zijn gasten

  16. #16
    Non-Member
    Join Date
    Jul 2005
    Posts
    606
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yep - respond in a language I clearly don't (nor want) to understand - very clever.

  17. #17
    SitePoint Addict
    Join Date
    Mar 2005
    Location
    Toronto
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Bob Carologees
    If it holds it for a day, you get your money and a good reference before it breaks then in my mind you've done a smart business deal. The world is cut-throat, NO-ONE is your friend don't forget that.
    Imagine if you are saying this to a teenager, how would you think this would affect their view of this world...and do you really believe in that?

  18. #18
    Non-Member
    Join Date
    Jan 2005
    Location
    Netherlands
    Posts
    4,300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Bob Carologees
    Yep - respond in a language I clearly don't (nor want) to understand - very clever.
    Hello

    Google

    http://forum.wordreference.com/showthread.php?t=175474

  19. #19
    Non-Member
    Join Date
    Jul 2005
    Posts
    606
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What does it make a difference what age the person is? It's the truth. The human race is a virus with shoes and the only purpose of our lives is to evolve and pro-create (unfortunately - go abortion!) evolution is all about survival of the fittest, the fittest in the business world are those who can make the most money with the smallest outlays.

    Anyway this is straying wildly from the original point that people who pussy-foot around worrying about semantics are the same people that go to cult group events and worship imaginary figures in the sky.

  20. #20
    Non-Member
    Join Date
    Jul 2005
    Posts
    606
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the extent to which the innkeeper trusts his guests reflects more on his own trustworthiness than on that of his guests.
    How profound. Not. Also it makes no sense, it's quite plausible that someone could be very trustworthy but realise that they are few and far between and therefore not trust anyone else.

  21. #21
    Night Elf silver trophybronze trophy Varelse's Avatar
    Join Date
    Mar 2005
    Location
    eu
    Posts
    5,967
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    The discussion went too far off-topic.
    It's a bit strange how a friendly tip can be replied with ironic comment. Please try to avoid it.

    Thread closed.
    FreelanceDaddy - freelancer's personal advisor
    █ Guide and advice for freelancers starting their career
    █ Over 1000 projects posted on freelance markets every day
    █ One-stop resource for online freelancing


Bookmarks

Posting Permissions

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