Why this CSS not valid? - css

I have this CSS:
.optionQuiz a:hover{
.Qtick{
background-color: green;
}
}
My HTML:
<div class="optionQuiz">
<a href="#">
<span class="Qtick">1</span>
</a>
</div>
My GOAL:
My Goal is when the user hovers the mouse over the <a> the span with class within the '<a>' to be highlighted.
MY Question:
Why this CSS didn't work? This is indeed good way but seems such thing have not been invented? Why? Should I use JavaScript? I don't want. I want it in CSS way.
Any kind of help is appreciated.

You don't need to use JavaScript. You can solve it with CSS only on a very simple way. See the following snippet:
.optionQuiz a:hover .Qtick {
background-color: green;
}
.optionQuiz a:hover .other1 {
background-color: blue;
}
.optionQuiz a:hover .other2 {
background-color: yellow;
}
<div class="optionQuiz">
<a href="#">
<span class="Qtick">1</span>
<span class="other1">2</span>
<span class="other2">3</span>
</a>
</div>

With plain CSS you can't use nested selectors.
You can do it using a pre-processor like Sass, PostCSS, Less...
If you want to use just CSS you have to use something like this:
a:hover span.Qtick{
color:red;
}
<div class="optionQuiz">
<a href="#">
<span class="Qtick">1</span>
</a>
</div>

Not sure what
.Qtick{
background-color: green;
}
is for...
if you want to change the color
this will do:
.optionQuiz a:hover{
background-color: green;
}
if you want only the span to be highlighter use the following selector:
.optionQuiz a:hover >span.Qtick{
background-color: green;
}

Related

Hiding span under div in CSS

Below is the code for my WP post. I'm trying to hide the span for comment. So that it doesn't appear on the blog post.
<div class="blog-stats">
<span class="clock">
<i class="fa fa-calendar stats-item"></i>
<span class="text-center text-light stats-item">February 15, 2020</span>
</span>
<span class="comment">
<i class="fa fa-comment stats-item"></i>
<span class="text-center text-light stats-item">no comments</span>
</span>
<span class="user">
<i class="fa fa-user stats-item"></i>
<span class="text-content text-light stats-item">Wayne John</span>
</span>
</div>
I tried a few below and it didn't work.
.blog-stats.comment {
display: none;
}
span .comment {
display: none;
}
span.comment {
display: none;
}
Any idea how to fix it?
Add below CSS and try :
<style type="text/css">
.blog-stats .comment span{
display: none !important;
}
</style>
your CSS code is OKAY!
try putting "!important" besides your style and clear your browser cache. maybe fixed.
please put space between classes like
.blog-stats .comment {
display: none;
}
or
.blog-stats .comment {
display: none !important;
}
this will work please try
In case if you don't want to use !important try the below version.
.blog-stats .comment.comment {
display: none;
}
Note: You can increase the .comment class x number of times to get higher precedence.
Example:
.blog-stats .comment.comment.comment {
display: none;
}
Please put this code in your css
.blog-stats span.comment{display: none;}

How can i change a link hover color in laravel 5.2

I want to change hover color in laravel 5.2
I'm try but can't.
Here is my link
<div class="classname">
<h4 align="center" class="well"><b>Course Materials<b></h4>
</div>
Here is my css
div.classname a:hover {
color: green;
}
Try:
.classname a:hover { color: green }
OR
change class to your link
a href="your link" class="classname" >.... < / a >
.classname a:hover { color: green }
I hope it work!
Make the changes as below in your css codes and it will work for you.
<div class="classname">
<h4 align="center" class="well"><b>Course Materials<b></h4>
</div>
In you css make changes and replace the code with lines below:
.classname a:hover {
color: green;
}

Why are multiple entries of 'color' css attribute active in Safari Dev Tools?

