I have a link, where I want to change the color of the text away from the color that I set for hyperlinks. My code is:
<span class="button"><%= link_to "Create new scenario", :action => "create" %></span>
And my CSS is:
a:link {
color:rgb(50%, 15%, 5%);
text-decoration:none;
}
.button {
-moz-border-radius-bottomleft:6px;
-moz-border-radius-bottomright:6px;
-moz-border-radius-topleft:6px;
-moz-border-radius-topright:6px;
background-color:rgb(93%, 93%, 93%);
border:1px solid black;
color:black !important;
line-height:1.9;
margin:0 3px 3px 0;
padding:4px 8px 4px 3px;
text-decoration:none;
}
For some reason the hyperlink text is still brown, rgb(50%, 15%, 5%).
Change your css to use the .button class and anchors with a parent css class of .button. as shown below:
.button,.button a:link {
-moz-border-radius-bottomleft:6px;
-moz-border-radius-bottomright:6px;
-moz-border-radius-topleft:6px;
-moz-border-radius-topright:6px;
background-color:rgb(93%, 93%, 93%);
border:1px solid black;
color:black !important;
line-height:1.9;
margin:0 3px 3px 0;
padding:4px 8px 4px 3px;
text-decoration:none;
}
EDIT: Keep in mind that this causes the border to repeat and makes the hyperlink show up without an underline because of text-decoration:none. The best practice in this case is to have a separate css declarations.
.button {....}
.button a:link {.....}
I think it's because of the specificity; the span (.button) is less specific to the link than the a:link so the a:link styles are being applied (correctly according to the spec: http://www.w3.org/TR/CSS2/cascade.html).
If you want to override the a:link styles for this one button (or...well, any other in the same way) add the class to the <a> tag rather than its parent element.
Though you might get away with:
.button > a:link {/* styles */}
Which should become specific since this one <a> is the descendant of the the span of class .button.
Edit:
It's worth pointing out that the '>' selector applies only to immediate descendants, so an a inside an element of class .button would be affected, however an a inside a div in turn inside an element of class .button would not be affected.
Also this selector is not supported by IE (certainly below version 7, and I don't know about version 7 -or, indeed, version 8). It might be okay to use, instead, the '*' operator:
.button * a:link {/* styles */}
bearing in mind that while this is supported -I think- in IE after version 5.x at least, it's a little broad in that it will target all as within an element of class .button, regardless of any interim elements, and will still likely be less-specific than any rule applied to a:links.
You could make a css style .button a:link {color: black;}
"! important" is not for forcing child's style. It's for the user to override styles assigned by webpage author. It has no use in your case.
The proper way to do it is:
.button {
-moz-border-radius-bottomleft:6px;
-moz-border-radius-bottomright:6px;
-moz-border-radius-topleft:6px;
-moz-border-radius-topright:6px;
background-color:rgb(93%, 93%, 93%);
border:1px solid black;
color:black;
line-height:1.9;
margin:0 3px 3px 0;
padding:4px 8px 4px 3px;
text-decoration:none;
}
.button a {
color:black;
}
Remarks:
".button > a" is a good idea but it won't work in IE6. Therefore one should use ".button a" here to be safe.
Putting ".button" and ".button a" together in one set of style will make the button border repeat itself.
Related
so I have my menu at the top and I would like the link for "Contact Us" to be white.
I've assigned it a custom class and this is what I added so far:
.cta-button {
border: 2px solid red;
border-radius: 15px;
padding: 5px;
background-color: red;
top: -6px;
color: #ffffff !important;
transition: all .3s 0s;
}
.cta-button a:link, a:visited, a:active {
padding: 0px !important;
color: #ffffff !important;
}
Here it is live:
https://kkat.mavenpromedia.com/
As you can see I added the "important" but the link is still black and pulling from the link styles in the header module itself rather than my added code for that one link.
Thank you
There are 2 issues here:
the color of the link is not set at the <li> level (where you've added the class) but at the <a> level. You need to set the property color under the selector .cta-button > a
The default color is already being set using !important (bad practice) so not only you must use !important as well but you also need to match the level of specificity . The best way to do that is to copy/paste the selector used in the template and add your custom class, like so
.et_pb_menu_0_tb_header.et_pb_menu ul li.cta-button a {
color: white !important;
}
of course you need to do the same for :active, :visited,…
Try adding color like this -
.et_pb_menu_0_tb_header.et_pb_menu ul li.cta-button a {
color: #fff !important;
}
.et_pb_menu_0_tb_header.et_pb_menu ul li.cta-button a:active,
.et_pb_menu_0_tb_header.et_pb_menu ul li.cta-button a:visited{
color: #fff !important;
}
As I can see in the website the link color given already has !important written for it. Now when we have two !important css properties mentioned for same element, then we have to check for the specificity. You can learn about specificity in CSS here : https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity
Another note: Using too many !important to over-ride CSS property is a bad practice.
I'm trying to find a way to remove the hyperlink styles from linked images. Here's what the hyperlinks look like:
Linked Text Example
Here's what a linked image currently looks like:
Linked Image Example
You can see there's a green line going through the background of the image.
I have both my styles for hyperlinks and for hyperlinked images separately referenced:
/**** HYPERLINK STYLING ******/
a, a:visited, a:focus {
text-decoration:none;
border-bottom: 2px solid #8dc635;
box-shadow: inset 0 -1px 0 #8dc635;
color: rgba(35, 35, 35, 0.8);
transition: 0.65s;
}
a:hover {
background: #8dc635;
}
/**** Don't style images with border / box-shadow ***/
a img {
border-bottom: none !important;
box-shadow: none !important;
outline : none !important;
background:transparent !important;
}
a img:hover {
border-bottom: none !important;
box-shadow: none !important;
outline : none !important;
background:transparent !important;
}
I've even tried using the !important function (as much as I'd rather not), and tried this:
/******** No color on / in images *********************/
a[href$=".png"] {
background-color: transparent !important;
border-bottom: none !important;
box-shadow: none !important;
}
a[href$=".png"]:hover{
background-color: transparent !important;
border-bottom: none;
box-shadow: none;
}
Nothing has worked. . . I'd rather not have to go in and add a class to every image on the website and I can't think how to make the selector for text hyperlinks more specific without excluding links accidentally. Ideas?
You're probably using the wrong selectors. Take the following example:
home
<a href="contact.html">
<img src="me.png" />
</a>
Now let's see how your CSS applies to them.
The selector a applies to all <a> elements, which in this case includes both the text link and the image link.
The selector a img applies to all <img> elements that are inside <a> elements.
Your CSS is affecting the <img> element and trying to remove its border, outline and shadow; however, the image itself never had any. The decorations you see come from the <a> element that's wrapping the <img> element.
Currently there is no CSS selector that selects elements which have children of a certain type. Here's my suggestion:
a:not(.image-link) {
text-decoration:none;
border-bottom: 2px solid #8dc635;
box-shadow: inset 0 -1px 0 #8dc635;
color: rgba(35, 35, 35, 0.8);
transition: 0.65s;
}
home
<a href="contact.html" class="image-link">
<img src="me.png" />
</a>
The :not() pseudoclass negates the selector inside its parentheses, so a:not(.image-link) will select all <a> elements that do not have the class image-link (in this case, the first one), and apply the decorations to those. Unfortunately, this does leave you with a bit of extra work and responsibility, because you have to make sure all your image links are given the image-link class.
I suppose your problem is an underline below the images? (you didn't really describe your problem...)
In that case, border-bottom is the wrong property, it has to be text-decoration: none
I am creating a set of styles for a dynamic breadcrumb.
Every previous step in the breadcrumb should have a border-bottom and a forward slash. The forward slash is done as a :before.
The problem is when there is a forward slash between two previous step's, there is no gap in the border on the right side.
To explain this problem better, please see this codepen... http://codepen.io/anon/pen/dJEen
I have tried doing a border-bottom:0 on the :before but this does nothing.
My code:
HTML
<div>
<a class="bcrmb" href="">Purchases</a>
<a class="bcrmb" href="">Order </a>
<span class="bcrmb">Delivery</span>
</div>
CSS
.bcrmb {
font-size:24px;
font-weight:bold;
margin: #6px 0;
display:inline-block;
letter-spacing:-1px;
font-family:sans-serif;
}
a.bcrmb {
color:#777;
border-bottom:2px solid #777;
margin-right:3px;
}
span.bcrmb {
color:#333;
}
a.bcrmb + .bcrmb:before {
content:"/";
margin-right:6px;
border-bottom:0;
}
Any help would be greatly appreciated.
You can do that in two ways, either by wrapping the text in a span element and assigning the border-bottom to span else you can use CSS positioning, by using absolute on the :before and relative to a
Demo (Using nested span elements)
Demo (Using CSS Positioning)
a.bcrmb {
color:#777;
border-bottom:3px solid #777;
margin-right:3px;
position: relative;
margin-right: 15px;
}
a.bcrmb + .bcrmb:before {
content:"/";
margin-right:6px;
border-bottom:0;
position: absolute;
left: -10px;
}
Also make sure you use text-decoration: none;, you aren't using that
In addition to Mr. Alien comment,
Using nested <span> is not always an option, because sometimes there is no access to HTML code.
Positioning of absolute element is not a good idea, because it will be hard or impossible to properly position it for different font sizes, font families, styles, or on different devices or screen sizes. Even on the demo link provided, arrow is a bit off on my screen.
So, I would add the third way, by adding a relative to parent (em), negative right margin to pseudo element.
Demo
a {
text-decoration: none;
}
.bcrmb {
font-size:24px;
border-bottom:3px solid #777;
}
.bcrmb:after {
content:">";
padding-left: 4px;
margin-right: -0.75em;
}
This is how the code looks:
And I want to a border for the highlighted element, i.e. <div class="Comment">...</div>, how do I style it using CSS?
NOTE: Notice the class named 'Comment'? It is used in both the highlighted element and it's parent element. So, that's probably why this one's a bit tricky?
I tried the CSS codes below, and some others, and none worked.
.DataList .Item .comment, .DataList .Comment .comment,
.DataList .FirstComment .comment, .DataList .Mine .comment {
border:1px solid #666;
padding:10px;
border-radius:3px;
-moz-border-radius:3px;
-webkit-border-radius:3px;
}
.DataList .Item div.comment, .DataList .Comment div.comment,
.DataList .FirstComment div.comment, .DataList .Mine div.comment {
border:1px solid #666;
padding:10px;
border-radius:3px;
-moz-border-radius:3px;
-webkit-border-radius:3px;
}
What am I doing wrong? Hope someone can help me solve this small riddle. Thanks.
first, try NOT styling with extreme specificity (adding parent/element selectors). this way, you can just use .Comment - note that they ARE case sensitive.
if styles are overridden or you have selectors of the same name but different "context" (like you have a list item with .Comment and it's child with div with .Comment), that's when you use higher specificity (adding the parent/element in the selector) like div.Comment, .Item .Comment
<style>
.btn{
display: inline-block;
padding: 15px 10px;
background: gray;
}
.btn:hover{
background:lightgray;
color:red;
}
</style>
<div class="btn">
text
</div>
works nicely. However if we have that:
<div class="btn">
text
</div>
it wouldn't work exactly as the first one. The anchor's text wouldn't be affected. Okay what if we add to the CSS:
.btn a:hover{
background:lightgray;
color:red;
}
That will work, but only if you hover exactly on the anchor, but still hover on the div rectangle wouldn't affect the anchor's text.
How can I tweak that without any javascript, so both rectangles acted identically?
http://jsfiddle.net/vaNJD/
UPD: adding !important keyword wouldn't help
Because all web browsers set a default color (and text-decoration) for a elements, you need a more specific selector to override the default. Try this instead:
.btn:hover, .btn:hover a {
background:lightgray;
color:red;
}
If you really want the two boxes to be identical, you would also need to override the un-hovered button as well:
.btn a {
color: black;
text-decoration: none;
}
It may also be worth pointing out that IE6 only supports the :hover pseudo-class on a elements. You may want to work around this by setting the a to display: block and adding the background color there.
You can accomplish the same effect by getting rid of the container and applying the .btn class directly to the a element. See the third box in this updated fiddle: http://jsfiddle.net/mlms13/vaNJD/5/
.btn:hover{
background:lightgray;
color:red;
}
.btn:hover a{
color: red;
}
Change to:
.btn:hover,
.btn:hover a{
background:lightgray;
color:red;
}
http://jsfiddle.net/vaNJD/4/
Like this?
.btn:hover a{
color:red;
}
I found one way in which you should set height for div tag and use it again for anchor tag and set anchor's display properties as block
for example
<style>
.divest
{
height:120px;
}
.divest a
{
display:block;
height:120px;
}
</style>
<div class="divest">here is hyperlink text</div>