:focus on class doesn't work - html

I want the class to appear a different color after selected. Why does it just go back to the non active color? what can I do so that it stays focused on my class?
I tried many things on this forum but nothing seems to work. I need it for school really quickly.
.Auswahl {
outline: none;
background-color: #F6F6F6;
border: none;
margin-right: -4px;
float: left;
-webkit-transition: background-color 0.2s linear;
-moz-transition: background-color 0.2s linear;
-o-transition: background-color 0.2s linear;
transition: background-color 0.2s linear;
}
.Auswahl:hover {
background-color: #FF0004;
}
.Auswahl:active {
background-color: #00FF2B;
}
.Auswahl:focus {
background-color: #7100FF;
}
<div class="Auswahl">
<h1>Sparkasse</h1>
<br>Vorteile
<br>Nachteile
</div>

The :focus pseudo-class applies while an element has the focus
(accepts keyboard events or other forms of text input).
More info here
Change your HTML like this:
.Auswahl {
outline: none;
background-color: #F6F6F6;
border: none;
margin-right: -4px;
float: left;
-webkit-transition: background-color 0.2s linear;
-moz-transition: background-color 0.2s linear;
-o-transition: background-color 0.2s linear;
transition: background-color 0.2s linear;
}
.Auswahl:hover {
background-color: #FF0004;
}
.Auswahl:focus {
background-color: #7100FF;
}
.Auswahl:active {
background-color: #00FF2B;
}
<button class="Auswahl">
<h1>Sparkasse</h1>
<br>Vorteile
<br>Nachteile
</button>

Try this. It's got a very small amount of jQuery to add a new class on click.
HTML
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<div class="Auswahl">
<h1>Sparkasse</h1>
<br>Vorteile
<br>Nachteile
</div>
CSS
.Auswahl {
outline: none;
background-color: #F6F6F6;
border: none;
margin-right: -4px;
float: left;
-webkit-transition: background-color 0.2s linear;
-moz-transition: background-color 0.2s linear;
-o-transition: background-color 0.2s linear;
transition: background-color 0.2s linear;
}
.Auswahl:hover {
background-color: #FF0004;
}
.Auswahl:active {
background-color: #00FF2B;
}
.Auswahl:focus {
background-color: #7100FF;
}
.newClass {
background-color: #7100FF;
}
JQUERY
$(".Auswahl").click(function(){
$(this).addClass('newClass');
});
Here's a Codepen example too: EXAMPLE HERE

Related

smooth scroll transition upon click using CSS only (no JavaScript allowed)

I'm trying to make a smooth scroll upon click the button (up) as in the gif:
https://elzero.org/wp-content/uploads/2021/04/scroll-to-top-pure-css.gif
the thing is, I'm not allowed to use JavaScript for that, so only HTML and CSS and I don't seem to be able to find a relevant pseudo-class for that. Can any one please help?
here is my HTML:
Up
<p id="one">One</p>
<p>Two</p>
<p>Three</p>
<p>Four</p>
And here's the CSS:
p {
margin-bottom: 600px;
}
a {
text-decoration: none;
background-color: red;
color: white;
padding: 5px;
position: fixed;
bottom: 40px;
right: 40px;
transition: 1s all linear;
-webkit-transition: 1s all linear;
-moz-transition: 1s all linear;
-ms-transition: 1s all linear;
-o-transition: 1s all linear;
}
You can use scroll-behavior: smooth;
html {
scroll-behavior: smooth;
}
p {
margin-bottom: 600px;
}
a {
text-decoration: none;
background-color: red;
color: white;
padding: 5px;
position: fixed;
bottom: 40px;
right: 40px;
transition: 1s all linear;
-webkit-transition: 1s all linear;
-moz-transition: 1s all linear;
-ms-transition: 1s all linear;
-o-transition: 1s all linear;
}
Up
<p id="one">One</p>
<p>Two</p>
<p>Three</p>
<p>Four</p>

Ease-in works for both text and background but ease-out only works for text. Why?

