why is this html and css rendering differently on my webpage? - html

I really liked the toggle switch "Example 3" on this website and they provide the HTML/CSS code with it. Although, when I try it on my webpage it renders as a simple plain checkbox.
I have beginners knowledge of HTML/CSS but the code makes sense and I'm not sure what is wrong.
This is the code and the website attached on the bottom. Example 3 is what it's supposed to look like.
<style>
/* Switch Yes No
==========================*/
.switch-yes-no {
padding: 0;
margin: 15px 0 0;
background: #FFF;
border-radius: 0;
background-image: none;
}
.switch-yes-no .switch-label {
box-shadow: none;
background: none;
}
.switch-yes-no .switch-label:after, .switch-yes-no .switch-label:before {
width: 100%;
height: 70%;
top: 5px;
left: 0;
text-align: center;
padding-top: 10%;
box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.2), inset 0 0 3px rgba(0, 0, 0, 0.1);
}
.switch-yes-no .switch-label:after {
color: #FFFFFF;
background: #32CD32;
backface-visibility: hidden;
transform: rotateY(180deg);
}
.switch-yes-no .switch-label:before {
background: #eceeef;
backface-visibility: hidden;
}
.switch-yes-no .switch-handle {
display: none;
}
.switch-yes-no .switch-input:checked ~ .switch-label {
background: #FFF;
border-color: #0088cc;
}
.switch-yes-no .switch-input:checked ~ .switch-label:before {
transform: rotateY(180deg)
}
.switch-yes-no .switch-input:checked ~ .switch-label:after {
transform: rotateY(0)
}
</style>
<label class="switch switch-yes-no">
<input class="switch-input" type="checkbox" />
<span class="switch-label" data-on="Yes" data-off="No"></span>
<span class="switch-handle"></span>
</label>
Example 3 on this website in case needed
Example 3

