Animation only happening on one checkbox despite different classes - html

I have found a checkbox which I really want to use but when I add more than 1 checkbox the animation only applies to the first one.
I have tried creating new class's like .cbx2 and .inp-cbx2 and applying the same style's but the animation still only applies to the first checkbox.
Could you please explain where I'm going wrong?
Thanks.
/* #### CHECKBOX STYLES AND ANIMATION #### */
.cbx {
margin: auto;
-webkit-user-select: none;
user-select: none;
cursor: pointer;
}
.cbx span {
display: inline-block;
vertical-align: middle;
transform: translate3d(0, 0, 0);
}
.cbx span:first-child {
position: relative;
width: 50px;
height: 50px;
border-radius: 0px;
transform: scale(1);
vertical-align: middle;
border: 1px solid #9098A9;
transition: all 0.2s ease;
}
.cbx span:first-child svg {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
fill: none;
stroke: #FFFFFF;
stroke-width: 2;
stroke-linecap: round;
stroke-linejoin: round;
stroke-dasharray: 16px;
stroke-dashoffset: 16px;
transition: all 0.3s ease;
transition-delay: 0.1s;
transform: translate3d(0, 0, 0);
}
.cbx span:first-child:before {
content: "";
width: 100%;
height: 100%;
background: #2bbfcb;
display: block;
transform: scale(0);
opacity: 1;
border-radius: 0%;
}
.cbx span:last-child {
padding-left: 8px;
}
.cbx:hover span:first-child {
border-color: #2bbfcb;
}
.inp-cbx:checked + .cbx span:first-child {
background: #2bbfcb;
border-color: #2bbfcb;
animation: wave 0.4s ease;
}
.inp-cbx:checked + .cbx span:first-child svg {
stroke-dashoffset: 0;
}
.inp-cbx:checked + .cbx span:first-child:before {
transform: scale(3.5);
opacity: 0;
transition: all 0.6s ease;
}
#keyframes wave {
50% {
transform: scale(0.9);
}
}
/* #### CHECKBOX STYLES AND ANIMATION #### */
.cbx2 {
margin: auto;
-webkit-user-select: none;
user-select: none;
cursor: pointer;
}
.cbx2 span {
display: inline-block;
vertical-align: middle;
transform: translate3d(0, 0, 0);
}
.cbx2 span:first-child {
position: relative;
width: 50px;
height: 50px;
border-radius: 0px;
transform: scale(1);
vertical-align: middle;
border: 1px solid #9098A9;
transition: all 0.2s ease;
}
.cbx2 span:first-child svg {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
fill: none;
stroke: #FFFFFF;
stroke-width: 2;
stroke-linecap: round;
stroke-linejoin: round;
stroke-dasharray: 16px;
stroke-dashoffset: 16px;
transition: all 0.3s ease;
transition-delay: 0.1s;
transform: translate3d(0, 0, 0);
}
.cbx2 span:first-child:before {
content: "";
width: 100%;
height: 100%;
background: #2bbfcb;
display: block;
transform: scale(0);
opacity: 1;
border-radius: 0%;
}
.cbx2 span:last-child {
padding-left: 8px;
}
.cbx2:hover span:first-child {
border-color: #2bbfcb;
}
.inp-cbx2:checked + .cbx2 span:first-child {
background: #2bbfcb;
border-color: #2bbfcb;
animation: wave 0.4s ease;
}
.inp-cbx2:checked + .cbx2 span:first-child svg {
stroke-dashoffset: 0;
}
.inp-cbx2:checked + .cbx2 span:first-child:before {
transform: scale(3.5);
opacity: 0;
transition: all 0.6s ease;
}
#keyframes wave {
50% {
transform: scale(0.9);
}
}
<input class="inp-cbx" id="cbx" type="checkbox" style="display: none;"/>
<label class="cbx" for="cbx"><span>
<svg width="40px" height="40px" viewbox="0 0 12 10">
<polyline points="1.5 6 4.5 9 10.5 1"></polyline>
</svg></span><span>DIRECT</span></label>
<input class="inp-cbx2" id="cbx2" type="checkbox" style="display: none;"/>
<label class="cbx2" for="cbx"><span>
<svg width="40px" height="40px" viewbox="0 0 12 10" class="c">
<polyline points="1.5 6 4.5 9 10.5 1"></polyline>
</svg></span><span>MUTI ROUTE</span></label>

