|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
How to display two different links in a page?
I want to show in a page two different link styles, to achieve this I have created two css files, one for each link style, and I have attached it in the page thus:
Code:
<html> <head> <title>Link format test</title> <link href="StylesCSS/link1.css" rel="stylesheet" type="text/css"> <link href=" StylesCSS/link2.css" rel="stylesheet" type="text/css"> </head> <body> Then I have applied the styles thus: Code:
<a href="index.aspx" class="letterLink1">Home</a> <a href="forgotten_password.aspx" class="letterLink2">I have forgotten my password</a> And both css files are as follow: link1.css Code:
a:link {
font-family: Arial;
font-size: 12px;
color: #669966;
text-decoration: none;
font-weight: bold;
}
a:hover {
font-family: Arial;
font-size: 12px;
color: #568156;
text-decoration: underline;
font-weight: bold;
}
a:active {
font-family: Arial;
font-size: 12px;
color: #568156;
text-decoration: underline;
font-weight: bold;
}
.letterLink1 {
font-family: Arial;
font-size: 12px;
color: #669966;
text-decoration: none;
font-weight: bold;
}
link2.css Code:
a:link {
font-family: Arial;
font-size: 10px;
color: #669966;
text-decoration: underline;
}
a:hover {
font-family: Arial;
font-size: 10px;
color: #FFCC66;
text-decoration: underline;
}
a:active {
font-family: Arial;
font-size: 10px;
color: #FFCC66;
text-decoration: underline;
}
.letterLink2 {
font-family: Arial;
font-size: 10px;
color: #669966;
text-decoration: underline;
}
But when I load the page, the link1 a:hover and a:active are showed as link2 a:hover and a:active. What is wrong? Thank you, Cesar |
|
#2
|
||||
|
||||
|
what's wrong is you are calling two css files and it's using the last one for the link tags...defining something twice without have a way to tell it which one, you'll have to make a class for each a: you want to use
make one css file and do this in your CSS file Code:
.linkstyleclass1
{
css statments
}
.linkstyleclass2
{
css statments
}
and this in your html: Code:
<a href="my link.html" class="linkstyleclass1">
<a href="my other link.html" class="linkstyleclass2">
that's what that class property is for... |
|
#3
|
|||
|
|||
|
It doesn' t work, I have put it thus:
Type_Links.css file: Code:
.linkGreen1
a:hover
{ font-family: Arial;
font-size: 12px;
color: #568156;
text-decoration: underline;
font-weight: bold;
}
a:active
{ font-family: Arial;
font-size: 12px;
color: #568156;
text-decoration: underline;
font-weight: bold;
}
.linkBlue1
a:hover
{
font-family: Arial;
font-size: 11px;
color: #FF6600;
text-decoration: underline;
}
a:active
{
font-family: Arial;
font-size: 11px;
color: #FF6600;
text-decoration: underline;
}
Then in the html: Code:
<html> <head> <title>Link format test</title> <link href=" StylesCSS/Type_Links.css " rel="stylesheet" type="text/css"> </head> <body> ... <a href="my link.html" class="linkGreen1"></a> <a href="my other link.html" class="linkBlue1"></a> |
|
#4
|
||||
|
||||
|
Ok try this.
in your HTML <style> #linkthing1 { css statments } #linkthing2 { css statments } </style> <a class="linkthing1">link1</a> <a class="linkthing2">link2</a> I'm the laziest person I know, and I'm too lazy too meet others... |
|
#5
|
|||
|
|||
|
I have tried another thing and it works fine, look:
(What do you think?) link1.css file Code:
a.letterLink1
{
font-family: Arial;
font-size: 12px;
color: #669966;
text-decoration: none;
font-weight: bold;
}
a.letterLink1:hover
{ font-family: Arial;
font-size: 12px;
color: #568156;
text-decoration: underline;
font-weight: bold;
}
a.letterLink1:active
{ font-family: Arial;
font-size: 12px;
color: #568156;
text-decoration: underline;
font-weight: bold;
}
a.letterLink2
{
font-family: Arial;
font-size: 11px;
color: #4962A0;
text-decoration: underline;
}
a.letterLink2:hover
{
font-family: Arial;
font-size: 11px;
color: #FF6600;
text-decoration: underline;
}
a.letterLink2:active
{
font-family: Arial;
font-size: 11px;
color: #FF6600;
text-decoration: underline;
}
Then: Code:
<html> <head> <title>Link format test</title> <link href="StylesCSS/link1.css" rel="stylesheet" type="text/css"> </head> <body> Then I have applied the styles thus: Code:
<a href="index.aspx" class="letterLink1">Home</a> <a href="forgotten_password.aspx" class="letterLink2">I have forgotten my password</a> |
|
#6
|
||||
|
||||
|
I didn't know you could do that. I just learned something
![]() By that I mean Code:
element.class:pseudoclass |
|
#7
|
|||
|
|||
|
tidying up
I find you don't need to repeat everything either... only the attributes that are changing (or are specified elsewhere as overall a:link { -styles-} declaration)
So you can have: .letterLink1{ font-family: Arial; font-size: 12px; color: #669966; text-decoration: none; font-weight: bold; } a:hover.letterLink1, a:active.letterLink1 { color: #568156; text-decoration: underline; } .letterLink2{ font-family: Arial; font-size: 11px; color: #4962A0; text-decoration: underline; } a:hover.letterLink2, a:active.letterLink2 { color: #FF6600; } which involves a lot less duplicate typing if you want to change things later on... Mike |
|
#8
|
|||
|
|||
|
Just as a tip, I'm pretty sure the correct syntax is element.class:meta rather than element:meta.class. I wouldn't normally mention such technicalities, but I think it did actually cause my css not to work in one particular browser before I changed.
I tend to do... Code:
.linkclass:link, .linkclass:visited, .linkclass:active, .linkclass:hover {
mainstyles;
}
.linkclass:hover {
justchangedstyles;
}
|
|
#9
|
|||
|
|||
|
Doh! You're right. Sorry!
|
![]() |
| Viewing: Dev Shed Forums > Web Design > CSS Help > How to display two different links in a page? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|