You need to read the instruction carefully. On the top of the page you have a part The Common CSS. This style must be used for all examples below.
For example 3 you need to add the part you have used.
.switch {
position: relative;
display: block;
vertical-align: top;
width: 100px;
height: 30px;
padding: 3px;
margin: 0 10px 10px 0;
background: linear-gradient(to bottom, #eeeeee, #FFFFFF 25px);
background-image: -webkit-linear-gradient(top, #eeeeee, #FFFFFF 25px);
border-radius: 18px;
box-shadow: inset 0 -1px white, inset 0 1px 1px rgba(0, 0, 0, 0.05);
cursor: pointer;
box-sizing:content-box;
}
.switch-input {
position: absolute;
top: 0;
left: 0;
opacity: 0;
box-sizing:content-box;
}
.switch-label {
position: relative;
display: block;
height: inherit;
font-size: 10px;
text-transform: uppercase;
background: #eceeef;
border-radius: inherit;
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.12), inset 0 0 2px rgba(0, 0, 0, 0.15);
box-sizing:content-box;
}
.switch-label:before, .switch-label:after {
position: absolute;
top: 50%;
margin-top: -.5em;
line-height: 1;
-webkit-transition: inherit;
-moz-transition: inherit;
-o-transition: inherit;
transition: inherit;
box-sizing:content-box;
}
.switch-label:before {
content: attr(data-off);
right: 11px;
color: #aaaaaa;
text-shadow: 0 1px rgba(255, 255, 255, 0.5);
}
.switch-label:after {
content: attr(data-on);
left: 11px;
color: #FFFFFF;
text-shadow: 0 1px rgba(0, 0, 0, 0.2);
opacity: 0;
}
.switch-input:checked ~ .switch-label {
background: #E1B42B;
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.15), inset 0 0 3px rgba(0, 0, 0, 0.2);
}
.switch-input:checked ~ .switch-label:before {
opacity: 0;
}
.switch-input:checked ~ .switch-label:after {
opacity: 1;
}
.switch-handle {
position: absolute;
top: 4px;
left: 4px;
width: 28px;
height: 28px;
background: linear-gradient(to bottom, #FFFFFF 40%, #f0f0f0);
background-image: -webkit-linear-gradient(top, #FFFFFF 40%, #f0f0f0);
border-radius: 100%;
box-shadow: 1px 1px 5px rgba(0, 0, 0, 0.2);
}
.switch-handle:before {
content: "";
position: absolute;
top: 50%;
left: 50%;
margin: -6px 0 0 -6px;
width: 12px;
height: 12px;
background: linear-gradient(to bottom, #eeeeee, #FFFFFF);
background-image: -webkit-linear-gradient(top, #eeeeee, #FFFFFF);
border-radius: 6px;
box-shadow: inset 0 1px rgba(0, 0, 0, 0.02);
}
.switch-input:checked ~ .switch-handle {
left: 74px;
box-shadow: -1px 1px 5px rgba(0, 0, 0, 0.2);
}
/* Transition
========================== */
.switch-label, .switch-handle {
transition: All 0.3s ease;
-webkit-transition: All 0.3s ease;
-moz-transition: All 0.3s ease;
-o-transition: All 0.3s ease;
}
.switch-yes-no {
padding: 0;
margin: 15px 0 0;
background: #FFF;
border-radius: 0;
background-image: none;
}
.switch-yes-no .switch-label {
box-shadow: none;
background: none;
}
.switch-yes-no .switch-label:after, .switch-yes-no .switch-label:before {
width: 100%;
height: 70%;
top: 5px;
left: 0;
text-align: center;
padding-top: 10%;
box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.2), inset 0 0 3px rgba(0, 0, 0, 0.1);
}
.switch-yes-no .switch-label:after {
color: #FFFFFF;
background: #32CD32;
backface-visibility: hidden;
transform: rotateY(180deg);
}
.switch-yes-no .switch-label:before {
background: #eceeef;
backface-visibility: hidden;
}
.switch-yes-no .switch-handle {
display: none;
}
.switch-yes-no .switch-input:checked ~ .switch-label {
background: #FFF;
border-color: #0088cc;
}
.switch-yes-no .switch-input:checked ~ .switch-label:before {
transform: rotateY(180deg)
}
.switch-yes-no .switch-input:checked ~ .switch-label:after {
transform: rotateY(0)
}
<label class="switch switch-yes-no">
<input class="switch-input" type="checkbox" />
<span class="switch-label" data-on="Yes" data-off="No"></span>
<span class="switch-handle"></span>
</label>

Yes, as the other answers suggest.. You need to add proper styling i.e., all the style classes or files needed. Also, I would like to add that include these files in their proper order inside your project. Remember, order is very important.

Related

how do I reposition a styled label to a corner of its div?

How would I move the content inside of .toggle-button to the far right lower corner?
I am new to html and css but from what I understand I've played around with the flex settings, margins, and paddings and I'm not having any luck figuring this out
Here is my code. I am only concerned with the page-header div (color blue border) and the toggle-button div (color purple)
.mypage{
border: 1px solid black;
}
.row {
margin: 10px;
width: 100%;
}
.page-header {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
border: 1px solid blue;
margin-right: 1vh;
}
.date-dropdown{
border: 1px solid red;
flex-grow: 1;
display: flex;
}
.dates-label {
font-size: large;
font-family: Arial, Helvetica, sans-serif;
}
.dates-select {
margin-left: 1vh;
}
.title-wrapper {
border: 1px solid orange;
flex-grow: 1;
text-align: center;
}
.toggle-button{
border: 1px solid purple;
flex-grow: 1;
}
/* ============= TOGGLE Button ======= */
.switch {
position: relative;
display: block;
vertical-align: top;
width: 100px;
height: 30px;
padding: 3px;
margin: 0 10px 10px 0;
background: linear-gradient(to bottom, #eeeeee, #FFFFFF 25px);
background-image: -webkit-linear-gradient(top, #eeeeee, #FFFFFF 25px);
border-radius: 18px;
box-shadow: inset 0 -1px white, inset 0 1px 1px rgba(0, 0, 0, 0.05);
cursor: pointer;
box-sizing:content-box;
}
.switch-input {
position: absolute;
top: 0;
left: 0;
opacity: 0;
box-sizing:content-box;
}
.switch-label {
position: relative;
display: block;
height: inherit;
font-size: 10px;
text-transform: uppercase;
background: #eceeef;
border-radius: inherit;
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.12), inset 0 0 2px rgba(0, 0, 0, 0.15);
box-sizing:content-box;
}
.switch-label:before, .switch-label:after {
position: absolute;
top: 50%;
margin-top: -.5em;
line-height: 1;
-webkit-transition: inherit;
-moz-transition: inherit;
-o-transition: inherit;
transition: inherit;
box-sizing:content-box;
}
.switch-label:before {
content: attr(data-off);
right: 11px;
color: #aaaaaa;
text-shadow: 0 1px rgba(255, 255, 255, 0.5);
}
.switch-label:after {
content: attr(data-on);
left: 11px;
color: #FFFFFF;
text-shadow: 0 1px rgba(0, 0, 0, 0.2);
opacity: 0;
}
.switch-input:checked ~ .switch-label {
background: #E1B42B;
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.15), inset 0 0 3px rgba(0, 0, 0, 0.2);
}
.switch-input:checked ~ .switch-label:before {
opacity: 0;
}
.switch-input:checked ~ .switch-label:after {
opacity: 1;
}
.switch-handle {
position: absolute;
top: 4px;
left: 4px;
width: 28px;
height: 28px;
background: linear-gradient(to bottom, #FFFFFF 40%, #f0f0f0);
background-image: -webkit-linear-gradient(top, #FFFFFF 40%, #f0f0f0);
border-radius: 100%;
box-shadow: 1px 1px 5px rgba(0, 0, 0, 0.2);
}
.switch-handle:before {
content: "";
position: absolute;
top: 50%;
left: 50%;
margin: -6px 0 0 -6px;
width: 12px;
height: 12px;
background: linear-gradient(to bottom, #eeeeee, #FFFFFF);
background-image: -webkit-linear-gradient(top, #eeeeee, #FFFFFF);
border-radius: 6px;
box-shadow: inset 0 1px rgba(0, 0, 0, 0.02);
}
.switch-input:checked ~ .switch-handle {
left: 74px;
box-shadow: -1px 1px 5px rgba(0, 0, 0, 0.2);
}
/* Transition
========================== */
.switch-label, .switch-handle {
transition: All 0.3s ease;
-webkit-transition: All 0.3s ease;
-moz-transition: All 0.3s ease;
-o-transition: All 0.3s ease;
}
.switch-yes-no {
padding: 0;
margin: 15px 0 0;
background: #FFF;
border-radius: 0;
background-image: none;
}
.switch-yes-no .switch-label {
box-shadow: none;
background: none;
}
.switch-yes-no .switch-label:after, .switch-yes-no .switch-label:before {
width: 100%;
height: 70%;
top: 5px;
left: 0;
text-align: center;
padding-top: 10%;
box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.2), inset 0 0 3px rgba(0, 0, 0, 0.1);
}
.switch-yes-no .switch-label:after {
color: #FFFFFF;
background: #32CD32;
backface-visibility: hidden;
transform: rotateY(180deg);
}
.switch-yes-no .switch-label:before {
background: #eceeef;
backface-visibility: hidden;
}
.switch-yes-no .switch-handle {
display: none;
}
.switch-yes-no .switch-input:checked ~ .switch-label {
background: #FFF;
border-color: #0088cc;
}
.switch-yes-no .switch-input:checked ~ .switch-label:before {
transform: rotateY(180deg)
}
.switch-yes-no .switch-input:checked ~ .switch-label:after {
transform: rotateY(0)
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>HTML5 boilerplate – all you really need…</title>
<link rel="stylesheet" href="css/styles.css">
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body id="home">
<div class="mypage">
<div class="row">
<div class="page-header">
<div class="date-dropdown">
<div class="dates-label">
<label for="dropdown">
Choose a date
</label>
</div>
<div class="dates-select">
<select name="dropdown" id="datesid">
<option>option 1</option>
<option>option 2</option>
<option>option 3</option>
</select>
</div>
</div>
<div class="title-wrapper">
<h1>Welcome</h1>
</div>
<div class="toggle-button">
<label class="switch switch-yes-no">
<input class="switch-input" type="checkbox" />
<span class="switch-label" data-on="Yes" data-off="No"></span>
<span class="switch-handle"></span>
</label>
</div>
</div>
</div>
<div class="row">
<div class="table-pie-wrapper">
<div class="table">
i am a table
</div>
<div class="pie-graph">
i am a pie graph
</div>
</div>
</div>
<div class="row">
<div class="table-summary-wrapper">
<div class="table-summary">
i am a table summary
</div>
</div>
</div>
</div>
</body>
</html>
I addded following css rules toggle-button class
display: flex;
justify-content: end;
Please check the following code snippet
.mypage{
border: 1px solid black;
}
.row {
margin: 10px;
width: 100%;
}
.page-header {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
border: 1px solid blue;
margin-right: 1vh;
}
.date-dropdown{
border: 1px solid red;
flex-grow: 1;
display: flex;
}
.dates-label {
font-size: large;
font-family: Arial, Helvetica, sans-serif;
}
.dates-select {
margin-left: 1vh;
}
.title-wrapper {
border: 1px solid orange;
flex-grow: 1;
text-align: center;
}
.toggle-button{
border: 1px solid purple;
flex-grow: 1;
display: flex;
justify-content: end;
}
/* ============= TOGGLE Button ======= */
.switch {
position: relative;
display: block;
vertical-align: top;
width: 100px;
height: 30px;
padding: 3px;
margin: 0 10px 10px 0;
background: linear-gradient(to bottom, #eeeeee, #FFFFFF 25px);
background-image: -webkit-linear-gradient(top, #eeeeee, #FFFFFF 25px);
border-radius: 18px;
box-shadow: inset 0 -1px white, inset 0 1px 1px rgba(0, 0, 0, 0.05);
cursor: pointer;
box-sizing:content-box;
}
.switch-input {
position: absolute;
top: 0;
left: 0;
opacity: 0;
box-sizing:content-box;
}
.switch-label {
position: relative;
display: block;
height: inherit;
font-size: 10px;
text-transform: uppercase;
background: #eceeef;
border-radius: inherit;
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.12), inset 0 0 2px rgba(0, 0, 0, 0.15);
box-sizing:content-box;
text-align: right;
background-color: red;
}
.switch-label:before, .switch-label:after {
position: absolute;
top: 50%;
margin-top: -.5em;
line-height: 1;
-webkit-transition: inherit;
-moz-transition: inherit;
-o-transition: inherit;
transition: inherit;
box-sizing:content-box;
}
.switch-label:before {
content: attr(data-off);
right: 11px;
color: #aaaaaa;
text-shadow: 0 1px rgba(255, 255, 255, 0.5);
}
.switch-label:after {
content: attr(data-on);
left: 11px;
color: #FFFFFF;
text-shadow: 0 1px rgba(0, 0, 0, 0.2);
opacity: 0;
}
.switch-input:checked ~ .switch-label {
background: #E1B42B;
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.15), inset 0 0 3px rgba(0, 0, 0, 0.2);
}
.switch-input:checked ~ .switch-label:before {
opacity: 0;
}
.switch-input:checked ~ .switch-label:after {
opacity: 1;
}
.switch-handle {
position: absolute;
top: 4px;
left: 4px;
width: 28px;
height: 28px;
background: linear-gradient(to bottom, #FFFFFF 40%, #f0f0f0);
background-image: -webkit-linear-gradient(top, #FFFFFF 40%, #f0f0f0);
border-radius: 100%;
box-shadow: 1px 1px 5px rgba(0, 0, 0, 0.2);
}
.switch-handle:before {
content: "";
position: absolute;
top: 50%;
left: 50%;
margin: -6px 0 0 -6px;
width: 12px;
height: 12px;
background: linear-gradient(to bottom, #eeeeee, #FFFFFF);
background-image: -webkit-linear-gradient(top, #eeeeee, #FFFFFF);
border-radius: 6px;
box-shadow: inset 0 1px rgba(0, 0, 0, 0.02);
}
.switch-input:checked ~ .switch-handle {
left: 74px;
box-shadow: -1px 1px 5px rgba(0, 0, 0, 0.2);
}
/* Transition
========================== */
.switch-label, .switch-handle {
transition: All 0.3s ease;
-webkit-transition: All 0.3s ease;
-moz-transition: All 0.3s ease;
-o-transition: All 0.3s ease;
}
.switch-yes-no {
padding: 0;
margin: 15px 0 0;
background: #FFF;
border-radius: 0;
background-image: none;
}
.switch-yes-no .switch-label {
box-shadow: none;
background: none;
}
.switch-yes-no .switch-label:after, .switch-yes-no .switch-label:before {
width: 100%;
height: 70%;
top: 5px;
left: 0;
text-align: center;
padding-top: 10%;
box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.2), inset 0 0 3px rgba(0, 0, 0, 0.1);
}
.switch-yes-no .switch-label:after {
color: #FFFFFF;
background: #32CD32;
backface-visibility: hidden;
transform: rotateY(180deg);
}
.switch-yes-no .switch-label:before {
background: #eceeef;
backface-visibility: hidden;
}
.switch-yes-no .switch-handle {
display: none;
}
.switch-yes-no .switch-input:checked ~ .switch-label {
background: #FFF;
border-color: #0088cc;
}
.switch-yes-no .switch-input:checked ~ .switch-label:before {
transform: rotateY(180deg)
}
.switch-yes-no .switch-input:checked ~ .switch-label:after {
transform: rotateY(0)
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>HTML5 boilerplate – all you really need…</title>
<link rel="stylesheet" href="css/styles.css">
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body id="home">
<div class="mypage">
<div class="row">
<div class="page-header">
<div class="date-dropdown">
<div class="dates-label">
<label for="dropdown">
Choose a date
</label>
</div>
<div class="dates-select">
<select name="dropdown" id="datesid">
<option>option 1</option>
<option>option 2</option>
<option>option 3</option>
</select>
</div>
</div>
<div class="title-wrapper">
<h1>Welcome</h1>
</div>
<div class="toggle-button">
<label class="switch switch-yes-no">
<input class="switch-input" type="checkbox" />
<span class="switch-label" data-on="Yes" data-off="No"></span>
<span class="switch-handle"></span>
</label>
</div>
</div>
</div>
<div class="row">
<div class="table-pie-wrapper">
<div class="table">
i am a table
</div>
<div class="pie-graph">
i am a pie graph
</div>
</div>
</div>
<div class="row">
<div class="table-summary-wrapper">
<div class="table-summary">
i am a table summary
</div>
</div>
</div>
</div>
</body>
</html>
You can achieve this with margin-left: auto or in the shorthand that you used:
.switch-yes-no {
...
margin: 15px 0 0 auto;
}
Working example:
.mypage {
border: 1px solid black;
}
.row {
margin: 10px;
width: 100%;
}
.page-header {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
border: 1px solid blue;
margin-right: 1vh;
}
.date-dropdown {
border: 1px solid red;
flex-grow: 1;
display: flex;
}
.dates-label {
font-size: large;
font-family: Arial, Helvetica, sans-serif;
}
.dates-select {
margin-left: 1vh;
}
.title-wrapper {
border: 1px solid orange;
flex-grow: 1;
text-align: center;
}
.toggle-button {
border: 1px solid purple;
flex-grow: 1;
}
/* ============= TOGGLE Button ======= */
.switch {
position: relative;
display: block;
vertical-align: top;
width: 100px;
height: 30px;
padding: 3px;
margin: 0 10px 10px 0;
background: linear-gradient(to bottom, #eeeeee, #FFFFFF 25px);
background-image: -webkit-linear-gradient(top, #eeeeee, #FFFFFF 25px);
border-radius: 18px;
box-shadow: inset 0 -1px white, inset 0 1px 1px rgba(0, 0, 0, 0.05);
cursor: pointer;
box-sizing: content-box;
}
.switch-input {
position: absolute;
top: 0;
left: 0;
opacity: 0;
box-sizing: content-box;
}
.switch-label {
position: relative;
display: block;
height: inherit;
font-size: 10px;
text-transform: uppercase;
background: #eceeef;
border-radius: inherit;
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.12), inset 0 0 2px rgba(0, 0, 0, 0.15);
box-sizing: content-box;
}
.switch-label:before,
.switch-label:after {
position: absolute;
top: 50%;
margin-top: -.5em;
line-height: 1;
-webkit-transition: inherit;
-moz-transition: inherit;
-o-transition: inherit;
transition: inherit;
box-sizing: content-box;
}
.switch-label:before {
content: attr(data-off);
right: 11px;
color: #aaaaaa;
text-shadow: 0 1px rgba(255, 255, 255, 0.5);
}
.switch-label:after {
content: attr(data-on);
left: 11px;
color: #FFFFFF;
text-shadow: 0 1px rgba(0, 0, 0, 0.2);
opacity: 0;
}
.switch-input:checked~.switch-label {
background: #E1B42B;
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.15), inset 0 0 3px rgba(0, 0, 0, 0.2);
}
.switch-input:checked~.switch-label:before {
opacity: 0;
}
.switch-input:checked~.switch-label:after {
opacity: 1;
}
.switch-handle {
position: absolute;
top: 4px;
left: 4px;
width: 28px;
height: 28px;
background: linear-gradient(to bottom, #FFFFFF 40%, #f0f0f0);
background-image: -webkit-linear-gradient(top, #FFFFFF 40%, #f0f0f0);
border-radius: 100%;
box-shadow: 1px 1px 5px rgba(0, 0, 0, 0.2);
}
.switch-handle:before {
content: "";
position: absolute;
top: 50%;
left: 50%;
margin: -6px 0 0 -6px;
width: 12px;
height: 12px;
background: linear-gradient(to bottom, #eeeeee, #FFFFFF);
background-image: -webkit-linear-gradient(top, #eeeeee, #FFFFFF);
border-radius: 6px;
box-shadow: inset 0 1px rgba(0, 0, 0, 0.02);
}
.switch-input:checked~.switch-handle {
left: 74px;
box-shadow: -1px 1px 5px rgba(0, 0, 0, 0.2);
}
/* Transition
========================== */
.switch-label,
.switch-handle {
transition: All 0.3s ease;
-webkit-transition: All 0.3s ease;
-moz-transition: All 0.3s ease;
-o-transition: All 0.3s ease;
}
.switch-yes-no {
padding: 0;
margin: 15px 0 0 auto;
background: #FFF;
border-radius: 0;
background-image: none;
}
.switch-yes-no .switch-label {
box-shadow: none;
background: none;
}
.switch-yes-no .switch-label:after,
.switch-yes-no .switch-label:before {
width: 100%;
height: 70%;
top: 5px;
left: 0;
text-align: center;
padding-top: 10%;
box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.2), inset 0 0 3px rgba(0, 0, 0, 0.1);
}
.switch-yes-no .switch-label:after {
color: #FFFFFF;
background: #32CD32;
backface-visibility: hidden;
transform: rotateY(180deg);
}
.switch-yes-no .switch-label:before {
background: #eceeef;
backface-visibility: hidden;
}
.switch-yes-no .switch-handle {
display: none;
}
.switch-yes-no .switch-input:checked~.switch-label {
background: #FFF;
border-color: #0088cc;
}
.switch-yes-no .switch-input:checked~.switch-label:before {
transform: rotateY(180deg)
}
.switch-yes-no .switch-input:checked~.switch-label:after {
transform: rotateY(0)
}
<div class="mypage">
<div class="row">
<div class="page-header">
<div class="date-dropdown">
<div class="dates-label">
<label for="dropdown">
Choose a date
</label>
</div>
<div class="dates-select">
<select name="dropdown" id="datesid">
<option>option 1</option>
<option>option 2</option>
<option>option 3</option>
</select>
</div>
</div>
<div class="title-wrapper">
<h1>Welcome</h1>
</div>
<div class="toggle-button">
<label class="switch switch-yes-no">
<input class="switch-input" type="checkbox" />
<span class="switch-label" data-on="Yes" data-off="No"></span>
<span class="switch-handle"></span>
</label>
</div>
</div>
</div>
<div class="row">
<div class="table-pie-wrapper">
<div class="table">
i am a table
</div>
<div class="pie-graph">
i am a pie graph
</div>
</div>
</div>
<div class="row">
<div class="table-summary-wrapper">
<div class="table-summary">
i am a table summary
</div>
</div>
</div>
</div>
If you want the whole button to be in the right bottom corner you can use align-self: flex-end:
.toggle-button {
...
align-self: flex-end;
}
Working example:
.mypage {
border: 1px solid black;
}
.row {
margin: 10px;
width: 100%;
}
.page-header {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
border: 1px solid blue;
margin-right: 1vh;
}
.date-dropdown {
border: 1px solid red;
flex-grow: 1;
display: flex;
}
.dates-label {
font-size: large;
font-family: Arial, Helvetica, sans-serif;
}
.dates-select {
margin-left: 1vh;
}
.title-wrapper {
border: 1px solid orange;
flex-grow: 1;
text-align: center;
}
.toggle-button {
border: 1px solid purple;
flex-grow: 1;
align-self: flex-end;
}
/* ============= TOGGLE Button ======= */
.switch {
position: relative;
display: block;
vertical-align: top;
width: 100px;
height: 30px;
padding: 3px;
margin: 0 10px 10px 0;
background: linear-gradient(to bottom, #eeeeee, #FFFFFF 25px);
background-image: -webkit-linear-gradient(top, #eeeeee, #FFFFFF 25px);
border-radius: 18px;
box-shadow: inset 0 -1px white, inset 0 1px 1px rgba(0, 0, 0, 0.05);
cursor: pointer;
box-sizing: content-box;
}
.switch-input {
position: absolute;
top: 0;
left: 0;
opacity: 0;
box-sizing: content-box;
}
.switch-label {
position: relative;
display: block;
height: inherit;
font-size: 10px;
text-transform: uppercase;
background: #eceeef;
border-radius: inherit;
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.12), inset 0 0 2px rgba(0, 0, 0, 0.15);
box-sizing: content-box;
}
.switch-label:before,
.switch-label:after {
position: absolute;
top: 50%;
margin-top: -.5em;
line-height: 1;
-webkit-transition: inherit;
-moz-transition: inherit;
-o-transition: inherit;
transition: inherit;
box-sizing: content-box;
}
.switch-label:before {
content: attr(data-off);
right: 11px;
color: #aaaaaa;
text-shadow: 0 1px rgba(255, 255, 255, 0.5);
}
.switch-label:after {
content: attr(data-on);
left: 11px;
color: #FFFFFF;
text-shadow: 0 1px rgba(0, 0, 0, 0.2);
opacity: 0;
}
.switch-input:checked~.switch-label {
background: #E1B42B;
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.15), inset 0 0 3px rgba(0, 0, 0, 0.2);
}
.switch-input:checked~.switch-label:before {
opacity: 0;
}
.switch-input:checked~.switch-label:after {
opacity: 1;
}
.switch-handle {
position: absolute;
top: 4px;
left: 4px;
width: 28px;
height: 28px;
background: linear-gradient(to bottom, #FFFFFF 40%, #f0f0f0);
background-image: -webkit-linear-gradient(top, #FFFFFF 40%, #f0f0f0);
border-radius: 100%;
box-shadow: 1px 1px 5px rgba(0, 0, 0, 0.2);
}
.switch-handle:before {
content: "";
position: absolute;
top: 50%;
left: 50%;
margin: -6px 0 0 -6px;
width: 12px;
height: 12px;
background: linear-gradient(to bottom, #eeeeee, #FFFFFF);
background-image: -webkit-linear-gradient(top, #eeeeee, #FFFFFF);
border-radius: 6px;
box-shadow: inset 0 1px rgba(0, 0, 0, 0.02);
}
.switch-input:checked~.switch-handle {
left: 74px;
box-shadow: -1px 1px 5px rgba(0, 0, 0, 0.2);
}
/* Transition
========================== */
.switch-label,
.switch-handle {
transition: All 0.3s ease;
-webkit-transition: All 0.3s ease;
-moz-transition: All 0.3s ease;
-o-transition: All 0.3s ease;
}
.switch-yes-no {
padding: 0;
margin: 15px 0 0;
background: #FFF;
border-radius: 0;
background-image: none;
}
.switch-yes-no .switch-label {
box-shadow: none;
background: none;
}
.switch-yes-no .switch-label:after,
.switch-yes-no .switch-label:before {
width: 100%;
height: 70%;
top: 5px;
left: 0;
text-align: center;
padding-top: 10%;
box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.2), inset 0 0 3px rgba(0, 0, 0, 0.1);
}
.switch-yes-no .switch-label:after {
color: #FFFFFF;
background: #32CD32;
backface-visibility: hidden;
transform: rotateY(180deg);
}
.switch-yes-no .switch-label:before {
background: #eceeef;
backface-visibility: hidden;
}
.switch-yes-no .switch-handle {
display: none;
}
.switch-yes-no .switch-input:checked~.switch-label {
background: #FFF;
border-color: #0088cc;
}
.switch-yes-no .switch-input:checked~.switch-label:before {
transform: rotateY(180deg)
}
.switch-yes-no .switch-input:checked~.switch-label:after {
transform: rotateY(0)
}
<div class="mypage">
<div class="row">
<div class="page-header">
<div class="date-dropdown">
<div class="dates-label">
<label for="dropdown">
Choose a date
</label>
</div>
<div class="dates-select">
<select name="dropdown" id="datesid">
<option>option 1</option>
<option>option 2</option>
<option>option 3</option>
</select>
</div>
</div>
<div class="title-wrapper">
<h1>Welcome</h1>
</div>
<div class="toggle-button">
<label class="switch switch-yes-no">
<input class="switch-input" type="checkbox" />
<span class="switch-label" data-on="Yes" data-off="No"></span>
<span class="switch-handle"></span>
</label>
</div>
</div>
</div>
<div class="row">
<div class="table-pie-wrapper">
<div class="table">
i am a table
</div>
<div class="pie-graph">
i am a pie graph
</div>
</div>
</div>
<div class="row">
<div class="table-summary-wrapper">
<div class="table-summary">
i am a table summary
</div>
</div>
</div>
</div>

Display tooltip on hover in cutom toggle switch

I have a custom toggle switch created
When I mousehover on it if the switch is ON its should display the message on tooltip as YES and if OFF tooltip meassage should be NO.
How can I acheive this in custom toggle switch?
.switch {
position: relative;
width: 80px;
height: 30px;
background: #FFF;
background-image: -webkit-linear-gradient(top, #eeeeee, #FFFFFF 25px);
border-radius: 18px;
box-shadow: inset 0 -1px white, inset 0 1px 1px rgba(0, 0, 0, 0.05);
cursor: pointer;
float: left;
bottom: 3px;
right: 0;
}
.switch-input {
position: absolute;
left: 0;
opacity: 0;
}
.switch-label {
position: relative;
display: block;
height: inherit;
font-size: 10px;
text-transform: uppercase;
background: #eceeef;
border-radius: inherit;
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.12), inset 0 0 2px rgba(0, 0, 0, 0.15);
}
.switch-label:before, .switch-label:after {
position: absolute;
top: 50%;
margin-top: -.5em;
line-height: 1;
-webkit-transition: inherit;
-moz-transition: inherit;
-o-transition: inherit;
transition: inherit;
}
.switch-label:before {
content: attr(data-off);
right: 11px;
color: #aaaaaa;
text-shadow: 0 1px rgba(255, 255, 255, 0.5);
}
.switch-label:after {
content: attr(data-on);
left: 11px;
color: #FFFFFF;
text-shadow: 0 1px rgba(0, 0, 0, 0.2);
opacity: 0;
}
.switch-input:checked ~ .switch-label {
background: #E1B42B;
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.15), inset 0 0 3px rgba(0, 0, 0, 0.2);
}
.switch-input:checked ~ .switch-label:before {
opacity: 0;
}
.switch-input:checked ~ .switch-label:after {
opacity: 1;
}
.switch-handle {
position: absolute;
top: 1px;
right: 100px;
width: 25px;
height: 28px;
background: linear-gradient(to bottom, #FFFFFF 40%, #f0f0f0);
background-image: -webkit-linear-gradient(top, #FFFFFF 40%, #f0f0f0);
border-radius: 100%;
box-shadow: 1px 1px 5px rgba(0, 0, 0, 0.2);
}
.switch-handle:before {
content: "";
position: absolute;
top: 50%;
left: 50%;
margin: -6px 0 0 -6px;
width: 12px;
height: 12px;
background: linear-gradient(to bottom, #eeeeee, #FFFFFF);
background-image: -webkit-linear-gradient(top, #eeeeee, #FFFFFF);
border-radius: 6px;
box-shadow: inset 0 1px rgba(0, 0, 0, 0.02);
}
.switch-input:checked ~ .switch-handle {
left: 50px;
box-shadow: -1px 1px 5px rgba(0, 0, 0, 0.2);
}
/* transitions */
.switch-label, .switch-handle {
transition: All 0.3s ease;
-webkit-transition: All 0.3s ease;
-moz-transition: All 0.3s ease;
-o-transition: All 0.3s ease;
}
.switch-flat {
padding: 0;
background: #FFF;
background-image: none;
}
.switch-flat .switch-label {
background: #FFF;
border: solid 2px #eceeef;
box-shadow: none;
}
.switch-flat .switch-label:after {
color: #0088cc;
}
.switch-flat .switch-handle {
top: 4px;
left: 5px;
background: #dadada;
width: 22px;
height: 22px;
box-shadow: none;
}
.switch-flat .switch-handle:before {
background: #eceeef;
}
.switch-flat .switch-input:checked ~ .switch-label {
background: #FFF;
border-color: #0088cc;
}
.switch-flat .switch-input:checked ~ .switch-handle {
left: 55px;
background: #0088cc;
box-shadow: none;
}
<label class='switch switch-flat'>
<input class='switch-input both' type='checkbox' checked />
<span class='switch-label' data-on='ON' data-off='OFF'></span>
<span class='switch-handle'></span>
</label>
First of all added a <span> as class name as tooltiptext in html inside the switch label
<span class="tooltiptext">ON</span>
While toggling the swicth the text of tooltiptext span also changed by
$(".switch-input").change(function(){
if($(".switch-input").prop("checked")){
$(".tooltiptext").text("ON")
}else{
$(".tooltiptext").text("OFF");
}
});
The visiblity of tooltiptext become hidden while hover the switch become visible
.switch .tooltiptext {
visibility: hidden;
}
.switch:hover .tooltiptext {
visibility: visible;
}
$(".switch-input").change(function(){
if($(".switch-input").prop("checked")){
$(".tooltiptext").text("ON")
}else{
$(".tooltiptext").text("OFF");
}
});
.switch {
margin:50px 45%;
position: relative;
width: 80px;
height: 30px;
background: #FFF;
background-image: -webkit-linear-gradient(top, #eeeeee, #FFFFFF 25px);
border-radius: 18px;
box-shadow: inset 0 -1px white, inset 0 1px 1px rgba(0, 0, 0, 0.05);
cursor: pointer;
float: left;
bottom: 3px;
right: 0;
}
.switch-input {
position: absolute;
left: 0;
opacity: 0;
}
.switch-label {
position: relative;
display: block;
height: inherit;
font-size: 10px;
text-transform: uppercase;
background: #eceeef;
border-radius: inherit;
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.12), inset 0 0 2px rgba(0, 0, 0, 0.15);
}
.switch-label:before, .switch-label:after {
position: absolute;
top: 50%;
margin-top: -.5em;
line-height: 1;
-webkit-transition: inherit;
-moz-transition: inherit;
-o-transition: inherit;
transition: inherit;
}
.switch-label:before {
content: attr(data-off);
right: 11px;
color: #aaaaaa;
text-shadow: 0 1px rgba(255, 255, 255, 0.5);
}
.switch-label:after {
content: attr(data-on);
left: 11px;
color: #FFFFFF;
text-shadow: 0 1px rgba(0, 0, 0, 0.2);
opacity: 0;
}
.switch-input:checked ~ .switch-label {
background: #E1B42B;
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.15), inset 0 0 3px rgba(0, 0, 0, 0.2);
}
.switch-input:checked ~ .switch-label:before {
opacity: 0;
}
.switch-input:checked ~ .switch-label:after {
opacity: 1;
}
.switch-handle {
position: absolute;
top: 1px;
right: 100px;
width: 25px;
height: 28px;
background: linear-gradient(to bottom, #FFFFFF 40%, #f0f0f0);
background-image: -webkit-linear-gradient(top, #FFFFFF 40%, #f0f0f0);
border-radius: 100%;
box-shadow: 1px 1px 5px rgba(0, 0, 0, 0.2);
}
.switch-handle:before {
content: "";
position: absolute;
top: 50%;
left: 50%;
margin: -6px 0 0 -6px;
width: 12px;
height: 12px;
background: linear-gradient(to bottom, #eeeeee, #FFFFFF);
background-image: -webkit-linear-gradient(top, #eeeeee, #FFFFFF);
border-radius: 6px;
box-shadow: inset 0 1px rgba(0, 0, 0, 0.02);
}
.switch-input:checked ~ .switch-handle {
left: 50px;
box-shadow: -1px 1px 5px rgba(0, 0, 0, 0.2);
}
/* transitions */
.switch-label, .switch-handle {
transition: All 0.3s ease;
-webkit-transition: All 0.3s ease;
-moz-transition: All 0.3s ease;
-o-transition: All 0.3s ease;
}
.switch-flat {
padding: 0;
background: #FFF;
background-image: none;
}
.switch-flat .switch-label {
background: #FFF;
border: solid 2px #eceeef;
box-shadow: none;
}
.switch-flat .switch-label:after {
color: #0088cc;
}
.switch-flat .switch-handle {
top: 4px;
left: 5px;
background: #dadada;
width: 22px;
height: 22px;
box-shadow: none;
}
.switch-flat .switch-handle:before {
background: #eceeef;
}
.switch-flat .switch-input:checked ~ .switch-label {
background: #FFF;
border-color: #0088cc;
}
.switch-flat .switch-input:checked ~ .switch-handle {
left: 55px;
background: #0088cc;
box-shadow: none;
}
/* tooltip */
.switch .tooltiptext {
visibility: hidden;
width: 50px;
background-color: black;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px 0;
position: absolute;
z-index: 1;
bottom: 37px;
left: calc(50% - 25px);
}
.switch .tooltiptext::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: black transparent transparent transparent;
}
.switch:hover .tooltiptext {
visibility: visible;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<label class='switch switch-flat'>
<input class='switch-input both' type='checkbox' checked />
<span class='switch-label' data-on='ON' data-off='OFF'></span>
<span class='switch-handle'></span>
<span class="tooltiptext">ON</span>
</label>
You can use script like this:
.switch {
position: relative;
width: 80px;
height: 30px;
background: #FFF;
background-image: -webkit-linear-gradient(top, #eeeeee, #FFFFFF 25px);
border-radius: 18px;
box-shadow: inset 0 -1px white, inset 0 1px 1px rgba(0, 0, 0, 0.05);
cursor: pointer;
float: left;
bottom: 3px;
right: 0;
}
.switch-input {
position: absolute;
left: 0;
opacity: 0;
}
.switch-label {
position: relative;
display: block;
height: inherit;
font-size: 10px;
text-transform: uppercase;
background: #eceeef;
border-radius: inherit;
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.12), inset 0 0 2px rgba(0, 0, 0, 0.15);
}
.switch-label:before, .switch-label:after {
position: absolute;
top: 50%;
margin-top: -.5em;
line-height: 1;
-webkit-transition: inherit;
-moz-transition: inherit;
-o-transition: inherit;
transition: inherit;
}
.switch-label:before {
content: attr(data-off);
right: 11px;
color: #aaaaaa;
text-shadow: 0 1px rgba(255, 255, 255, 0.5);
}
.switch-label:after {
content: attr(data-on);
left: 11px;
color: #FFFFFF;
text-shadow: 0 1px rgba(0, 0, 0, 0.2);
opacity: 0;
}
.switch-input:checked ~ .switch-label {
background: #E1B42B;
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.15), inset 0 0 3px rgba(0, 0, 0, 0.2);
}
.switch-input:checked ~ .switch-label:before {
opacity: 0;
}
.switch-input:checked ~ .switch-label:after {
opacity: 1;
}
.switch-handle {
position: absolute;
top: 1px;
right: 100px;
width: 25px;
height: 28px;
background: linear-gradient(to bottom, #FFFFFF 40%, #f0f0f0);
background-image: -webkit-linear-gradient(top, #FFFFFF 40%, #f0f0f0);
border-radius: 100%;
box-shadow: 1px 1px 5px rgba(0, 0, 0, 0.2);
}
.switch-handle:before {
content: "";
position: absolute;
top: 50%;
left: 50%;
margin: -6px 0 0 -6px;
width: 12px;
height: 12px;
background: linear-gradient(to bottom, #eeeeee, #FFFFFF);
background-image: -webkit-linear-gradient(top, #eeeeee, #FFFFFF);
border-radius: 6px;
box-shadow: inset 0 1px rgba(0, 0, 0, 0.02);
}
.switch-input:checked ~ .switch-handle {
left: 50px;
box-shadow: -1px 1px 5px rgba(0, 0, 0, 0.2);
}
/* transitions */
.switch-label, .switch-handle {
transition: All 0.3s ease;
-webkit-transition: All 0.3s ease;
-moz-transition: All 0.3s ease;
-o-transition: All 0.3s ease;
}
.switch-flat {
padding: 0;
background: #FFF;
background-image: none;
}
.switch-flat .switch-label {
background: #FFF;
border: solid 2px #eceeef;
box-shadow: none;
}
.switch-flat .switch-label:after {
color: #0088cc;
}
.switch-flat .switch-handle {
top: 4px;
left: 5px;
background: #dadada;
width: 22px;
height: 22px;
box-shadow: none;
}
.switch-flat .switch-handle:before {
background: #eceeef;
}
.switch-flat .switch-input:checked ~ .switch-label {
background: #FFF;
border-color: #0088cc;
}
.switch-flat .switch-input:checked ~ .switch-handle {
left: 55px;
background: #0088cc;
box-shadow: none;
}
.tooltip {
}
.tooltip .tooltiptext {
visibility: hidden;
width: 120px;
background-color: black;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px 0;
/* Position the tooltip */
position: absolute;
z-index: 1;
}
.tooltip:hover .tooltiptext {
visibility: visible;
}
<html>
<script>
function content_of_toolTip() {
if (document.getElementById("check").checked == true) {
document.getElementById("tooltipLabel").innerHTML = "yes"
}
if (document.getElementById("check").checked == false) {
document.getElementById("tooltipLabel").innerHTML = "no"
}
}
</script>
<body style="text-align:center;">
<label class='switch switch-flat tooltip'>
<input class='switch-input both' id="check" onchange=content_of_toolTip() type='checkbox' checked />
<span class='switch-label' data-on='ON' data-off='OFF' onmouseover="content_of_toolTip()" onfocus="content_of_toolTip(this)" ></span>
<span class='switch-handle'></span>
<span class="tooltiptext" id="tooltipLabel">Tooltip text</span>
</label>
</body>
</html>

Hover effect on before and after

I have the following fiddle:
https://jsfiddle.net/ur9bpgbn/164/
I try to apply a hover effect to the whole arrow with no success.
I have the CSS here:
.arrow {
position: absolute;
font-size: 16px;
max-width: 350px;
background: #FFF;
height: 40px;
line-height: 40px;
margin-bottom: 20px;
text-align: center;
color: #000;
box-shadow: 3px 5px 5px rgba(0, 0, 0, 0.2);
visibility: hidden;
opacity: 0;
transition: visibility 0s, opacity 0.3s ease-in-out;
z-index: 999;
}
.arrow.active {
visibility: visible;
opacity: 1;
}
.arrow.active.animate-left-to-right {
animation-name: move-left-to-right;
animation-duration: 1s;
animation-delay: 0.6s;
animation-iteration-count: infinite;
animation-direction: alternative;
}
.arrow.active.animate-right-to-left {
animation-name: move-right-to-left;
animation-duration: 1s;
animation-delay: 0.6s;
animation-iteration-count: infinite;
animation-direction: alternative;
}
#keyframes move-left-to-right {
0% {
transform: translateX (5%);
box-shadow: 3px 5px 5px rgba(0, 0, 0, 0.2);
}
50% {
transform: translateX(15%);
box-shadow: 3px 5px 5px rgba(0, 0, 0, 0.4);
}
100% {
transform: translateX(5%);
box-shadow: 3px 5px 5px rgba(0, 0, 0, 0.2);
}
}
#keyframes move-right-to-left {
0% {
transform: translateX(-5%);
box-shadow: -3px 5px 5px rgba(0, 0, 0, 0.2);
}
50% {
transform: translateX(-15%);
box-shadow: -3px 5px 5px rgba(0, 0, 0, 0.4);
}
100% {
transform: translateX(-5%);
box-shadow: -3px 5px 5px rgba(0, 0, 0, 0.2);
}
}
/*right arrow*/
.arrow-right {
border-radius: 0px 0px 0 0px;
background: linear-gradient(to right, rgba(255, 255, 255, 1), rgba(255, 255, 255, 0.7));
}
.arrow-right:after {
content: "";
position: absolute;
right: -20px;
top: 0;
border-top: 20px solid transparent;
border-bottom: 20px solid transparent;
border-left: 20px solid #FFF;
opacity: 0.7;
}
.arrow-right:before {
content: "";
position: absolute;
left: -20px;
top: 0;
border-top: 0px solid transparent;
border-bottom: 40px solid transparent;
border-right: 20px solid #FFF;
opacity: 1;
}
/*left arrow*/
.arrow-left {
border-radius: 0 0px 0px 0;
background: linear-gradient(to left, rgba(255, 255, 255, 1), rgba(255, 255, 255, 0.7));
}
.arrow-left:before {
content: "";
position: absolute;
left: -20px;
top: 0;
border-top: 20px solid transparent;
border-bottom: 20px solid transparent;
border-right: 20px solid #FFF;
opacity: 0.7;
}
.arrow-left:after {
content: "";
position: absolute;
right: -20px;
top: 0;
border-top: 0px solid transparent;
border-bottom: 40px solid transparent;
border-left: 20px solid #FFF;
opacity: 1;
}
.arrow:hover{
background-color: darkblue;
}
<div id="app">
<div href="#" class="arrow arrow-right animate-right-to-left">This is a text</div>
<div href="#" class="arrow arrow-left animate-left-to-right" style="margin-top:30%; margin-left:30%;"><span class="room-desc">This is a text</span></div>
</div>
I found a way to apply hover:after but I don't want the hover effect to apply when the user mouses over the after, I want it the other way around. It should actually cover all the situations, if the user mouses over the main div, the after OR the before it should apply the hover state to all of these.
I tried reading up some documentaton on pseudo elements but I didn't found a working solution yet.
Is this doable?
.arrow:hover:after { } should fire when either the arrow is hovered or the after is hovered (as the after will be inside the arrow element)
$('.arrow').addClass('active')
body{
background: #000;
margin: 20%;
}
.arrow {
position: absolute;
font-size: 16px;
max-width: 350px;
background: #FFF;
height: 40px;
line-height: 40px;
margin-bottom: 20px;
text-align: center;
color: #000;
box-shadow: 3px 5px 5px rgba(0, 0, 0, 0.2);
visibility: hidden;
opacity: 0;
transition: visibility 0s, opacity 0.3s ease-in-out;
z-index: 999;
}
.arrow.active {
visibility: visible;
opacity: 1;
}
.arrow.active.animate-left-to-right {
animation-name: move-left-to-right;
animation-duration: 1s;
animation-delay: 0.6s;
animation-iteration-count: infinite;
animation-direction: alternative;
}
.arrow.active.animate-right-to-left {
animation-name: move-right-to-left;
animation-duration: 1s;
animation-delay: 0.6s;
animation-iteration-count: infinite;
animation-direction: alternative;
}
#keyframes move-left-to-right {
0% {
transform: translateX (5%);
box-shadow: 3px 5px 5px rgba(0, 0, 0, 0.2);
}
50% {
transform: translateX(15%);
box-shadow: 3px 5px 5px rgba(0, 0, 0, 0.4);
}
100% {
transform: translateX(5%);
box-shadow: 3px 5px 5px rgba(0, 0, 0, 0.2);
}
}
#keyframes move-right-to-left {
0% {
transform: translateX(-5%);
box-shadow: -3px 5px 5px rgba(0, 0, 0, 0.2);
}
50% {
transform: translateX(-15%);
box-shadow: -3px 5px 5px rgba(0, 0, 0, 0.4);
}
100% {
transform: translateX(-5%);
box-shadow: -3px 5px 5px rgba(0, 0, 0, 0.2);
}
}
/*right arrow*/
.arrow-right {
border-radius: 0px 0px 0 0px;
background: linear-gradient(to right, rgba(255, 255, 255, 1), rgba(255, 255, 255, 0.7));
}
.arrow-right:after {
content: "";
position: absolute;
right: -20px;
top: 0;
border-top: 20px solid transparent;
border-bottom: 20px solid transparent;
border-left: 20px solid #FFF;
opacity: 0.7;
}
.arrow-right:before {
content: "";
position: absolute;
left: -20px;
top: 0;
border-top: 0px solid transparent;
border-bottom: 40px solid transparent;
border-right: 20px solid #FFF;
opacity: 1;
}
/*left arrow*/
.arrow-left {
border-radius: 0 0px 0px 0;
background: linear-gradient(to left, rgba(255, 255, 255, 1), rgba(255, 255, 255, 0.7));
}
.arrow-left:before {
content: "";
position: absolute;
left: -20px;
top: 0;
border-top: 20px solid transparent;
border-bottom: 20px solid transparent;
border-right: 20px solid #FFF;
opacity: 0.7;
}
.arrow-left:after {
content: "";
position: absolute;
right: -20px;
top: 0;
border-top: 0px solid transparent;
border-bottom: 40px solid transparent;
border-left: 20px solid #FFF;
opacity: 1;
}
.arrow:hover:after{
border-left-color: red; /* turn arrow red on hover */
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="app">
<div href="#" class="arrow arrow-right animate-right-to-left">This is a text</div>
<div href="#" class="arrow arrow-left animate-left-to-right" style="margin-top:30%; margin-left:30%;"><span class="room-desc">This is a text</span></div>
</div>
You mean something like this?
.arrow:hover {
background: darkblue;
}
.arrow:hover:before {
border-right: 20px solid darkblue;
}
.arrow:hover:after {
border-left: 20px solid darkblue;
}

Align label contents after checkbox css

I have styled Checkbox from this source as below:
.toggle-button {
margin: 0 20px;
}
/*
* Toggle button styles
*/
.toggle-button {
position: relative;
display: inline-block;
color: rgb(80, 77, 77);
}
.toggle-button label {
display: inline-block;
cursor: pointer;
text-align: left;
}
.toggle-button input {
display: none;
}
.toggle-button__icon {
cursor: pointer;
pointer-events: none;
}
.toggle-button__icon:before,
.toggle-button__icon:after {
content: "";
position: absolute;
top: 45%;
left: 35%;
transition: 0.2s ease-out;
}
.toggle-button--tuli label {
line-height: 20px;
text-indent: 30px;
}
.toggle-button--tuli input[type=checkbox]:checked~.toggle-button__icon {
background: #fff;
}
.toggle-button--tuli input[type=checkbox]:checked~.toggle-button__icon:before,
.toggle-button--tuli input[type=checkbox]:checked~.toggle-button__icon:after {
opacity: 1;
}
.toggle-button--tuli .toggle-button__icon {
position: absolute;
top: 0;
left: 0;
width: 20px;
height: 20px;
transition: all 0.2s;
border: 2px solid rgb(37, 146, 236);
border-radius: 1px;
box-shadow: 0 1px 0 rgba(0, 0, 0, 0.1);
text-shadow: 0 1px 0 rgba(0, 0, 0, 0.1);
}
.toggle-button--tuli .toggle-button__icon:before,
.toggle-button--tuli .toggle-button__icon:after {
top: 5px;
left: 2px;
width: 12px;
height: 2px;
border-radius: 3px;
background: #fff;
box-shadow: 0 1px 0 rgba(0, 0, 0, 0.1);
top: 35%;
background: #0175b2;
opacity: 0;
transform-origin: left center;
}
.toggle-button--tuli .toggle-button__icon:before {
transform: translate(0, 0) rotate(45deg) scale(0.6, 1);
}
.toggle-button--tuli .toggle-button__icon:after {
transform: translate(4px, 6px) rotate(-45deg);
}
.toggle-button--tuli:hover input[type=checkbox]:not(:checked)~.toggle-button__icon {
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
text-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="toggle-button toggle-button--tuli">
<input id="toggleButton11" type="checkbox">
<label for="toggleButton11">I confirm that I have read and agree to the Terms of Use specified by the client and some long text to continue with to show the alignment below checkbox</label>
<div class="toggle-button__icon"></div>
</div>
If you run the snippet you can see that when label contents break the line it comes below the checkbox. How can I modify the css to align label contents to appear after the checkbox. I've tried text-indent but that only works for 1st line. Hope to find some help.
Instead of text-indent use padding-left and it will work as you wish:
.toggle-button {
margin: 0 20px;
}
/*
* Toggle button styles
*/
.toggle-button {
position: relative;
display: inline-block;
color: rgb(80, 77, 77);
}
.toggle-button label {
display: inline-block;
cursor: pointer;
text-align: left;
}
.toggle-button input {
display: none;
}
.toggle-button__icon {
cursor: pointer;
pointer-events: none;
}
.toggle-button__icon:before,
.toggle-button__icon:after {
content: "";
position: absolute;
top: 45%;
left: 35%;
transition: 0.2s ease-out;
}
.toggle-button--tuli label {
line-height: 20px;
padding-left: 30px;
}
.toggle-button--tuli input[type=checkbox]:checked~.toggle-button__icon {
background: #fff;
}
.toggle-button--tuli input[type=checkbox]:checked~.toggle-button__icon:before,
.toggle-button--tuli input[type=checkbox]:checked~.toggle-button__icon:after {
opacity: 1;
}
.toggle-button--tuli .toggle-button__icon {
position: absolute;
top: 0;
left: 0;
width: 20px;
height: 20px;
transition: all 0.2s;
border: 2px solid rgb(37, 146, 236);
border-radius: 1px;
box-shadow: 0 1px 0 rgba(0, 0, 0, 0.1);
text-shadow: 0 1px 0 rgba(0, 0, 0, 0.1);
}
.toggle-button--tuli .toggle-button__icon:before,
.toggle-button--tuli .toggle-button__icon:after {
top: 5px;
left: 2px;
width: 12px;
height: 2px;
border-radius: 3px;
background: #fff;
box-shadow: 0 1px 0 rgba(0, 0, 0, 0.1);
top: 35%;
background: #0175b2;
opacity: 0;
transform-origin: left center;
}
.toggle-button--tuli .toggle-button__icon:before {
transform: translate(0, 0) rotate(45deg) scale(0.6, 1);
}
.toggle-button--tuli .toggle-button__icon:after {
transform: translate(4px, 6px) rotate(-45deg);
}
.toggle-button--tuli:hover input[type=checkbox]:not(:checked)~.toggle-button__icon {
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
text-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="toggle-button toggle-button--tuli">
<input id="toggleButton11" type="checkbox">
<label for="toggleButton11">I confirm that I have read and agree to the Terms of Use specified by the client and some long text to continue with to show the alignment below checkbox</label>
<div class="toggle-button__icon"></div>
</div>
For the label, use padding instead of text-indent:
.toggle-button--tuli label {
line-height: 20px;
padding-left: 30px;
}
It will add padding left for the text and the button will be aligned to the left side because it is positioned absolutely.
If you remove the text-indent and instead use padding-left that should work.
.toggle-button {
margin: 0 20px;
}
/*
* Toggle button styles
*/
.toggle-button {
position: relative;
display: inline-block;
color: rgb(80, 77, 77);
}
.toggle-button label {
display: inline-block;
cursor: pointer;
text-align: left;
}
.toggle-button input {
display: none;
}
.toggle-button__icon {
cursor: pointer;
pointer-events: none;
}
.toggle-button__icon:before,
.toggle-button__icon:after {
content: "";
position: absolute;
top: 45%;
left: 35%;
transition: 0.2s ease-out;
}
.toggle-button--tuli label {
line-height: 20px;
padding-left: 30px;
}
.toggle-button--tuli input[type=checkbox]:checked~.toggle-button__icon {
background: #fff;
}
.toggle-button--tuli input[type=checkbox]:checked~.toggle-button__icon:before,
.toggle-button--tuli input[type=checkbox]:checked~.toggle-button__icon:after {
opacity: 1;
}
.toggle-button--tuli .toggle-button__icon {
position: absolute;
top: 0;
left: 0;
width: 20px;
height: 20px;
transition: all 0.2s;
border: 2px solid rgb(37, 146, 236);
border-radius: 1px;
box-shadow: 0 1px 0 rgba(0, 0, 0, 0.1);
text-shadow: 0 1px 0 rgba(0, 0, 0, 0.1);
}
.toggle-button--tuli .toggle-button__icon:before,
.toggle-button--tuli .toggle-button__icon:after {
top: 5px;
left: 2px;
width: 12px;
height: 2px;
border-radius: 3px;
background: #fff;
box-shadow: 0 1px 0 rgba(0, 0, 0, 0.1);
top: 35%;
background: #0175b2;
opacity: 0;
transform-origin: left center;
}
.toggle-button--tuli .toggle-button__icon:before {
transform: translate(0, 0) rotate(45deg) scale(0.6, 1);
}
.toggle-button--tuli .toggle-button__icon:after {
transform: translate(4px, 6px) rotate(-45deg);
}
.toggle-button--tuli:hover input[type=checkbox]:not(:checked)~.toggle-button__icon {
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
text-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="toggle-button toggle-button--tuli">
<input id="toggleButton11" type="checkbox">
<label for="toggleButton11">I confirm that I have read and agree to the Terms of Use specified by the client and some long text to continue with to show the alignment below checkbox</label>
<div class="toggle-button__icon"></div>
</div>
I've updated the answer. padding-left will allow the click to to be detected.
.toggle-button {
margin: 0 20px;
position: relative;
display: inline-block;
color: #504d4d
}
.toggle-button__icon {
cursor: pointer;
pointer-events: none
}
.toggle-button label {
display: inline-block;
cursor: pointer;
text-align: left
}
.toggle-button input {
display: none
}
.toggle-button--tuli label {
line-height: 20px;
padding-left: 25px
}
.toggle-button__icon:before,
.toggle-button__icon:after {
content: "";
position: absolute;
top: 45%;
left: 35%;
transition: .2s ease-out
}
.toggle-button--tuli input[type=checkbox]:checked~.toggle-button__icon {
background: #fff
}
.toggle-button--tuli input[type=checkbox]:checked~.toggle-button__icon:before,
.toggle-button--tuli input[type=checkbox]:checked~.toggle-button__icon:after {
opacity: 1
}
.toggle-button--tuli .toggle-button__icon {
position: absolute;
top: 0;
left: 0;
width: 20px;
height: 20px;
transition: all .2s;
border: 2px solid #2592ec;
border-radius: 1px;
box-shadow: 0 1px 0 rgba(0, 0, 0, 0.1);
text-shadow: 0 1px 0 rgba(0, 0, 0, 0.1)
}
.toggle-button--tuli .toggle-button__icon:before,
.toggle-button--tuli .toggle-button__icon:after {
top: 5px;
left: 2px;
width: 12px;
height: 2px;
border-radius: 3px;
background: #fff;
box-shadow: 0 1px 0 rgba(0, 0, 0, 0.1);
top: 35%;
background: #0175b2;
opacity: 0;
transform-origin: left center
}
.toggle-button--tuli .toggle-button__icon:before {
transform: translate(0, 0) rotate(45deg) scale(0.6, 1)
}
.toggle-button--tuli .toggle-button__icon:after {
transform: translate(4px, 6px) rotate(-45deg)
}
.toggle-button--tuli:hover input[type=checkbox]:not(:checked)~.toggle-button__icon {
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
text-shadow: 0 1px 3px rgba(0, 0, 0, 0.2)
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="toggle-button toggle-button--tuli">
<input id="toggleButton11" type="checkbox">
<label for="toggleButton11">I confirm that I have read and agree to the Terms of Use specified by the client and some long text to continue with to show the alignment below checkbox</label>
<div class="toggle-button__icon"></div>
</div>
Here you go
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="checkbox">
<label><input type="checkbox"> I confirm that I have read and agree to the Terms
of Use specified by the client and some long text to continue with to show the alignment below checkbox
I confirm that I have read and agree to the Terms
of Use specified by the client and some long text to continue with to show the alignment below checkbox</label>
</div>
Try this code..

remove css property set for radio btutton inside div

.toggle {
position: relative;
margin: 0 auto;
height: 30px;
width: 65%;
border-radius: 0;
-webkit-border-radius: 0;
-moz-border-radius: 0;
-webkit-box-shadow: inset 0 1px 3px rgba(0, 0, 0, .3), 0 1px rgba(255, 255, 255, .1);
box-shadow: inset 0 1px 3px rgba(0, 0, 0, .3), 0 1px rgba(255, 255, 255, .1);
background: #AAA;
text-shadow: none;
font-weight: 400
}
.chngamt-head,
.toggle-label:active {
font-weight: 700
}
.toggle-label {
position: relative;
z-index: 2;
float: left;
width: 49%;
line-height: 30px;
font-size: 10px;
color: rgba(255, 255, 255, .87);
text-align: center
}
.toggle-label-off {
padding-left: 2px
}
.stylechngbut,
.styleinpamt {
margin-bottom: 15px;
padding: 15px
}
.toggle-input {
display: none
}
.toggle-input:checked+.toggle-label {
color: rgba(0, 0, 0, .65);
-webkit-transition: .15s ease-out;
-moz-transition: .15s ease-out;
-o-transition: .15s ease-out;
transition: .15s ease-out
}
.toggle-input:checked+.toggle-label-on~.toggle-selection {
left: 50%
}
.toggle-selection {
display: block;
position: absolute;
z-index: 1;
top: 2px;
left: 2px;
width: 49%;
height: 26px;
background: #65bd63;
border-radius: 0;
-webkit-border-radius: 0;
-moz-border-radius: 0;
background-image: -webkit-linear-gradient(top, #9dd993, #65bd63);
background-image: -moz-linear-gradient(top, #9dd993, #65bd63);
background-image: -o-linear-gradient(top, #9dd993, #65bd63);
background-image: linear-gradient(to bottom, #9dd993, #65bd63);
-webkit-box-shadow: inset 0 1px rgba(255, 255, 255, .5), 0 0 2px rgba(0, 0, 0, .2);
box-shadow: inset 0 1px rgba(255, 255, 255, .5), 0 0 2px rgba(0, 0, 0, .2);
-webkit-transition: left .15s ease-out;
-moz-transition: left .15s ease-out;
-o-transition: left .15s ease-out;
transition: left .15s ease-out
}
.toggle-blue .toggle-selection {
background: #FCCD17;
background-image: -webkit-linear-gradient(top, #fff3b2, #fccd17);
background-image: -moz-linear-gradient(top, #fff3b2, #fccd17);
background-image: -o-linear-gradient(top, #fff3b2, #fccd17);
background-image: linear-gradient(to bottom, #fff3b2, #fccd17)
}
.toggle-yellow .toggle-selection {
background: #c4bb61;
background-image: -webkit-linear-gradient(top, #e0dd94, #c4bb61);
background-image: -moz-linear-gradient(top, #e0dd94, #c4bb61);
background-image: -o-linear-gradient(top, #e0dd94, #c4bb61);
background-image: linear-gradient(to bottom, #e0dd94, #c4bb61)
}
[type="radio"]:not(:checked),
[type="radio"]:checked {
position: absolute;
left: -9999px;
}
[type="radio"]:not(:checked)+label,
[type="radio"]:checked+label {
position: relative;
padding-left: 55px;
cursor: pointer;
margin: 0;
width: 100%;
}
/* checkbox aspect */
[type="radio"]:not(:checked)+label::before,
[type="radio"]:checked+label::before {
background: #000000 none repeat scroll 0 0;
border-radius: 0;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3) inset;
content: "";
height: 45px;
left: 0;
position: absolute;
top: 0;
width: 45px;
}
/* checked mark aspect */
[type="radio"]:not(:checked)+label:after,
[type="radio"]:checked+label:after {
color: #ffffff;
content: "✔";
font-size: 18px;
left: 14px;
line-height: 0.8;
position: absolute;
top: 17px;
transition: all 0.2s ease 0s;
}
/* checked mark aspect changes */
[type="radio"]:not(:checked)+label:after {
opacity: 0;
transform: scale(0);
}
[type="radio"]:checked+label:after {
opacity: 1;
transform: scale(1);
}
/* disabled checkbox */
[type="radio"]:disabled:not(:checked)+label:before,
[type="radio"]:disabled:checked+label:before {
box-shadow: none;
border-color: #bbb;
background-color: #fff;
}
[type="radio"]:disabled:checked+label:after {
color: #fff;
}
[type="radio"]:disabled+label {
color: #aaa;
}
/* accessibility */
[type="radio"]:checked:focus+label:before,
[type="radio"]:not(:checked):focus+label:before {
border: 1px dotted blue;
}
/* hover style just for information */
label:hover:before {
border: 1px solid #4778d9!important;
}
[type="radio"]:checked+label {
background: #FFDF66;
}
<div class="toggle toggle-blue reset-this">
<input type="radio" class="toggle-input " name="SchemeType" value="R" id="LStoggle" checked />
<label for="LStoggle" class="toggle-label toggle-label-off">
Male
</label>
<input type="radio" class="toggle-input" name="SchemeType" value="D" id="SIPtoggle" />
<label for="SIPtoggle" class="toggle-label toggle-label-on">
female
</label>
<span class="toggle-selection"></span>
</div>
i am using css property [type="radio"] for radio button outside class toggle div but radio button inside class toggle should not use css property [type="radio"] it should remove the css property set for radio button outside class toggle div i used css combinator but its not working i want following output jsfiddle any help will be appreciated