The whole reason classes exist in CSS is to make your styles reusable across multiple elements. There is no need to duplicate your CSS.
The reason the second check box doesn't work when using the same classes as the first is because you haven't updated the second labels for property. This property tells the browser the id of the form element that should be effected when the label is clicked.
In your case, the second label should look like this:
<label class="cbx" for="cbx2"><span>
/* #### CHECKBOX STYLES AND ANIMATION #### */
.cbx {
margin: auto;
-webkit-user-select: none;
user-select: none;
cursor: pointer;
}
.cbx span {
display: inline-block;
vertical-align: middle;
transform: translate3d(0, 0, 0);
}
.cbx span:first-child {
position: relative;
width: 50px;
height: 50px;
border-radius: 0px;
transform: scale(1);
vertical-align: middle;
border: 1px solid #9098A9;
transition: all 0.2s ease;
}
.cbx span:first-child svg {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
fill: none;
stroke: #FFFFFF;
stroke-width: 2;
stroke-linecap: round;
stroke-linejoin: round;
stroke-dasharray: 16px;
stroke-dashoffset: 16px;
transition: all 0.3s ease;
transition-delay: 0.1s;
transform: translate3d(0, 0, 0);
}
.cbx span:first-child:before {
content: "";
width: 100%;
height: 100%;
background: #2bbfcb;
display: block;
transform: scale(0);
opacity: 1;
border-radius: 0%;
}
.cbx span:last-child {
padding-left: 8px;
}
.cbx:hover span:first-child {
border-color: #2bbfcb;
}
.inp-cbx:checked+.cbx span:first-child {
background: #2bbfcb;
border-color: #2bbfcb;
animation: wave 0.4s ease;
}
.inp-cbx:checked+.cbx span:first-child svg {
stroke-dashoffset: 0;
}
.inp-cbx:checked+.cbx span:first-child:before {
transform: scale(3.5);
opacity: 0;
transition: all 0.6s ease;
}
#keyframes wave {
50% {
transform: scale(0.9);
}
}
<input class="inp-cbx" id="cbx" type="checkbox" style="display: none;" />
<label class="cbx" for="cbx"><span>
<svg width="40px" height="40px" viewbox="0 0 12 10">
<polyline points="1.5 6 4.5 9 10.5 1"></polyline>
</svg></span><span>DIRECT</span></label>
<input class="inp-cbx" id="cbx2" type="checkbox" style="display: none;" />
<label class="cbx" for="cbx2"><span>
<svg width="40px" height="40px" viewbox="0 0 12 10" class="c">
<polyline points="1.5 6 4.5 9 10.5 1"></polyline>
</svg></span><span>MUTI ROUTE</span></label>

Related

Why does "<use xlink:href..." change the behavior of an svg image?

I am studying the following code:
* {
box-sizing: border-box;
}
body {
font-family: "Open Sans", sans-serif;
font-size: 16px;
-webkit-font-smoothing: antialiased;
text-rendering: optimizelegibility;
color: #223254;
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.cbx {
-webkit-user-select: none;
user-select: none;
cursor: pointer;
padding: 6px 8px;
border-radius: 6px;
overflow: hidden;
transition: all 0.2s ease;
}
.cbx:not(:last-child) {
margin-right: 6px;
}
.cbx:hover {
background: rgba(0, 119, 255, 0.06);
}
.cbx span {
float: left;
vertical-align: middle;
transform: translate3d(0, 0, 0);
}
.cbx span:first-child {
position: relative;
width: 18px;
height: 18px;
border-radius: 4px;
transform: scale(1);
border: 1px solid #cccfdb;
transition: all 0.2s ease;
box-shadow: 0 1px 1px rgba(0, 16, 75, 0.05);
}
.cbx span:first-child svg {
position: absolute;
top: 3px;
left: 2px;
fill: none;
stroke: #fff;
stroke-width: 2;
stroke-linecap: round;
stroke-linejoin: round;
stroke-dasharray: 16px;
stroke-dashoffset: 16px;
transition: all 0.3s ease;
transition-delay: 0.1s;
transform: translate3d(0, 0, 0);
}
.cbx span:last-child {
padding-left: 8px;
line-height: 18px;
}
.cbx:hover span:first-child {
border-color: #07f;
}
.inp-cbx {
position: absolute;
visibility: hidden;
}
.inp-cbx:checked+.cbx span:first-child {
background: #07f;
border-color: #07f;
animation: wave 0.4s ease;
}
.inp-cbx:checked+.cbx span:first-child svg {
stroke-dashoffset: 0;
}
.inline-svg {
position: absolute;
width: 0;
height: 0;
pointer-events: none;
user-select: none;
}
#-moz-keyframes wave {
50% {
transform: scale(0.9);
}
}
#-webkit-keyframes wave {
50% {
transform: scale(0.9);
}
}
#-o-keyframes wave {
50% {
transform: scale(0.9);
}
}
#keyframes wave {
50% {
transform: scale(0.9);
}
}
<input class="inp-cbx" id="morning" type="checkbox" />
<label class="cbx" for="morning">
<span>
<svg width="12px" height="10px">
<use xlink:href="#check"></use>
</svg>
</span>
<span>Label</span>
</label>
<!--SVG Sprite-->
<svg class="inline-svg">
<symbol id="check" viewbox="0 0 12 10">
<polyline points="1.5 6 4.5 9 10.5 1"></polyline>
</symbol>
</svg>
And when I extract the separate svg and put it directly in the svg tag (but removing the inline-svg class), the check svg no longer shows up. As shown here:
* {
box-sizing: border-box;
}
body {
font-family: "Open Sans", sans-serif;
font-size: 16px;
-webkit-font-smoothing: antialiased;
text-rendering: optimizelegibility;
color: #223254;
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.cbx {
-webkit-user-select: none;
user-select: none;
cursor: pointer;
padding: 6px 8px;
border-radius: 6px;
overflow: hidden;
transition: all 0.2s ease;
}
.cbx:not(:last-child) {
margin-right: 6px;
}
.cbx:hover {
background: rgba(0, 119, 255, 0.06);
}
.cbx span {
float: left;
vertical-align: middle;
transform: translate3d(0, 0, 0);
}
.cbx span:first-child {
position: relative;
width: 18px;
height: 18px;
border-radius: 4px;
transform: scale(1);
border: 1px solid #cccfdb;
transition: all 0.2s ease;
box-shadow: 0 1px 1px rgba(0, 16, 75, 0.05);
}
.cbx span:first-child svg {
position: absolute;
top: 3px;
left: 2px;
fill: none;
stroke: #fff;
stroke-width: 2;
stroke-linecap: round;
stroke-linejoin: round;
stroke-dasharray: 16px;
stroke-dashoffset: 16px;
transition: all 0.3s ease;
transition-delay: 0.1s;
transform: translate3d(0, 0, 0);
}
.cbx span:last-child {
padding-left: 8px;
line-height: 18px;
}
.cbx:hover span:first-child {
border-color: #07f;
}
.inp-cbx {
position: absolute;
visibility: hidden;
}
.inp-cbx:checked+.cbx span:first-child {
background: #07f;
border-color: #07f;
animation: wave 0.4s ease;
}
.inp-cbx:checked+.cbx span:first-child svg {
stroke-dashoffset: 0;
}
.inline-svg {
position: absolute;
width: 0;
height: 0;
pointer-events: none;
user-select: none;
}
#-moz-keyframes wave {
50% {
transform: scale(0.9);
}
}
#-webkit-keyframes wave {
50% {
transform: scale(0.9);
}
}
#-o-keyframes wave {
50% {
transform: scale(0.9);
}
}
#keyframes wave {
50% {
transform: scale(0.9);
}
}
<input class="inp-cbx" id="morning" type="checkbox" />
<label class="cbx" for="morning">
<span>
<svg width="12px" height="10px">
<symbol id="check" viewbox="0 0 12 10">
<polyline points="1.5 6 4.5 9 10.5 1"></polyline>
</symbol>
</svg>
</span>
<span>Label</span>
</label>
What is the cause for this behavior and how do I make it behave the same way?
I have tried using the inline-svg class and checked tag for tag what css properties are missing but I can't see something that differs which makes me believe it is some special behavior from the svg tag.
With the help from #enxaneta I learned that <symbol> is not visible unless used with <use> so I simply removed the <symbol> and replaced it with a <svg> and it works perfectly:
* {
box-sizing: border-box;
}
body {
font-family: "Open Sans", sans-serif;
font-size: 16px;
-webkit-font-smoothing: antialiased;
text-rendering: optimizelegibility;
color: #223254;
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.cbx {
-webkit-user-select: none;
user-select: none;
cursor: pointer;
padding: 6px 8px;
border-radius: 6px;
overflow: hidden;
transition: all 0.2s ease;
}
.cbx:not(:last-child) {
margin-right: 6px;
}
.cbx:hover {
background: rgba(0, 119, 255, 0.06);
}
.cbx span {
float: left;
vertical-align: middle;
transform: translate3d(0, 0, 0);
}
.cbx span:first-child {
position: relative;
width: 18px;
height: 18px;
border-radius: 4px;
transform: scale(1);
border: 1px solid #cccfdb;
transition: all 0.2s ease;
box-shadow: 0 1px 1px rgba(0, 16, 75, 0.05);
}
.cbx span:first-child svg {
position: absolute;
top: 3px;
left: 2px;
fill: none;
stroke: #fff;
stroke-width: 2;
stroke-linecap: round;
stroke-linejoin: round;
stroke-dasharray: 16px;
stroke-dashoffset: 16px;
transition: all 0.3s ease;
transition-delay: 0.1s;
transform: translate3d(0, 0, 0);
}
.cbx span:last-child {
padding-left: 8px;
line-height: 18px;
}
.cbx:hover span:first-child {
border-color: #07f;
}
.inp-cbx {
position: absolute;
visibility: hidden;
}
.inp-cbx:checked+.cbx span:first-child {
background: #07f;
border-color: #07f;
animation: wave 0.4s ease;
}
.inp-cbx:checked+.cbx span:first-child svg {
stroke-dashoffset: 0;
}
.inline-svg {
position: absolute;
width: 0;
height: 0;
pointer-events: none;
user-select: none;
}
#-moz-keyframes wave {
50% {
transform: scale(0.9);
}
}
#-webkit-keyframes wave {
50% {
transform: scale(0.9);
}
}
#-o-keyframes wave {
50% {
transform: scale(0.9);
}
}
#keyframes wave {
50% {
transform: scale(0.9);
}
}
<input class="inp-cbx" id="morning" type="checkbox" />
<label class="cbx" for="morning">
<span>
<svg width="12px" height="10px" viewbox="0 0 12 10">
<polyline points="1.5 6 4.5 9 10.5 1"></polyline>
</svg>
</span>
<span>Label</span>
</label>

Reversing CSS animation after leaving hover does not work

I'm trying to reverse the animation after the user is not hovering. I tried making a keyframe with the opposite animation, using reverse and adding transition: all 2s but neither worked. I also tried div::after:not(:hover).
html {
background-color: black;
}
div {
position: relative;
width: 50vw;
transition: all 2s reverse;
}
div:hover::after {
position: absolute;
content: " ";
height: 50px;
width: 50px;
top: 50%;
right: 0;
border: solid rgb(255, 255, 255);
border-width: 0 10px 10px 0;
display: inline-block;
animation: fadeMain 2s cubic-bezier(0.785, 0.135, 0.15, 0.86) forwards;
// background-color: green;
}
div::after:not(:hover) {
animation: fadeMain 2s cubic-bezier(0.785, 0.135, 0.15, 0.86) reverse;
}
#keyframes fadeMain {
from {
opacity: 0;
transform: translateX(0px) rotate(-45deg);
}
to {
opacity: 1;
transform: translateX(20px) rotate(-45deg);
}
}
// Doesnt work:
// #keyframes fadeMainOut {
// from {
// opacity: 1;
// transform: translateX(20px) rotate(-45deg);
// }
// to {
// opacity: 0;
// transform: translateX(0px) rotate(-45deg);
// }
// }
<div>
<svg id="centerLogo" width="586" height="192" viewBox="0 0 586 192" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M0 192H36.5324L97.2281 82.4505L79.1057 49.2973L0 192ZM124.555 32.8649L106.145 3.43666e-05L88.023 32.8649L106.145 65.7298L176.046 192H212.291L124.555 32.8649Z" fill="white"/>
<path d="M332.66 92.8289L335.248 89.6577L400.547 0.576604H366.315L318.277 66.3063L315.688 69.7658L313.099 66.3063L264.773 0.576604H230.541L296.127 89.6577L298.428 92.8289V93.1171L315.688 116.18L371.493 192H405.724L332.66 92.8289ZM225.651 192H259.882L307.058 128L290.086 104.649L225.651 192Z" fill="white"/>
<path d="M551.769 3.43666e-05L498.552 72.6487V72.937L445.623 3.43666e-05H411.392L479.567 93.4054L481.58 96V96.2883L485.032 100.901V192H512.36V100.613L513.223 99.7478L515.812 96.2883V96L517.825 93.4054L586 3.43666e-05H551.769Z" fill="white"/>
</svg>
</div>
Your problem is that div::after:not(:hover) doesn't render an :after element in div.
Also to switch animation between hover and non hover you need to use keywords other than from to.
these changes should fix it
div::after {
content: " ";
position: absolute;
height: 50px;
width: 50px;
top: 50%;
right: 0;
border: solid rgb(255, 255, 255);
border-width: 0 10px 10px 0;
display: inline-block;
opacity: 0;
animation: fadeMainOut 2s cubic-bezier(0.785, 0.135, 0.15, 0.86)
forwards;
}
div:hover::after {
content: " ";
position: absolute;
height: 50px;
width: 50px;
top: 50%;
right: 0;
border: solid rgb(255, 255, 255);
border-width: 0 10px 10px 0;
display: inline-block;
animation: fadeMain 2s cubic-bezier(0.785, 0.135, 0.15, 0.86) forwards;
}
#keyframes fadeMain {
from {
opacity: 0;
transform: translateX(0px) rotate(-45deg);
}
to {
opacity: 1;
transform: translateX(20px) rotate(-45deg);
}
}
#keyframes fadeMainOut {
0% {
opacity: 1;
transform: translateX(20px) rotate(-45deg);
}
100% {
opacity: 0;
transform: translateX(0px) rotate(-45deg);
}
}

css closing sidebar when clicking in the main window