Ease-in only works for text and background but ease-out only works for text but not background.
article {
width: 100%;
height: 1000px;
background-color: #fffff;
color: #00000;
}
article .topnav {
opacity: 0;
transition: background-color .9s ease-out;
transition: background-color .9s ease-in;
-moz-transition: background-color .9s ease-in;
-webkit-transition: background-color .9s ease-in;
}
article .topnav {
background: rgba(0,0,0,0);
transition: opacity .9s ease-out;
transition: opacity .9s ease-in;
-moz-transition: opacity .9s ease-in;
-webkit-transition: opacity .9s ease-in;
}
article:hover p.topnav {
opacity: 0.7;
background-color: #808080;
}
.topnav {
visibility: invisible;
text-align: center;
margin: auto;
width: 50%;
}
<article>
<p class="topnav">I am topnav</p>
</article>
Please see fiddle.
The idea is so that when I hover in and out of , both the text and the background eases in and out together.
Please help.
You are setting both transitions on the unhovered state, thus the second one is overwriting the first rule. You need to apply transition rules to both unhovered and hovered state.
article {
width: 100%;
height: 1000px;
background-color: #fffff;
color: #00000;
}
article p.topnav {
opacity: 0;
background-color: #000;
transition: all .9s ease-out;
}
article:hover p.topnav {
opacity: 0.7;
background-color: #808080;
transition: all .9s ease-in;
}
.topnav {
text-align: center;
margin: auto;
width: 50%;
}
<article>
<p class="topnav">I am topnav</p>
</article>

Sync hover state with <li> and <a>? [duplicate]

This question already has answers here:
How to affect other elements when one element is hovered
(9 answers)
Closed 8 years ago.
I am trying to make it so that so that a hover effect will apply for both a listed item tag and an anchor tag that it is nested in. Ideally I want it so that all the CSS is on one tag instead of split into two. I want the hover effect of the anchor tag to animate when the listed element tag is triggered. I'm assuming the solution would be to merge the styles into one but I don't know how to do it.
HTML:
<ul class="nav">
<li>
CONTACT
</li>
<li>
ABOUT
</li>
<li>
PORTFOLIO
</li>
</ul>
CSS:
body{
background: #000;
}
ul{
list-style-type:none;
display: inline-block;
}
.nav{
float:right;
list-style-type:none;
overflow: hidden;
}
.nav li{
float:right;
overflow: hidden;
color: #00bff3;
border: 1px solid #00bff3;
padding: 8px;
margin-left: 10px;
text-align: center;
-webkit-transition: all 0.3s ease-in;
-moz-transition: all 0.3s ease-in;
-o-transition: all 0.3s ease-in;
}
.nav li:hover{
background:#00bff3;
color:#000000;
}
.blue{
color: #00bff3;
text-decoration: none;
-webkit-transition: all 0.3s ease-in;
-moz-transition: all 0.3s ease-in;
-o-transition: all 0.3s ease-in;
}
.blue:hover{
color:#000000;
}
http://jsfiddle.net/2gbu5yrz/
It's easy enough to move the relevant styles to the links themselves (really where they should be anyhow):
http://codepen.io/pageaffairs/pen/PwNeEO
.blue{
color: #00bff3;
text-decoration: none;
-webkit-transition: all 0.3s ease-in;
-moz-transition: all 0.3s ease-in;
-o-transition: all 0.3s ease-in;
display: block;
text-align: center;
padding: 8px;
}
.blue:hover{
color:#000000;
background:#00bff3;
}
Maybe this is what you are looking for: Replace .blue:hover with .nav li:hover .blue.
http://jsfiddle.net/p0ahhp5c/
The solution is to make your a use block display style:
.blue{
display: block;
color: #00bff3;
text-decoration: none;
-webkit-transition: all 0.3s ease-in;
-moz-transition: all 0.3s ease-in;
-o-transition: all 0.3s ease-in;
}
Try this
.nav:hover .blue:hover {
/*your code here*/
}

background overlays text