Sometimes I see two entries for the CSS 'color' attribute active on a single element, even when one has !important. The one without !important is taking precedence though, as it should (I am trying to force the element to color: white). See screenshot:
Thanks!
UPDATE: added html markup
<div class="x-button x-button-back x-layout-box-item x-stretched" id="quit-button" style="width: auto !important;">
<span class="x-badge" style="display: none;"></span>
<span class="x-button-icon x-hidden" id="ext-element-1109"></span>
<span class="x-button-label" style="" id="ext-element-1110">Quit</span>
</div>
.peacekeepers-edition is set on the first element inside the body, #playview is a distant descendent.
Regardless of the specificity of the rule all proprieties from the CSSOM will appear in the inspector rule view. The fact that the "color:#ccffff" is not crossed/underline is just an inspector bug.
BTW, you overqualified your selectors: .preacekeepers-edition #playview will have a specificity of 1|1|0|, that is way more that you should have. Adding !important will make things hard to manage later.
I'm making some assumptions about your markup (because you haven't provided any), but I think it's fairly safe to say that this is your issue.
Assuming your markup is something like this...
<div class="peace-keepers-edition">
<div id="playview">
<button class="x-button-back">
<i class="x-button-icon">icon</i>
</button>
</div>
</div>
Your first selector targets the button element...
.peace-keepers-edition #playview .x-button-back {
color: #FFF !important;
}
but your second selector targets an element that is a descendant of your button...
.peace-keepers-edition #playview .x-button-back .x-button-icon {
color: #ccccff;
}
Your !important rule is irrelevant because your selectors are targeting different elements.
Easy fix; add this line after line 769...
.peace-keepers-edition #playview .x-button-back .x-button-icon {
color: #fff;
}
Broken example...
body {
background: #1a1a1a;
}
button {
padding: 15px;
font-size: 30px;
background: green;
}
.peace-keepers-edition #playview .x-button-back {
color: #FFF !important;
}
.peace-keepers-edition #playview .x-button-back .x-button-icon {
color: #ccccff;
}
<div class="peace-keepers-edition">
<div id="playview">
<button class="x-button-back">
<i class="x-button-icon">icon</i>
</button>
</div>
</div>
Working example...
body {
background: #1a1a1a;
}
button {
padding: 15px;
font-size: 30px;
background: green;
}
.peace-keepers-edition #playview .x-button-back {
color: #FFF !important;
}
.peace-keepers-edition #playview .x-button-back .x-button-icon {
color: #fff;
}
<div class="peace-keepers-edition">
<div id="playview">
<button class="x-button-back">
<i class="x-button-icon">icon</i>
</button>
</div>
</div>

Whats the right method for different colour/style in CSS

I am trying to have 2 different colours/styles for each word of my website name, something like this:
I currently use:
James<strong>.</strong><span>Wood</span>
("STRONG" and "SPAN" tags inside "A" tag).
And then do the rest with CSS.
Is this the right method to do it with CSS if we can't use images?
Very similar to Gianps answer, but with a bit simpler CSS:
Working Demo:
http://www.cdpn.io/wvCou
HTML:
<a href="#" class='title'><span class='green'>James</span>.<span class='orange'>Wood</span></a>
CSS:
.title {
font-size: 18px;
text-transform: uppercase;
font-weight: bold;
color: red;
text-decoration: none;
}
.title .green {color: green;}
.title .orange {color: orange;}
That html code is not readable. It's right to do it with css but in a way like this:
<a href="#" class="f18 b">
<span class="green uc">james</span>.<span class="orange uc">wood</span>
</a>
and define css classes:
.f18 {font-size: 18px;}
.b {font-weight:bold;}
.uc {text-transform:uppercase;}

Is there a CSS selector to locate the 2nd/3rd child or descendant (of a given class/id) under an element (with a given class/id)?

I have something along the lines of this
<div class="menu" style="background-color: transparent;">
<div class="button">
<div class="divider" style="background-color: transparent;"></div>
<a id="apple" class="unselect select" href="/apple">
<span class="apple1">Apple</span>
</a>
</div>
<div class="button">
<div class="divider"></div>
<a id="orange" class="unselect" href="/orange">
<span class="orange1">Orange</span>
</a>
</div>
....
this gives me the first divider
css=div.menu div.button div.divider
I am trying to access the 2nd divider. I have the need to access the buttons as well. I tried reading through the the nth child stuff and noticed that it is not compatible with IE.
Is there a CSS selector to locate the 2nd/3rd child or descendant (of a given class/id) under an element (with a given class/id)?
I am using xPaths now
//div[#class='menu']/descendant::div[contains(#class,'divider')][2]
it works but I want to migrate this to CSS.
The adjacent sibling selector + is able to do that and is compatible with IE7+
Fiddle demonstrating its use with 4 buttons: http://jsfiddle.net/AgNwu/
(no need for "div" if you rely already on id/class everywhere. If you call something "button", expect it to be a link, an input[type="submit|image|button|reset"] or button element ;) )
CSS
.menu > .button {
border: 1px solid darkblue;
padding: 10px;
margin: 5px 0;
}
.menu > .button + .button .divider {
background: Tan;
}
.menu > .button + .button .divider:after{
content: " (2nd or more)";
}
.menu > .button + .button + .button .divider {
background: yellow;
}
.menu > .button + .button + .button .divider:after{
content: " (3rd or more)";
}
edit: adjacent sibling, I thought this was sibling vs. general sibling
You can replace + by ~ (general sibling) if you have other type of nodes in-between your .button nodes/elements. This'd be the equivalent of :nth-of-type that would still work in IE7+
You can write like this:
div.menu div.button + div.button div.divider{
color:red;
}

Resources