Hello there I searched for other people who has the same problem as me but I couldn't implement their problem to mine so I want to close the sidebar when clicking outside the sidebar.
html {
background-color: #161618;
overflow: hidden;
}
#menuToggle
{
display: block;
position: relative;
top: 10px;
left: 10px;
z-index: 1;
-webkit-user-select: none;
user-select: none;
}
#menuToggle a
{
text-decoration: none;
color: #7e7e7e;
font-family: 'Microsoft Yahei';
transition: color 0.3s ease;
}
#menuToggle a:hover
{
color: white;
}
#menuToggle input
{
display: block;
width: 40px;
height: 32px;
position: absolute;
top: -7px;
left: 2px;
cursor: pointer;
opacity: 0;
z-index: 2;
-webkit-touch-callout: none;
}
#menuToggle span
{
display: block;
width: 33px;
height: 4px;
margin-bottom: 5px;
position: relative;
background: #cdcdcd;
border-radius: 3px;
z-index: 1;
transform-origin: 4px 0px;
transition: transform 0.5s cubic-bezier(0.77,0.2,0.05,1.0),
background 0.5s cubic-bezier(0.77,0.2,0.05,1.0),
opacity 0.55s ease;
}
#menuToggle span:first-child
{
transform-origin: 0% 0%;
}
#menuToggle span:nth-last-child(2)
{
transform-origin: 0% 100%;
}
#menuToggle input:checked ~ span
{
opacity: 1;
transform: rotate(45deg) translate(-2px, -1px);
background: #FCFCFC;
}
#menuToggle input:checked ~ span:nth-last-child(3)
{
opacity: 0;
transform: rotate(0deg) scale(0.2, 0.2);
}
#menuToggle input:checked ~ span:nth-last-child(2)
{
transform: rotate(-45deg) translate(0, -1px);
}
#menu
{
position: fixed;
width: fit-content;
background-color: #141414;
margin: -100px 0 0 -50px;
padding: 50px;
box-shadow: 0 -2px 15px rgb(5, 5, 5);
height: 1400px;
padding-top: 125px;
list-style-type: none;
-webkit-font-smoothing: antialiased;
transform-origin: 0% 0%;
transform: translate(-100%, 0);
transition: transform 0.5s cubic-bezier(0.77,0.2,0.05,1.0);
}
#menu li
{
padding: 10px 0;
font-size: 22px;
}
#menuToggle input:checked ~ ul
{
transform: none;
}
.github:hover {
filter: invert(100%) sepia(100%) saturate(0%) hue-rotate(308deg) brightness(101%) contrast(101%);
}
<nav role="navigation">
<div id="menuToggle">
<input type="checkbox" />
<span></span>
<span></span>
<span></span>
<ul id="menu">
<li>Home</li>
<li>About</li>
<li>Info</li>
<li>Contact</li>
<li><svg class="github" style="position:absolute;fill: #7e7e7e;width:35px;height:35px;margin-top: 275%;margin-left: 25%;padding:0%;" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z"/></svg></li>
</ul>
</div>
</nav>
as I should I have tried to solve the problem on my own and I did stuff with js with body onclick= ... but I am not that familiar with js and I don't know if it would work
Your toggle menu works by checking/unchecking a checkbox. This can only be done by clicking on the input element (incl. all child elements) itself or by clicking on the linked label.
None of that applies if you clicking outside that specific element. As such you require a script to listen for click events outside of that element. here you find a reference to this code
Last but not least to finish the code from the reference you can use:
document.querySelector("#menuToggle input").checked = false; to uncheck the checkbox in question to close it.
var ignoreElement = document.querySelector("#menuToggle");
document.addEventListener('click', function(event) {
var clickElement = ignoreElement.contains(event.target);
if (!clickElement) {
document.querySelector("#menuToggle input").checked = false;
}
});
html {
background-color: #161618;
overflow: hidden;
}
#menuToggle {
display: block;
position: relative;
top: 10px;
left: 10px;
z-index: 1;
-webkit-user-select: none;
user-select: none;
}
#menuToggle a {
text-decoration: none;
color: #7e7e7e;
font-family: 'Microsoft Yahei';
transition: color 0.3s ease;
}
#menuToggle a:hover {
color: white;
}
#menuToggle input {
display: block;
width: 40px;
height: 32px;
position: absolute;
top: -7px;
left: 2px;
cursor: pointer;
opacity: 0;
z-index: 2;
-webkit-touch-callout: none;
}
#menuToggle span {
display: block;
width: 33px;
height: 4px;
margin-bottom: 5px;
position: relative;
background: #cdcdcd;
border-radius: 3px;
z-index: 1;
transform-origin: 4px 0px;
transition: transform 0.5s cubic-bezier(0.77, 0.2, 0.05, 1.0), background 0.5s cubic-bezier(0.77, 0.2, 0.05, 1.0), opacity 0.55s ease;
}
#menuToggle span:first-child {
transform-origin: 0% 0%;
}
#menuToggle span:nth-last-child(2) {
transform-origin: 0% 100%;
}
#menuToggle input:checked~span {
opacity: 1;
transform: rotate(45deg) translate(-2px, -1px);
background: #FCFCFC;
}
#menuToggle input:checked~span:nth-last-child(3) {
opacity: 0;
transform: rotate(0deg) scale(0.2, 0.2);
}
#menuToggle input:checked~span:nth-last-child(2) {
transform: rotate(-45deg) translate(0, -1px);
}
#menu {
position: fixed;
width: fit-content;
background-color: #141414;
margin: -100px 0 0 -50px;
padding: 50px;
box-shadow: 0 -2px 15px rgb(5, 5, 5);
height: 1400px;
padding-top: 125px;
list-style-type: none;
-webkit-font-smoothing: antialiased;
transform-origin: 0% 0%;
transform: translate(-100%, 0);
transition: transform 0.5s cubic-bezier(0.77, 0.2, 0.05, 1.0);
}
#menu li {
padding: 10px 0;
font-size: 22px;
}
#menuToggle input:checked~ul {
transform: none;
}
.github:hover {
filter: invert(100%) sepia(100%) saturate(0%) hue-rotate(308deg) brightness(101%) contrast(101%);
}
<nav role="navigation">
<div id="menuToggle">
<input type="checkbox" />
<span></span>
<span></span>
<span></span>
<ul id="menu">
<a href="loading.html">
<li>Home</li>
</a>
<a href="#">
<li>About</li>
</a>
<a href="index.html">
<li>Info</li>
</a>
<a href="#">
<li>Contact</li>
</a>
<a href="#">
<li><svg class="github" style="position:absolute;fill: #7e7e7e;width:35px;height:35px;margin-top: 275%;margin-left: 25%;padding:0%;" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z"/></svg></li>
</a>
</ul>
</div>
</nav>

