I am trying to format a reply button:
.replyBtn {
background-color:#CCC;
color:#333333;
font-weight:bold;
padding:3px;
font-size:12px;
text-decoration:none;
}
.replyBtn:hover {
background-color:#333;
color:#FFFFFF;
font-weight:bold;
padding:3px;
font-size:12px;
text-decoration:none;
}
.replyBtn:link {
background-color:#333;
color:#FFF;
font-weight:bold;
padding:3px;
font-size:12px;
}
.replyBtn:active {
background-color:#CCC;
color:#333333;
font-weight:bold;
padding:3px;
font-size:12px;
}
.replyBtn:visited {
background-color:#CCC;
color:#333333;
font-weight:bold;
padding:3px;
font-size:12px;
}
The background color changes. The only thing that is wrong is that it shows the hyperlink color with the underline(which is something i don't want it to have). also, the color of the text should change to white on hover over...
a:focus
state, too - David Thomas 2012-04-04 20:23
Add a
infront of the class
a.replyBtn:hover
CSS works by order of specificity of the selectors used, and then, if two selectors are equally specific, in order of which came last. Reorder your CSS to:
.replyBtn {
background-color:#CCC;
color:#333333;
font-weight:bold;
padding:3px;
font-size:12px;
text-decoration:none;
}
.replyBtn:link {
background-color:#333;
color:#FFF;
font-weight:bold;
padding:3px;
font-size:12px;
}
.replyBtn:visited {
background-color:#CCC;
color:#333333;
font-weight:bold;
padding:3px;
font-size:12px;
}
.replyBtn:hover {
background-color:#333;
color:#FFFFFF;
font-weight:bold;
padding:3px;
font-size:12px;
text-decoration:none;
}
.replyBtn:active {
background-color:#CCC;
color:#333333;
font-weight:bold;
padding:3px;
font-size:12px;
}
I'll point out that you seem to be styling the .replyBtn
elements with a default and then over-riding those defaults in your .replyBtn:link
styles. I realise you may have other element-types with the same class-name, but you should define the a
/link-specific styles in the .replyBtn:link
, so it forms the defaults for all of those links:
.replyBtn:link {
text-decoration: none;
background-color:#333;
color:#FFF;
font-weight:bold;
padding:3px;
font-size:12px;
}
/* all the other stuff... */
Edited in response to the comment left in the comments, from the OP:
try this: jsfiddle.net/CTxQs.
Well, given that your HTML mark-up is:
<div class="replyBtn"><a href="#btn_comment">Reply</a></div>
Your CSS is wrong. This selector:
.replyBtn:link {
}
Selects an element of class-name replyBtn
that is a link; this is all well and good and would work, if your a
element had the class of .replyBtn
. But it does not; the a
element is a child element of the .replyBtn
div
element. Amend your selectors to the following:
.replyBtn { /* selects the div */
background-color:#CCC;
color:#333333;
font-weight:bold;
padding:3px;
font-size:12px;
text-decoration:none;
}
.replyBtn a:link { /* selects the a that's a child of the div */
background-color:#333;
color:#FFF;
font-weight:bold;
padding:3px;
font-size:12px;
text-decoration:none;
}
.replyBtn a:visited {
background-color:#CCC;
color:#333333;
font-weight:bold;
padding:3px;
font-size:12px;
}
.replyBtn a:hover {
background-color:#333;
color:#FFFFFF;
font-weight:bold;
padding:3px;
font-size:12px;
text-decoration:none;
}
.replyBtn a:active {
background-color:#CCC;
color:#333333;
font-weight:bold;
padding:3px;
font-size:12px;
}
Further reading, from Eric Meyer:
.element:link
gives a default to all links with the class-name of element
. Unless those styles are overridden elsewhere (by !important
, or by a more specific selector) - David Thomas 2012-04-04 20:30
a
and not just the div
http://jsfiddle.net/CTxQs/8/ Though I really know little about html and css it looked to work for me - Danny 2012-04-04 20:42
hr
is what you need. Follow through and check out the JS Fiddle demo, too - David Thomas 2012-04-04 20:47
I successfully applied my required behavior as
a:link.replyBtn, a:visited.replyBtn,
a:active.replyBtn, a:hover.replyBtn {...}
On my page, all links are shown as expected i.e. with respect to their css classes. It is working on Chrome but not IE, still working on it... Hope this would help
a:link
,a:visited
,a:hover
,a:active
- David Thomas 2012-04-04 20:20