|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
seemingly simple CSS span, div, problem
I stumbled across this problem modifying someone else's code.
I have a stylesheet with two definitions: PHP Code:
In my HTML file I have the following link: PHP Code:
The problem is that the link is being formatted according to the a{...} definition, that is, 12px and black, not 10 px and red like I want it. The first thing I thought was that a <span> tag is only supposed to contain text, not tags, so I changed it to a <div> tag. Still the same result. If I change my HTML to: PHP Code:
Why doesn't using a <span> or <div> tag around an <a> tag work like I think it should? |
|
#2
|
|||
|
|||
|
<a href="foo.php" class="small">LINK</a>
This is the correct method if you want the link to be affected by the CSS. Elements can be defined in CSS so using a will effect links. using h1 will effect h1 (header) tags. <span class="small"> is not effecting anything, because there is no style called small that can be associated with SPAN tags. span.small or .small would affect just the SPAN tag, but not the link. Hope that makes sense, it's hard to describe briefly. ![]() |
|
#3
|
|||
|
|||
|
Thanks degsy. I understand what you're saying, but am confused about what I thought I knew about the <span> tag. I don't understand why the definitions of the span tag don't apply to the text in the anchor tags enclosed between the span tags.
Say my definitions are PHP Code:
If I use PHP Code:
If I use PHP Code:
If I use PHP Code:
|
|
#4
|
|||
|
|||
|
You can use
Code:
span.small a {font-size : 10px; color : red;}
The a tag has some implicit properties assigned to that you have to override. Things like color and text-decoration. |
|
#5
|
|||
|
|||
|
Aha! I like it, very subtle. It works.
|
|
#6
|
|||
|
|||
|
It must be the way the browser implements default link colors. It likely has a default style implementation for anchors, probably something like this: a{color: blue; text-decoration: underline;}. Unless you explicitly override this, the anchor will appear as dictated by the default style.
Applying the color to the span won't set the anchor color, because the anchor still has the default anchor style set. This is necessary to keep html 'simple.' If anchors inherited colors from their parent elements, something as simple as <body color="red">Click <a href="foo">here</a></body> would wipe out the coloring of the link, since the body's color declaration would propagate through all it's child elements. |
|
#7
|
|||
|
|||
|
cpv204:
This should work using div tags. <style type="text/css"> <!-- #link a { color: red; font-family: verdana, sans-serif; } --> </style> <div id="link"><a href="link.html">a link</a></div> |
![]() |
| Viewing: Dev Shed Forums > Web Design > CSS Help > seemingly simple CSS span, div, problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|