Changing hovering behavior in scss

How can I make the "Menu" Button remain in hover as long as the mouse/pointer remains in the menu? When the pointer points on Twitter for example I want the menu button to show Home.
Like this:
And not like this:
This is the Codepen example: https://codepen.io/fotios_tragopoulos/pen/YzWyZJj
This is the code:
body {
background-color: #010101;
color: rgba(255, 255, 255, 0.7);
font-family: 'Lato', sans-serif;
margin: 20px;
}
.menu {
text-transform: uppercase;
color: rgba(255, 255, 255, 0.8);
display: inline-block;
cursor: pointer;
pointer-events: none;
position: absolute;
bottom: 20px;
left: 20px;
&:hover {
pointer-events: all;
.spacer {
&:before {
width: 100%;
transition-delay: 0s;
}
}
.item {
opacity: 1;
top: 0px;
&:nth-child(1) {
transition-delay: 0.25s;
}
&:nth-child(2) {
transition-delay: 0.3s;
}
&:nth-child(3) {
transition-delay: 0.35s;
}
&:nth-child(4) {
transition-delay: 0.4s;
}
&:nth-child(5) {
transition-delay: 0.45s;
}
&:nth-child(6) {
transition-delay: 0.5s;
}
&:nth-child(7) {
transition-delay: 0.55s;
}
&:nth-child(8) {
transition-delay: 0.6s;
}
&:nth-child(9) {
transition-delay: 0.65s;
}
&:nth-child(10) {
transition-delay: 0.7s;
}
}
}
}
.label {
display: inline-block;
cursor: pointer;
pointer-events: all;
}
.spacer {
display: inline-block;
width: 80px;
margin-left: 15px;
margin-right: 15px;
vertical-align: middle;
cursor: pointer;
position: relative;
&:before {
content: "";
position: absolute;
border-bottom: 1px solid #ffffff;
height: 1px;
width: 0%;
transition: width 0.25s ease;
transition-delay: 0.7s;
}
}
.item {
position: relative;
display: inline-block;
margin-right: 30px;
top: 10px;
opacity: 0;
transition: opacity 0.5s ease, top 0.5s ease;
transition-delay: 0;
&:hover {
span {
color: #ff0000;
}
}
&:nth-child(1) {
transition-delay: 0.45s;
}
&:nth-child(2) {
transition-delay: 0.4s;
}
&:nth-child(3) {
transition-delay: 0.35s;
}
&:nth-child(4) {
transition-delay: 0.3s;
}
&:nth-child(5) {
transition-delay: 0.25s;
}
&:nth-child(6) {
transition-delay: 0.2s;
}
&:nth-child(7) {
transition-delay: 0.15s;
}
&:nth-child(8) {
transition-delay: 0.1s;
}
&:nth-child(9) {
transition-delay: 0.05s;
}
&:nth-child(10) {
transition-delay: 0s;
}
}
span {
transition: color 0.5s ease;
}
.btn-flip {
opacity: 1;
outline: 0;
color: #fff;
line-height: 40px;
position: relative;
text-align: center;
letter-spacing: 1px;
display: inline-block;
text-decoration: none;
font-family: 'Open Sans';
text-transform: uppercase;
&:hover {
&:after {
opacity: 1;
transform: translateY(0) rotateX(0);
}
&:before {
opacity: 0;
transform: translateY(50%) rotateX(90deg);
}
}
&:after {
top: 0;
left: 0;
opacity: 0;
width: 100%;
color: #323237;
display: block;
transition: 0.5s;
position: absolute;
background: #adadaf;
content: attr(data-back);
transform: translateY(-50%) rotateX(90deg);
}
&:before {
top: 0;
left: 0;
opacity: 1;
color: #adadaf;
display: block;
padding: 0 30px;
line-height: 40px;
transition: 0.5s;
position: relative;
background: #323237;
content: attr(data-front);
transform: translateY(0) rotateX(0);
}
}
<div class="menu">
<div class="spacer"></div>
<div class="item"><span>Twitter</span></div>
<div class="item"><span>Instagram</span></div>
<div class="item"><span>Flickr</span></div>
<div class="item"><span>Behance</span></div>
<div class="item"><span>MixCloud</span></div>
</div>
You can add the same rules inside .menu:
.menu {
...
&:hover {
.btn-flip {
&:after {
opacity: 1;
transform: translateY(0) rotateX(0);
}
&:before {
opacity: 0;
transform: translateY(50%) rotateX(90deg);
}
}

radio button and label

I'm not that much experienced in HTML and I wanted to use a designed radio Button.
So, I used these codes from a website and modified it a little bit.
The problem now is whenever I write a sentence in the label it is not appearing in the same line.
Do you have any idea why is that happening ?
Here are the codes
html {
font-family: "Segoe UI";
}
*, *::after, *::before {
box-sizing: border-box;
}
html, body {
height: 100%;
min-height: 100%;
}
body {
margin: 0;
font-family: 'Raleway', Arial, sans-serif;
}
.toggle-button {
position: relative;
display: inline-block;
color: black;
margin: 0 20px;
}
/*tested*/
.toggle-button label {
display: inline-block;
text-transform: uppercase;
cursor: pointer;
text-align: left;
}
/*tested*/
.toggle-button input {
display: none;
}
.toggle-button__icon {
cursor: pointer;
pointer-events: none;
}
/*to let radio button invites clicking*/
.toggle-button__icon:before, .toggle-button__icon:after {
content: "";
position: absolute;
transition: 0.200s ease-out;
}
/*to make radio button clickable*/
.toggle-button--maa label {
width: 110px; /*space between the options*/
height: 20px;
line-height: 20px; /*line spacing*/
transition: all 0.2s;
}
.toggle-button--maa label:before, .toggle-button--maa label:after {
position: absolute;
top: 0;
left: 30px;
width: 110px;
transition: all 0.2s .1s ease-out;
}
.toggle-button--maa label:before {
content: attr(data-text);
}
.toggle-button--maa input:checked ~ .toggle-button__icon:before {
animation: wave .7s ease-out;
}
.toggle-button--maa input:checked ~ .toggle-button__icon:after {
transform: scale(1);
animation: zoomIn .2s;
}
.toggle-button--maa .toggle-button__icon {
position: absolute;
left: 0;
top: 0;
height: 20px;
width: 20px;
border-radius: 50%;
background: #fff;
box-shadow: inset 1px 1px 10px rgba(0, 0, 0, 0.15);
}
.toggle-button--maa .toggle-button__icon:before, .toggle-button--maa .toggle-button__icon:after {
border-radius: 50%;
}
.toggle-button--maa .toggle-button__icon:before {
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(255, 255, 255, 0.8);
}
.toggle-button--maa .toggle-button__icon:after {
top: 4px;
left: 4px;
width: 60%;
height: 60%;
background: #61B136;
animation: zoomOut .2s ease-out;
transform: scale(0);
transition: none;
}
.toggle-button--maa:hover input:not(:checked) ~ .toggle-button__icon {
animation: hover .2s;
}
.toggle-button--maa:hover input:not(:checked) ~ label:before {
text-shadow: 0 1px 0 rgba(0, 0, 0, 0.2);
}
#keyframes zoomOut {
0% {
transform: scale(1);
}
30% {
transform: scale(1.2);
}
100% {
transform: scale(0);
}
}
#keyframes zoomIn {
0% {
transform: scale(0);
}
90% {
transform: scale(1.2);
}
100% {
transform: scale(1);
}
}
#keyframes hover {
0% {
transform: scale(1);
}
30% {
transform: scale(1.1);
}
100% {
transform: scale(1);
}
}
#keyframes wave {
0% {
opacity: 1;
transform: scale(1);
}
40% {
opacity: 0.2;
}
100% {
opacity: 0;
transform: scale(1.5);
}
}
#keyframes zoomFadeOut {
0% {
opacity: 1;
}
100% {
opacity: 0;
}
}
#keyframes zoomFadeIn {
0% {
opacity: 0;
transform: scale(3);
}
90% {
opacity: 1;
transform: scale(1);
}
100% {
transform: scale(1);
}
}
#keyframes hover {
0% {
transform: scale(1);
}
30% {
transform: scale(1.1);
}
100% {
transform: scale(1);
}
<div id="ButtonsDiv" class="auto-style4" >
<div class="toggle-button toggle-button--maa">
<input id="toggleButton7" name="radio3" type="radio"/>
<label for="toggleButton7" data-text="Bachelor accounting student" ></label>
<div class="toggle-button__icon"></div>
</div>
<div class="toggle-button toggle-button--maa">
<input id="toggleButton8" name="radio3" type="radio"/>
<label for="toggleButton8" data-text="Bachelor finance student" class="auto-style5"></label>
<div class="toggle-button__icon"></div>
</div>
</div>
The problem is that you set the label and the :before fixed width. Also, you set position:absolute to the :before element.
html {
font-family: "Segoe UI";
}
*, *::after, *::before {
box-sizing: border-box;
}
html, body {
height: 100%;
min-height: 100%;
}
body {
margin: 0;
font-family: 'Raleway', Arial, sans-serif;
}
.toggle-button {
position: relative;
display: inline-block;
color: black;
margin: 0 20px;
}
/*tested*/
.toggle-button label {
display: inline-block;
text-transform: uppercase;
cursor: pointer;
text-align: left;
}
/*tested*/
.toggle-button input {
display: none;
}
.toggle-button__icon {
cursor: pointer;
pointer-events: none;
}
/*to let radio button invites clicking*/
.toggle-button__icon:before, .toggle-button__icon:after {
content: "";
position: absolute;
transition: 0.200s ease-out;
}
/*to make radio button clickable*/
.toggle-button--maa label {
height: 20px;
line-height: 20px; /*line spacing*/
transition: all 0.2s;
}
.toggle-button--maa label:before, .toggle-button--maa label:after {
margin-left:25px;
transition: all 0.2s .1s ease-out;
}
.toggle-button--maa label:before {
content: attr(data-text);
}
.toggle-button--maa input:checked ~ .toggle-button__icon:before,
.toggle-button--maa:hover input ~ .toggle-button__icon:before{
animation: wave .7s ease-out;
}
.toggle-button--maa input:checked ~ .toggle-button__icon:after,
.toggle-button--maa:hover input ~ .toggle-button__icon:after {
transform: scale(1);
animation: zoomIn .2s;
}
.toggle-button--maa .toggle-button__icon {
position: absolute;
left: 0;
top: 0;
height: 20px;
width: 20px;
border-radius: 50%;
background: #fff;
box-shadow: inset 1px 1px 10px rgba(0, 0, 0, 0.15);
}
.toggle-button--maa .toggle-button__icon:before, .toggle-button--maa .toggle-button__icon:after {
border-radius: 50%;
}
.toggle-button--maa .toggle-button__icon:before {
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(255, 255, 255, 0.8);
}
.toggle-button--maa .toggle-button__icon:after {
top: 4px;
left: 4px;
width: 60%;
height: 60%;
background: #61B136;
animation: zoomOut .2s ease-out;
transform: scale(0);
transition: none;
}
/*.toggle-button--maa:hover input:not(:checked) ~ .toggle-button__icon:after {
background:#CACACA;
transform: scale(1);
animation: zoomIn .2s;
}*/
/*.toggle-button--maa:hover input:not(:checked) ~ .toggle-button__icon {
animation: hover .2s;
}*/
.toggle-button--maa:hover input:not(:checked) ~ label:before {
text-shadow: 0 1px 0 rgba(0, 0, 0, 0.2);
}
#keyframes zoomOut {
0% {
transform: scale(1);
}
30% {
transform: scale(1.2);
}
100% {
transform: scale(0);
}
}
#keyframes zoomIn {
0% {
transform: scale(0);
}
90% {
transform: scale(1.2);
}
100% {
transform: scale(1);
}
}
#keyframes hover {
0% {
transform: scale(1);
}
30% {
transform: scale(1.1);
}
100% {
transform: scale(1);
}
}
#keyframes wave {
0% {
opacity: 1;
transform: scale(1);
}
40% {
opacity: 0.2;
}
100% {
opacity: 0;
transform: scale(1.5);
}
}
#keyframes zoomFadeOut {
0% {
opacity: 1;
}
100% {
opacity: 0;
}
}
#keyframes zoomFadeIn {
0% {
opacity: 0;
transform: scale(3);
}
90% {
opacity: 1;
transform: scale(1);
}
100% {
transform: scale(1);
}
}
#keyframes hover {
0% {
transform: scale(1);
}
30% {
transform: scale(1.1);
}
100% {
transform: scale(1);
}
<div id="ButtonsDiv" class="auto-style4" >
<div class="toggle-button toggle-button--maa">
<input id="toggleButton7" name="radio3" type="radio"/>
<label for="toggleButton7" data-text="Bachelor accounting student" ></label>
<div class="toggle-button__icon"></div>
</div>
<div class="toggle-button toggle-button--maa">
<input id="toggleButton8" name="radio3" type="radio"/>
<label for="toggleButton8" data-text="Bachelor finance student" class="auto-style5"></label>
<div class="toggle-button__icon"></div>
</div>
</div>