CSS Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignCSS Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 30th, 2002, 11:30 AM
cpv204 cpv204 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2002
Location: NYC
Posts: 29 cpv204 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 36 m 39 sec
Reputation Power: 0
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:
 a {font-size 12pxcolor black;}
a.small {font-size 10pxcolor red;} 

In my HTML file I have the following link:
PHP Code:
<span class="small"><a href="foo.php">LINK</a></span


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:
<a href="foo.php" class="small">LINK</a
everything works fine. I get 10px and red text.

Why doesn't using a <span> or <div> tag around an <a> tag work like I think it should?

Reply With Quote
  #2  
Old September 30th, 2002, 12:28 PM
degsy degsy is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Nov 2001
Posts: 1,882 degsy User rank is Sergeant (500 - 2000 Reputation Level)degsy User rank is Sergeant (500 - 2000 Reputation Level)degsy User rank is Sergeant (500 - 2000 Reputation Level)degsy User rank is Sergeant (500 - 2000 Reputation Level)degsy User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 5 Days 21 h 19 m 30 sec
Reputation Power: 18
<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.

Reply With Quote
  #3  
Old September 30th, 2002, 02:06 PM
cpv204 cpv204 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2002
Location: NYC
Posts: 29 cpv204 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 36 m 39 sec
Reputation Power: 0
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:
.red {color redfont-family Verdana;}
{text-size 12px;}
{text-size 12px;} 


If I use
PHP Code:
<span class="red">Here is some sample text</span
I get red, Verdana text in the browser default size. Good.

If I use
PHP Code:
<span class="red"><b>Here is some sample text</b></span
I get red, bold, 12px, Verdana text. Also good. Here the span affected the text within the <b> tags.

If I use
PHP Code:
<span class="red"><a href="foo.php">Here is some sample text</a></span
I get blue (default link color), 12px, Verdana text. Not good. The span did change the font, but not the color within the <a> tags. Why not?

Reply With Quote
  #4  
Old September 30th, 2002, 02:14 PM
bricker42 bricker42 is offline
Moderator =(8^(|)
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2002
Location: Sacramento, CA
Posts: 1,710 bricker42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 38 sec
Reputation Power: 13
Send a message via AIM to bricker42
You can use
Code:
span.small a {font-size : 10px; color : red;}
to get the effect you want.

The a tag has some implicit properties assigned to that you have to override. Things like color and text-decoration.

Reply With Quote
  #5  
Old September 30th, 2002, 02:30 PM
cpv204 cpv204 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2002
Location: NYC
Posts: 29 cpv204 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 36 m 39 sec
Reputation Power: 0
Aha! I like it, very subtle. It works.

Reply With Quote
  #6  
Old September 30th, 2002, 02:39 PM
MJEggertson MJEggertson is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2002
Location: Seattle WA
Posts: 863 MJEggertson User rank is Corporal (100 - 500 Reputation Level)MJEggertson User rank is Corporal (100 - 500 Reputation Level)MJEggertson User rank is Corporal (100 - 500 Reputation Level)MJEggertson User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 22 sec
Reputation Power: 13
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.

Reply With Quote
  #7  
Old October 1st, 2002, 05:10 PM
InOblivion InOblivion is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: Norway
Posts: 34 InOblivion User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 11
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>

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignCSS Help > seemingly simple CSS span, div, problem

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap