CSS Selector :not is not overriding css from specified class - css

In my site I have a links with the target="_blank". On some of these links I want the cursor to be a pointer. On links with the class name "inline-link" I want it to be text. I updated the post with my entire CSS page.
However I cannot seem to override the css.
Here is my 'complete' css:
.grouped-link {
cursor: pointer;
}
.slideout-link {
span.show:hover {
color: $darkgrey;
}
}
.section-subtitle a, a.section-subtitle {
color: $darkgrey;
float: right;
text-transform: uppercase;
font-size: 16px;
font-weight: 400;
letter-spacing: 2px;
margin-top: 65px;
text-decoration: none;
border-bottom: 1px solid $darkgrey;
&:hover {
border-color: $midgrey;
color: $midgrey;
text-decoration: none;
}
}
.underline-link {
border-bottom: 1px solid $lightgrey;
cursor: pointer;
padding-bottom: 5px;
text-transform: uppercase;
width: 150px;
&.dark {
border-color: $grey;
color: $grey;
}
&:hover {
border-color: $midgrey;
color: $midgrey;
text-decoration: none;
}
&.light {
border-color: $upmidgrey;
color: $upmidgrey;
}
&.lightest {
color: $lightgrey;
}
}
.inline-link {
color: $grey;
cursor: text;
&:hover {
text-decoration: none;
cursor: text;
}
}
a[target="_blank"]:not(.inline-link):hover {
text-decoration: none;
cursor: pointer;
}
Here is my html:
<p> Text text text <a className="inline-link" href="http://www.link.com" target="_blank">text</a> text </p>

Unless you use React or some other system that require you to use className instead of class, basically this code works:
.inline-link {
color: grey;
cursor: text;
}
.inline-link:hover {
text-decoration: none;
cursor: text;
}
a[target="_blank"]:not(.inline-link):hover {
text-decoration: none;
cursor: pointer;
}
<p> Text text text <a class="inline-link" href="http://www.link.com" target="_blank">text</a> text </p>
<p> Text text text text text </p>

Related

CSS priority messed up