DEMO
As you can see in my jsbin the background overlays the text in my three link objects (move your cursor above it to see it).
I have tried around with the z-index (as suggested by a friend), however that doesn't seem to have any effect.
How would you go about fixing it?
Here's the relevant CSS:
a {
color: #CCCCCC;
}
a:hover {
background-color: #CCCCCC;
}
As you can see, The font color and background color are the same on hover. The z-index has nothing to do with it. Change the color on :hover and you will see the text, as demonstrated on this fiddle: http://jsfiddle.net/yVdvx/
Change this CSS code.
From:
a {
z-index: 10000;
text-decoration: none;
border-bottom: 1px dotted #666666;
color: #CCCCCC;
-webkit-transition: 0.25s ease;
transition: 0.25s ease;
}
a:hover {
background-color: #CCCCCC;
opacity: .9;
-webkit-transition: 0.25s ease;
transition: 0.25s ease;
}
To (my example makes a:hover color blue):
a {
z-index: 10000;
text-decoration: none;
border-bottom: 1px dotted #666666;
color: #CCCCCC;
-webkit-transition: 0.25s ease;
transition: 0.25s ease;
}
a:hover {
background-color: blue;
color: #393434;
opacity: .9;
-webkit-transition: 0.25s ease;
transition: 0.25s ease;
}
Besides, it may be good to include CSS code in a separate file and load it in the HTML file.

Child change when parent is hovered over

I am trying to get a child element to change when the parent is hovered. I also want an attribute of that parent to change as well. I am trying to get the background color of #action to change and the color of the a or h1 to change when action is hovered over. Is this possible?
here is the html
<section id="action" class="general">
<div class="container">
<h1>This text</h1>
</div>
</section>
and here is the css. CSS is built using SASS that is why it is structured like that.
#action {
background-color: $bgLight;
border-top: 1px solid #252525;
-webkit-transition: all 0.2s ease-out;
-moz-transition: all 0.2s ease-out;
-ms-transition: all 0.2s ease-out;
-o-transition: all 0.2s ease-out;
transition: all 0.2s ease-out;
a {
text-decoration: none;
h1 {
margin: 0;
color: $colorLight;
font-weight: 300;
text-align: center;
}
}
}
#action:hover a {
background-color: #76A7D1;
color: $colorDark;
}
Try this:
#action {
background-color: $bgLight;
border-top: 1px solid #252525;
-webkit-transition: all 0.2s ease-out;
-moz-transition: all 0.2s ease-out;
-ms-transition: all 0.2s ease-out;
-o-transition: all 0.2s ease-out;
transition: all 0.2s ease-out;
a {
text-decoration: none;
h1 {
margin: 0;
color: $colorLight;
font-weight: 300;
text-align: center;
}
}
}
#action:hover{
background-color: #76A7D1;
a{
h1{
color: $colorDark;
}
}
}
You can do the same as #Alessandro Minoccheri suggested but in a less verbose way which I like particularly:
#action {
background-color: $bgLight;
border-top: 1px solid #252525;
-webkit-transition: all 0.2s ease-out;
-moz-transition: all 0.2s ease-out;
-ms-transition: all 0.2s ease-out;
-o-transition: all 0.2s ease-out;
transition: all 0.2s ease-out;
a {
text-decoration: none;
h1 {
margin: 0;
color: $colorLight;
font-weight: 300;
text-align: center;
}
}
&:hover{
background-color: #76A7D1;
a{
h1{
color: $colorDark;
}
}
}
}
The & within #action refers to the parent element, in other words to #action itself.
I like this approach because everything gets self contained within one style declaration and is less repetitive.
It is like saying: "... and when this element is hovered apply these styles to it, and these styles to a and h1".
One small comment regarding your markup #zachstames: a (anchor element) is an inline content element, while h1 (header of level 1) is a block element. According to the W3C specifications an inline element should not contain block elements but only data.
Hope it helps.
Cheers!
This is what you want? DEMO
You are able to make this:
#action:hover {
background: yellow;
}
#action:hover a {
background-color: #76A7D1;
color: white;
}
As you can see I repeat the use of the pseudo-class #action:hover. I'm saying:
"When action is hover, change it's backgroud AND when action is hover, change the background and the font color of the a element".
Hope I've helped.
Be good,
Leonardo