Reputation: 1666
I'm trying to get the border around my links to change color with the links. I have it set so a.hover
changes the color slightly and wanted to make it change the border color also. Is it possible to do this using just CSS and HTML?
This is my HTML code:
<h1>
<a class="border" href="http://example.com">Home</a>
<a class="border" href="http://example.com/forum">Forum</a>
</h1>
and this is my CSS:
h1 {
text-align: center;
color:#00F;
}
a:link {
color: #00F;
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #00F;
}
a:hover {
text-decoration: none;
color: #006;
}
a:active {
text-decoration: none;
color: #000;
}
a.border {
border-style: solid;
border-color: #00F;
border-width: 5px;
}
Upvotes: 1
Views: 12169
Reputation: 122
I clean the code:
<h1>
<a href="http://example.com">Home</a>
<a href="http://example.com/forum">Forum</a>
</h1>
h1 {
text-align: center;
color:#00F;
}
a:link, a:visited {
color: #00F;
text-decoration: none;
border: 5px solid #00F;
}
a:hover {
text-decoration: none;
color: #006;
border: 5px solid #006;
}
a:active {
text-decoration: none;
color: #000;
border: 5px solid #000;
}
Use Border and I've delete class in tag html.
Upvotes: 3
Reputation: 11597
The only thing you need is this:
a.border:hover {
border-color: red;
}
The other styles are already inherited.
Upvotes: 2
Reputation: 1395
a.border:hover{
border-color: #006; /*Or whatever*/
}
I'd advise reading up on http://coding.smashingmagazine.com/2007/07/27/css-specificity-things-you-should-know/
Upvotes: 1
Reputation: 1433
You're looking to add border: 5px solid #000000;
inside your a:hover{}
I think
border
class on your <a>
tag or add the above inside a.border:hover{}
- read the comments for an explanation.Upvotes: 2
Reputation: 16922
You are looking for the css property "border". The following code will add a border when you hover:
a.border:hover {
text-decoration: none;
color: #006;
border-style: solid;
border-color: red;
border-width: 5px;
}
Your a.border was more specific than your a:hover selecter. Therefore you wouldn't see a border.
JS fiddle: http://jsfiddle.net/vJ2fJ/2/
Upvotes: 2
Reputation: 417
Use the ":hover" pseudo selector if you want the style to change when the user pass the mouse over your item. Your CSS should be like this:
a:hover {
border:5px solid #00F;
}
When you hover any link you'll se the effect.
Upvotes: 1