For proper CSS priority setting, I searched around a bit and found nothing similar of sort. I vaguely remember someone posting about CSS priority in the comments,a long time ago, but I do not recall at all. Hence, I'm asking this question - for one part, to get my answer - and to archive this answer for future reference for others(also inclusive of myself incase this happens again).
Here's my snippet:
.ContainerTitle {
background: #fff;
float: left;
padding: 15px;
padding-left: 15px;
border: solid 1px #000;
font-size: Large;
color: #000;
text-align: left;
cursor: pointer;
transition: all .1s ease-out;
}
.DownloadThis,
.ViewThis {
display: inline-block;
padding: 20px;
padding-bottom: 10px;
border: solid 1px #fff;
width: 40px;
}
/*PROBLEM BELOW HERE HELP!!! */
.showHint {
margin-top: 20px;
background: #f1f1f1;
}
.ViewThis:hover .showHint:after {
content: '*Hint: View Online';
}
.DownloadThis:hover .showHint:after {
content: '*Hint: Download';
}
/*PROBLEM ABOVE HERE HELP!!! */
.DownloadThis {
background: #1D9C73;
color: #fff;
}
.ViewThis {
background: #7D529E;
color: #fff;
}
.DownloadThis:hover,
.ViewThis:hover {
border: solid 1px #000;
background: #fff;
}
.DownloadThis:hover {
color: #1D9C73;
}
.ViewThis:hover {
color: #7D529E;
}
.ContainerTitle:before,
.DownloadThis:before,
.ViewThis:before {
font-family: FontAwesome;
font-style: normal;
font-weight: normal;
text-decoration: inherit;
padding-left: 6px;
padding-right: 8px;
font-size: 32px;
}
.ContainerTitle:before {
content: '\f0f6';
font-size: 24px;
}
.DownloadThis:before {
content: '\f019';
}
.ViewThis:before {
content: '\f06e';
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css" rel="stylesheet" />
<div class="ContainerTitle">SYLLABUS:
<div class="DownloadThis"></div>
<div class="ViewThis"></div>
<div class="showHint"></div>
</div>
<div class="ContainerTitle">NOTE:
<div class="DownloadThis"></div>
<div class="ViewThis"></div>
<p class="showHint"></p>
</div>
I want to show Hint with the help of showHint class when I hover over the desired classes with this code
.ViewThis:hover .showHint:after{content:'*Hint: View Online';}
.DownloadThis:hover .showHint:after{content:'*Hint: Download';}
but, for some reason, it is not working!
I assume it is because I messed up the priority in CSS setting.
I want it to achieve an effect similar to this(but while hovering over .DownloadThis and .ViewThis . If a different generic message appears when I hover over .ContainerTitle that'd be awesome too!):
.ContainerTitle {
background: #fff;
float: left;
padding: 15px;
padding-left: 15px;
border: solid 1px #000;
font-size: Large;
color: #000;
text-align: left;
cursor: pointer;
transition: all .1s ease-out;
}
.DownloadThis,
.ViewThis {
display: inline-block;
padding: 20px;
padding-bottom: 10px;
border: solid 1px #fff;
width: 40px;
}
.showHint {
margin-top: 20px;
background: #f1f1f1;
}
.ContainerTitle:hover .showHint:after {
content: '*Hint: I want to display text like this!';
}
.DownloadThis {
background: #1D9C73;
color: #fff;
}
.ViewThis {
background: #7D529E;
color: #fff;
}
.DownloadThis:hover,
.ViewThis:hover {
border: solid 1px #000;
background: #fff;
}
.DownloadThis:hover {
color: #1D9C73;
}
.ViewThis:hover {
color: #7D529E;
}
.ContainerTitle:before,
.DownloadThis:before,
.ViewThis:before {
font-family: FontAwesome;
font-style: normal;
font-weight: normal;
text-decoration: inherit;
padding-left: 6px;
padding-right: 8px;
font-size: 32px;
}
.ContainerTitle:before {
content: '\f0f6';
font-size: 24px;
}
.DownloadThis:before {
content: '\f019';
}
.ViewThis:before {
content: '\f06e';
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css" rel="stylesheet" />
<div class="ContainerTitle">SYLLABUS:
<div class="DownloadThis"></div>
<div class="ViewThis"></div>
<div class="showHint"></div>
</div>
<div class="ContainerTitle">NOTE:
<div class="DownloadThis"></div>
<div class="ViewThis"></div>
<p class="showHint"></p>
</div>
Also, I would like to know why the hover on .ContainerTitle would work while it fails to work on .DownloadThis and .ViewThis ?
Is the answer related to the fact that both .DownloadThis and .ViewThis are chid of .ContainerTitle? If so how does this type of relation affect containers? I request this information so that I will not repeat the same mistake in the future.
You need the next sibling and general sibling selector for this. Read about it here.
.ContainerTitle {
background: #fff;
float: left;
padding: 15px;
padding-left: 15px;
border: solid 1px #000;
font-size: Large;
color: #000;
text-align: left;
cursor: pointer;
transition: all .1s ease-out;
}
.DownloadThis,
.ViewThis {
display: inline-block;
padding: 20px;
padding-bottom: 10px;
border: solid 1px #fff;
width: 40px;
}
/*PROBLEM BELOW HERE HELP!!! */
.showHint {
margin-top: 20px;
background: #f1f1f1;
}
.ViewThis:hover + .showHint:after {
content: '*Hint: View Online';
}
.DownloadThis:hover ~ .showHint:after {
content: '*Hint: Download';
}
/*PROBLEM ABOVE HERE HELP!!! */
.DownloadThis {
background: #1D9C73;
color: #fff;
}
.ViewThis {
background: #7D529E;
color: #fff;
}
.DownloadThis:hover,
.ViewThis:hover {
border: solid 1px #000;
background: #fff;
}
.DownloadThis:hover {
color: #1D9C73;
}
.ViewThis:hover {
color: #7D529E;
}
.ContainerTitle:before,
.DownloadThis:before,
.ViewThis:before {
font-family: FontAwesome;
font-style: normal;
font-weight: normal;
text-decoration: inherit;
padding-left: 6px;
padding-right: 8px;
font-size: 32px;
}
.ContainerTitle:before {
content: '\f0f6';
font-size: 24px;
}
.DownloadThis:before {
content: '\f019';
}
.ViewThis:before {
content: '\f06e';
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css" rel="stylesheet" />
<div class="ContainerTitle">SYLLABUS:
<div class="DownloadThis"></div>
<div class="ViewThis"></div>
<div class="showHint"></div>
</div>
<div class="ContainerTitle">NOTE:
<div class="DownloadThis"></div>
<div class="ViewThis"></div>
<p class="showHint"></p>
</div>
It isn't working because .showHint is not a descendant of .ViewThis. You need to use the general sibling selector (~):
.ViewThis:hover ~ .showHint:after{content:'*Hint: View Online';}
.DownloadThis:hover ~ .showHint:after{content:'*Hint: Download';}
Example:
.ContainerTitle {
background: #fff;
float: left;
padding: 15px;
padding-left: 15px;
border: solid 1px #000;
font-size: Large;
color: #000;
text-align: left;
cursor: pointer;
transition: all .1s ease-out;
}
.DownloadThis,
.ViewThis {
display: inline-block;
padding: 20px;
padding-bottom: 10px;
border: solid 1px #fff;
width: 40px;
}
/*PROBLEM BELOW HERE HELP!!! */
.showHint {
margin-top: 20px;
background: #f1f1f1;
}
.ViewThis:hover ~ .showHint:after {
content: '*Hint: View Online';
}
.DownloadThis:hover ~ .showHint:after {
content: '*Hint: Download';
}
/*PROBLEM ABOVE HERE HELP!!! */
.DownloadThis {
background: #1D9C73;
color: #fff;
}
.ViewThis {
background: #7D529E;
color: #fff;
}
.DownloadThis:hover,
.ViewThis:hover {
border: solid 1px #000;
background: #fff;
}
.DownloadThis:hover {
color: #1D9C73;
}
.ViewThis:hover {
color: #7D529E;
}
.ContainerTitle:before,
.DownloadThis:before,
.ViewThis:before {
font-family: FontAwesome;
font-style: normal;
font-weight: normal;
text-decoration: inherit;
padding-left: 6px;
padding-right: 8px;
font-size: 32px;
}
.ContainerTitle:before {
content: '\f0f6';
font-size: 24px;
}
.DownloadThis:before {
content: '\f019';
}
.ViewThis:before {
content: '\f06e';
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css" rel="stylesheet" />
<div class="ContainerTitle">SYLLABUS:
<div class="DownloadThis"></div>
<div class="ViewThis"></div>
<div class="showHint"></div>
</div>
<div class="ContainerTitle">NOTE:
<div class="DownloadThis"></div>
<div class="ViewThis"></div>
<p class="showHint"></p>
</div>
It isn't working because .showHint is NOT a child of .DownloadThis or .ViewThis.
Using the tilde (general sibling) selector, this will then select the next (and all) .showHint elements within the scope of .ContainerTitle.
.ViewThis:hover ~ .showHint:after {
content: '*Hint: View Online';
}
.DownloadThis:hover ~ .showHint:after {
content: '*Hint: Download';
}
Check out my demo

LESS formatting

I have been writing some LESS CSS code recently, and was wondering what the best way for format this would be.
Ideally i don't want to reproduce the button classes, and separate them from the input tags, unless that's the best way to go.
.button,
button,
input[type="submit"],
input[type="reset"],
input[type="button"] {
display: inline-block;
height: 38px;
padding: 0 30px;
color: #555;
text-align: center;
font-size: 11px;
font-weight: 600;
line-height: 38px;
letter-spacing: .1rem;
text-transform: uppercase;
text-decoration: none;
white-space: nowrap;
background-color: transparent;
border-radius: 4px;
border: 1px solid #bbb;
cursor: pointer;
box-sizing: border-box;
&:hover,
&:focus {
color: #333;
border-color: #888;
outline: 0;
}
&.button-primary {
color: #FFF;
background-color: #33C3F0;
border-color: #33C3F0;
&:hover,
&:focus {
color: #FFF;
background-color: #1EAEDB;
border-color: #1EAEDB;
}
}
}
I did initially think about doing them like this
.button,
button,
input {
&:[type="submit"],
&:[type="reset"],
&:[type="button"] {}
However doing them like this would mean the button class would also have a type.
Any help would be much appreciated, thanks.
You can solve this by using the extend function in LESS.
button, .button {
// styles
}
input {
&[type="submit"], &[type="reset"], &[type="button"] {
// All styles from .button will also be available here.
&:extend(.button);
}
}

Strange hover behaviour on link on Chrome

I'm experiencing a strange hover behavior on a link inside a list in Chrome.
I've managed to replicate the issue in this jsFiddle copying the whole html and css from the website.
The problem is on the first element of the side menu, which is the link with "Maria Montessori" in it. What happens is that the hover area is like interrupted in the middle, where the text is. It's like there is something covering the middle part of the button. Try it yourself to understand what I mean.
The relative code is this:
<ul class="page-menu">
<li class="page_item page-item-30">Maria Montessori</li>
<li class="page_item page-item-32">La pedagogia scientifica</li>
...
And the css:
.page-menu {
display: inline-block;
margin-right: 25px;
text-align: center;
width: 210px;
li {
margin-bottom: 10px;
}
li.current_page_item {
a {
background-color: $blue-montessori;
border-bottom: 2px solid $blue-montessori;
color: white;
font-weight: bold;
}
}
li.current_page_parent {
a {
background-color: $blue-montessori;
border-bottom: 2px solid $blue-montessori;
color: white;
font-weight: bold;
}
}
a {
background-color: $grey-light;
border-bottom: 2px solid $grey-light;
color: $grey-dark;
display: block;
font-family: Lato;
font-weight: 300;
line-height: 1.2;
padding: 15px 20px;
text-decoration: none;
text-transform: uppercase;
&:hover {
background-color: $blue-light;
border-bottom: 2px solid $blue-dark;
color: white;
font-weight: 400;
}
}
ul.children {
margin-top: 10px;
li {
margin-bottom: 10px;
margin-left: 10px;
}
li a {
background-color: #f9f9f9;
border-bottom: 2px solid #f9f9f9;
color: $grey-dark;
display: block;
font-family: Lato;
font-size: 12px;
font-weight: 400;
line-height: 1.2;
padding: 10px 20px;
text-decoration: none;
text-transform: uppercase;
&:hover {
background-color: $blue-light;
border-bottom: 2px solid $blue-dark;
color: white;
font-weight: 400;
}
}
li.current_page_item {
a {
background-color: $blue-montessori;
border-bottom: 2px solid $blue-montessori;
color: white;
font-weight: bold;
}
}
}
.page_item_has_children > .children {display: none;} /*hides the submenu*/
.page_item_has_children.current_page_item > .children,
.page_item_has_children.current_page_ancestor > .children {display: block;} /*shows the submenu for the current page or when on its subpages */
}
Inspecting it with developer tools didn't really help and what's strange is that the issue appears to be only on the first element. And in Firefox works fine, anyway.
Your div menu-menu-1-container is overlapping to your first menu because of line height property of your div .nav-menu use padding instead
.nav-menu {
padding: 17px; /* remove line-height property */
}
Updated working Code

Having trouble getting multiple styles to work with hover / links etc

I am having issues trying to make some changes to my wife's web site. I have set up multiple classes for different hover over colours etc. Eg. Lft menu all navy text except for underline & light blue with hover over, top menu all white text except for underline & light blue with hover over.
I have tried all sorts of things but can't get them to work together. One keeps overriding the other. Any help would be awesome.
The site is live. www.spunkerella.com
here is the code for the style sheet.
<style type="text/css" >
<!--
* { padding: ; margin: 0; }
body {
font-family: Verdana, Helvetica, sans-serif;
font-size: 13px;
background-color: #17215f;
}
#wrapper {
margin: 30px auto;
width: 900px;
background-color:#ffffff;
border:medium solid #00a9cb;
}
#header {
width: 900px;
float: left;
padding: 0px;
height:250px;
margin: 0px 0px 0px 0px;
background: #ffffff;
}
#leftcolumn {
background: #ffffff;
margin: 0px 0px 0px 0px;
padding: 10px;
width: 180px;
float: left;
}
#rightcolumn {
float: right;
background: #ffffff;
margin: 0px 0px 0px 0px;
padding: 5px;
width: 688px;
display: inline;
}
#footer {
width: 900px;
clear: both;
background: #ffffff;
margin: 0px 0px 0px 0px;
padding: 0px;
}
.style1 {color: #17215f}
.style2 {font-size: xx-small}
a:link {
color: #453223;
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #453223;
}
a:hover {
text-decoration: underline;
color: #453223;
}
a:active {
text-decoration: none;
color: #453223;
}
.style3 {color: #453223; font-weight: bold; }
.lgfont {color: #453223;}
.style4
a:link {
color: #ffffff;
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #ffffff;
}
a:hover {
text-decoration: underline;
color: #00a9cb;
}
a:active {
text-decoration: none;
color: #ffffff;
}
.style5
a:link {
color: #17215f;
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #17215f;
}
a:hover {
text-decoration: underline;
color: #00a9cb;
}
a:active {
text-decoration: none;
color: #17215f;
}
-->
</style>
When you specify multiple styles for the same attribute in CSS (example here: setting the color to two different ones on hover), it can only choose one of them, so the others have to get overridden. Here is a good resource on CSS styling priority:
http://www.w3.org/wiki/CSS/Training/Priority_level_of_selector
Hope this helps!

Change link color on div hover

How do I change my link colors when I hover a div?
I tried to use:
#voltarTEST {
width: 80px;
height: 62px;
padding-top: 16px;
background-image: url(../img/multiLangImage/Seta11.png);
background-repeat: no-repeat;
}
#seguinteBtn {
width: 80px;
height: 62px;
padding-top: 16px;
background-image: url(../img/multiLangImage/Seta21.png);
background-repeat: no-repeat;
text-decoration: none;
color: #777;
}
#seguinteBtn:hover {
background-image: url(../img/multiLangImage/Seta22.png);
background-repeat: no-repeat;
text-decoration: none;
color: #FFF;
}
#voltarText {
/* padding-right: 10px;*/
padding-left: 30px;
}
#voltarNEText {
/* padding-right: 10px;*/
padding-left: 30px;
}
#voltarTEST:hover {
background-image: url(../img/multiLangImage/Seta12.png);
background-repeat: no-repeat;
}
#voltarTEST a {
text-decoration: none;
font-size: x-small;
font-family: Verdana;
text-decoration: none;
color: #999;
}
#voltarTEST a:hover {
text-decoration: none;
font-size: x-small;
font-family: Verdana;
text-decoration: none;
color: #FFF;
}
#dataUltimaSincMSG {
margin-bottom: 0;
}
#estadoSinc {
margin-bottom: 0;
}
But that did not work, this only changes color when I hover over the link.
Add this:
#voltarTEST:hover a{
text-decoration: none;
font-size: x-small;
font-family: Verdana;
text-decoration: none;
color:#FFF;
}
You want to set the hover event on the div, not the link..
#voltarTEST a:hover should be #voltarTEST:hover a
The first (the way you had it) says when the link inside of the voltarTEST div is hovered on. The second says apply this style to links inside voltarTEST when voltarTEST is hovered on.
Here's a DEMO
Use the :hover on the div instead of the a :
#voltarTEST:hover a{
text-decoration: none;
font-size: x-small;
font-family: Verdana;
text-decoration: none;
color:#FFF;
}

Resources