Need help implementing aspects for toggle bar - html

Basically, I am trying to create a toggle bar with a day and night system. Once you toggle the bar, it either leads to day or night. I have the toggle bar, but I am having trouble implementing the day and night system. Once the user toggles to day or night, I want the background to be light blue for day and black for dark blue for night. I want the colors to switch depending if the user is on day or night. How can I do this? The toggle code is down below. Here is the link for the code I am using if it's easier to read in this format: https://codepen.io/bnthor/pen/WQBNxO
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>repl.it</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="toggleWrapper">
<input type="checkbox" class="dn" id="dn"/>
<label for="dn" class="toggle">
<span class="toggle__handler">
<span class="crater crater--1"></span>
<span class="crater crater--2"></span>
<span class="crater crater--3"></span>
</span>
<span class="star star--1"></span>
<span class="star star--2"></span>
<span class="star star--3"></span>
<span class="star star--4"></span>
<span class="star star--5"></span>
<span class="star star--6"></span>
</label>
</div>
</body>
</html>
CSS
body {
background-color: #1e314f;
font-family: 'Helvetica Rounded', 'Arial Rounded MT Bold', 'Montserrat', sans-serif;
color: #fff;
}
.toggleWrapper {
position: absolute;
top: 50%;
left: 50%;
overflow: hidden;
padding: 0 200px;
transform: translate3d(-50%, -50%, 0);
}
.toggleWrapper input {
position: absolute;
left: -99em;
}
.toggle {
cursor: pointer;
display: inline-block;
position: relative;
width: 90px;
height: 50px;
background-color: #83d8ff;
border-radius: 84px;
transition: background-color 200ms cubic-bezier(0.445, 0.05, 0.55, 0.95);
}
.toggle:before {
content: 'AM';
position: absolute;
left: -50px;
top: 15px;
font-size: 18px;
}
.toggle:after {
content: 'PM';
position: absolute;
right: -48px;
top: 15px;
font-size: 18px;
color: #749ed7;
}
.toggle__handler {
display: inline-block;
position: relative;
z-index: 1;
top: 3px;
left: 3px;
width: 44px;
height: 44px;
background-color: #ffcf96;
border-radius: 50px;
box-shadow: 0 2px 6px rgba(0, 0, 0, .3);
transition: all 400ms cubic-bezier(0.68, -0.55, 0.265, 1.55);
transform: rotate(-45deg);
}
.toggle__handler .crater {
position: absolute;
background-color: #e8cda5;
opacity: 0;
transition: opacity 200ms ease-in-out;
border-radius: 100%;
}
.toggle__handler .crater--1 {
top: 18px;
left: 10px;
width: 4px;
height: 4px;
}
.toggle__handler .crater--2 {
top: 28px;
left: 22px;
width: 6px;
height: 6px;
}
.toggle__handler .crater--3 {
top: 10px;
left: 25px;
width: 8px;
height: 8px;
}
.star {
position: absolute;
background-color: #fff;
transition: all 300ms cubic-bezier(0.445, 0.05, 0.55, 0.95);
border-radius: 50%;
}
.star--1 {
top: 10px;
left: 35px;
z-index: 0;
width: 30px;
height: 3px;
}
.star--2 {
top: 18px;
left: 28px;
z-index: 1;
width: 30px;
height: 3px;
}
.star--3 {
top: 27px;
left: 40px;
z-index: 0;
width: 30px;
height: 3px;
}
.star--4, .star--5, .star--6 {
opacity: 0;
transition: all 300ms 0 cubic-bezier(0.445, 0.05, 0.55, 0.95);
}
.star--4 {
top: 16px;
left: 11px;
z-index: 0;
width: 2px;
height: 2px;
transform: translate3d(3px, 0, 0);
}
.star--5 {
top: 32px;
left: 17px;
z-index: 0;
width: 3px;
height: 3px;
transform: translate3d(3px, 0, 0);
}
.star--6 {
top: 36px;
left: 28px;
z-index: 0;
width: 2px;
height: 2px;
transform: translate3d(3px, 0, 0);
}
input:checked + .toggle {
background-color: #749dd6;
}
input:checked + .toggle:before {
color: #749ed7;
}
input:checked + .toggle:after {
color: #fff;
}
input:checked + .toggle .toggle__handler {
background-color: #ffe5b5;
transform: translate3d(40px, 0, 0) rotate(0);
}
input:checked + .toggle .toggle__handler .crater {
opacity: 1;
}
input:checked + .toggle .star--1 {
width: 2px;
height: 2px;
}
input:checked + .toggle .star--2 {
width: 4px;
height: 4px;
transform: translate3d(-5px, 0, 0);
}
input:checked + .toggle .star--3 {
width: 2px;
height: 2px;
transform: translate3d(-7px, 0, 0);
}
input:checked + .toggle .star--4, input:checked + .toggle .star--5, input:checked + .toggle .star--6 {
opacity: 1;
transform: translate3d(0, 0, 0);
}
input:checked + .toggle .star--4 {
transition: all 300ms 200ms cubic-bezier(0.445, 0.05, 0.55, 0.95);
}
input:checked + .toggle .star--5 {
transition: all 300ms 300ms cubic-bezier(0.445, 0.05, 0.55, 0.95);
}
input:checked + .toggle .star--6 {
transition: all 300ms 400ms cubic-bezier(0.445, 0.05, 0.55, 0.95);
}

So you just edit body element like:
HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>repl.it</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body id="body">
<div class="toggleWrapper">
<input type="checkbox" class="dn" id="dn" onclick="changeBack()"/>
<label for="dn" class="toggle">
<span class="toggle__handler">
<span class="crater crater--1"></span>
<span class="crater crater--2"></span>
<span class="crater crater--3"></span>
</span>
<span class="star star--1"></span>
<span class="star star--2"></span>
<span class="star star--3"></span>
<span class="star star--4"></span>
<span class="star star--5"></span>
<span class="star star--6"></span>
</label>
</div>
</body>
</html>
And you can use javascript to change background:
<script>
function changeBack() {
var checkBox = document.getElementById("dn");
if (checkBox.checked == true) {
document.getElementById("body").style.backgroundColor = "lightblue";
}
else {
document.getElementById("body").style.backgroundColor = "black";
}
}
</script>
EDITED
<input type="checkbox" class="dn" id="dn" onclick="changeBack()"/>
and all JS

Related

Focus on outside rectangle of Toggle Switch on switch to true

Unable to focus on rectangle outside of toggle switch on selecting and I wanted to add the functionality to focus on the label class which is used for outside rectangle of toggle switch, but was completely stuck. I am trying to do, is if the switch is pressed, then focus should be on rectangle box. I am using below HTML and CSS. Any help appreciated.
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.switch {
position: relative;
border: 1px solid rgb(112, 112, 112);
display: flex;
align-items: center;
width: 280px;
height: 70px;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
left:234px;
position: absolute;
cursor: pointer;
top: 20px;
right: 0;
bottom: 0;
height: 24px;
width: 40px;
background-color: grey;
-webkit-transition: 4s;
transition: 4s;
border-radius: 34px;
}
.slider:before {
position: absolute;
content: "";
height: 18px;
width: 18px;
left: 4px;
bottom: 4px;
background-color: white;
border-radius: 50%;
}
input:checked + .slider {
background-color: #2196F3;
}
.switch:hover{
box-shadow: 0 0 10px red;
}
.switch:active{
border-radius: 5 10px;
}
.switch:focus{
background-color: #0064D2;
}
input:checked + .slider:before {
-webkit-transform: translateX(26px);
-ms-transform: translateX(26px);
transform: translateX(100%);
}
.switch label {
position: absolute;
left:2px;
width: 234px;
height: 22px;
color: rgb(65, 65, 65);
font-size: 16px;
font-weight: normal;
letter-spacing: 0.15px;
line-height: 22px;
}
</style>
</head>
<body>
<h2>Toggle Switch</h2>
<label class="switch">
<label for="toggle-switch"
>Switch label
</label>
<input type="checkbox" id="toggle-switch">
<span class="slider round"></span>
</label>
</body>
</html>

How to change the size of a css toggle switch

I'm designing an element for a plugin called elementor. This project is really just to help me learn the functionality of developing for wordpress.
What I'm making is a "toggle content" slider that can toggle between text or predefined html. I've used the slider according to this guide: https://www.w3schools.com/howto/howto_css_switch.asp
Right Now the size of a switch is very big. I want a small switch. How Can change it? Can anyone help me out? Thanks.
.switch {
position: relative;
display: inline-block;
width: 60px;
height: 34px;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
-webkit-transition: .4s;
transition: .4s;
}
.slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
}
input:checked + .slider {
background-color: #2196F3;
}
input:focus + .slider {
box-shadow: 0 0 1px #2196F3;
}
input:checked + .slider:before {
-webkit-transform: translateX(26px);
-ms-transform: translateX(26px);
transform: translateX(26px);
}
/* Rounded sliders */
.slider.round {
border-radius: 34px;
}
.slider.round:before {
border-radius: 50%;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
</style>
</head>
<body>
<h2>Toggle Switch</h2>
<label class=" switch">
<input type="checkbox" checked>
<span class=" slider round"></span>
</label>
</body>
</html>
I used calc(); and var();, so you don't have to do a lot of work
Mozilla documentation: calc() explanation and var() explanation and --var: ; explanation .
just change ONE value the height of switch for change all responsively!!!
* {
--switch-height: 34px; /* change the value */
/* other code, pls see it then */
}
if you want a smaller switch, the 8px default padding, will take a lot of space,
so I simplified it for you! just change the --switch-padding: 8px; to something smaller...
automatically CSS calculates all things for you, for making the switch look good for all dimensions :)
the same thing if you want the switch to be bigger, remember to make the padding also bigger (the padding var)
I know This is not a site "we-are-doing-your-work.com" but I really want to help you!
here the complete fixed code:
* {
--switch-height: 34px;
--switch-padding: 8px;
--switch-width: calc((var(--switch-height) * 2) - var(--switch-padding));
--slider-height: calc(var(--switch-height) - var(--switch-padding));
--slider-on: calc(var(--switch-height) - var(--switch-padding));
}
.switch {
position: relative;
display: inline-block;
width: var(--switch-width);
height: var(--switch-height);
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
-webkit-transition: .4s;
transition: .4s;
}
.slider:before {
content: "";
position: absolute;
height: var(--slider-height);
width: var(--slider-height);
left: calc(var(--switch-padding) / 2);
bottom: calc(var(--switch-padding) / 2);
background-color: white;
-webkit-transition: .4s;
transition: .4s;
}
input:checked+.slider {
background-color: #2196F3;
}
input:focus+.slider {
box-shadow: 0 0 1px #2196F3;
}
input:checked+.slider:before {
transform: translateX(var(--slider-on));
}
.slider.round {
border-radius: var(--slider-height);
}
.slider.round:before {
border-radius: 50%;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h2>Toggle Switch</h2>
<label class="switch">
<input type="checkbox" checked>
<span class="slider round"></span>
</label>
</body>
</html>
* {
box-sizing: border-box;
}
body{
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
.label{
background-color: #fea621;
display: flex;
border-radius: 50px;
height: 26px;
width: 50px;
align-items: center;
justify-content: space-between;
padding: 5px;
position: relative;
}
.checkbox{
opacity: 0;
position: absolute;
}
.checkbox + .label .ball{
content: url(323329.png);
background-color: #001e3d;
}
.checkbox:checked + .label .ball{
content: url(flag-ukraine-circle.svg);
background-color: #001e3d;
transform: translateX(24px);
}
.ball{
background-color: #001e3d;
border-radius: 50%;
height: 22px;
width: 22px;
position: absolute;
top: 2px;
left: 2px;
transition: transform .2s linear;
}
.ball:before:checked{
content: url(flag-ukraine-circle.svg);
left: 50px;
}
.ball:checked:after{
left: 0;
}
<div>
<input type="checkbox" id="checkbox" class="checkbox">
<label for="checkbox" class="label">
<i class="ukraine"></i>
<i class="usa"></i>
<div class="ball"></div>
</label>
</div>
You can change the size by changing the css
.switch {
position: relative;
display: inline-block;
width: 35px;
height: 22px;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
-webkit-transition: .4s;
transition: .4s;
}
.slider:before {
position: absolute;
content: "";
height: 10px;
width: 10px;
left: 4px;
bottom: 6px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
}
input:checked + .slider {
background-color: #2196F3;
}
input:focus + .slider {
box-shadow: 0 0 1px #2196F3;
}
input:checked + .slider:before {
-webkit-transform: translateX(16px);
-ms-transform: translateX(16px);
transform: translateX(16px);
}
/* Rounded sliders */
.slider.round {
border-radius: 34px;
}
.slider.round:before {
border-radius: 50%;
}
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
</style>
</head>
<body>
<h2>Toggle Switch</h2>
<label class=" switch">
<input type="checkbox" checked>
<span class=" slider round"></span>
</label>
</body>
</html>
try to experiment with different widths and heights

Show Div When Click Check-box Radio

As you can see in the title I want to show Divs related to my check-box radio button. I looked for past topics about that and I try to do it with some scripts but I failed. I know Im missing somethings.
What I want to do is; when click on Second button (check-box radio tool 2) I want to open div class row3. and When click on First button (check-box radio tool 1) I want to open div class row2.
Maybe it is so easy but Im new on this stuffs. Any help or sugestion would be great.
Thanks..
/* PRODUCTS AND BUTTONS */
.button {
position: absolute;
bottom: 0%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
background-color: #d8d8d8cc;
color: rgb(0, 0, 0);
font-size: 70%;
width: 70%;
height: 20%;;
border: none;
cursor: pointer;
border-radius: 7px;
text-align: center;
}
.button span {
cursor: pointer;
display: inline-block;
position: relative;
transition: 0.5s;
}
.button span:after {
content: '\00bb';
position: absolute;
opacity: 0;
top: 0;
right: -20px;
transition: 0.5s;
}
.button:hover span {
padding-right: 25px;
}
.button:hover span:after {
opacity: 1;
right: 0;
}
.container2 {
position: relative;
width: 100%;
max-width: 400px;
}
.container2 img {
width: 100%;
height: auto;
border-radius: 10px;
}
.container2 img {
width: 100%;
height: auto;
border-radius: 10px;
}
.column2 {
float: center;
width: 2300%;
padding:8px;
}
.row2 {
width: 80%;
padding:5px;
position: relative;
left: 23%;
bottom: 5%;
margin-top:5%;
}
/* Clearfix (clear floats) */
.row2::after {
content: "";
clear: both;
display: table;
}
.row3 {
width: 80%;
padding:5px;
position: relative;
left: 23%;
bottom: 5%;
margin-top:5%;
}
/* Clearfix (clear floats) */
.row3::after {
content: "";
clear: both;
display: table;
}
*:focus {
outline: 0 !important;
}
/* PRODUCTS AND BUTTONS END */
/* Split the screen in half */
.split {
height: 100%;
width: 50%;
position: fixed;
z-index: 1;
top: 0;
overflow-x: hidden;
padding-top: 20px;
}
/* Control the left side */
.left {
left: 0;
background-color: rgb(240, 240, 240);
}
/* Control the right side */
.right {
right: 0;
background-color: rgb(255, 255, 255);
}
/* If you want the content centered horizontally and vertically */
.centered {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
}
.centered2 {
position: fixed;
top: 50%;
left: 55%;
transform: translate(-50%, -50%);
text-align: center;
}
/* Style the image inside the centered container, if needed */
.centered img {
width: 150px;
border-radius: 50%;
}
/* Please ❤ this if you like it! */
#import url('https://fonts.googleapis.com/css?family=Poppins:100,100i,200,200i,300,300i,400,400i,500,500i,600,600i,700,700i,800,800i,900,900i&subset=devanagari,latin-ext');
:root {
--white: #ffffff;
--light: #f0eff3;
--black: #000000;
--dark-blue: #ffffff;
--dark-light: #ffffff;
--red: #d8d8d8;
--yellow: #d8d8d8;
--grey: #ecedf3;
}
/* #Primary
================================================== */
body{
width: 100%;
background: var(--dark-blue);
overflow-x: hidden;
font-family: 'Poppins', sans-serif;
font-size: 17px;
line-height: 30px;
-webkit-transition: all 300ms linear;
transition: all 300ms linear;
}
p{
font-family: 'Poppins', sans-serif;
font-size: 17px;
line-height: 30px;
color: var(--white);
letter-spacing: 1px;
font-weight: 500;
-webkit-transition: all 300ms linear;
transition: all 300ms linear;
}
::selection {
color: var(--white);
background-color: var(--black);
}
::-moz-selection {
color: var(--white);
background-color: var(--black);
}
mark{
color: var(--white);
background-color: var(--black);
}
.section {
position: relative;
width: 100%;
}
.over-hide {
overflow: hidden;
}
.z-bigger {
z-index: 100 !important;
}
.background-color{
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: var(--dark-blue);
z-index: 1;
-webkit-transition: all 300ms linear;
transition: all 300ms linear;
}
.checkbox:checked ~ .background-color{
background-color: var(--white);
}
[type="checkbox"]:checked,
[type="checkbox"]:not(:checked),
[type="radio"]:checked,
[type="radio"]:not(:checked){
position: absolute;
left: -9999px;
width: 0;
height: 0;
visibility: hidden;
}
.checkbox:checked + label,
.checkbox:not(:checked) + label{
position: relative;
width: 70px;
display: inline-block;
padding: 0;
margin: 0 auto;
text-align: center;
margin: 17px 0;
margin-top: 100px;
height: 6px;
border-radius: 4px;
background-image: linear-gradient(298deg, var(--red), var(--yellow));
z-index: 100 !important;
}
.checkbox:checked + label:before,
.checkbox:not(:checked) + label:before {
position: absolute;
font-family: 'unicons';
cursor: pointer;
top: 17px;
z-index: 2;
font-size: 20px;
line-height: 40px;
text-align: center;
width: 40px;
height: 40px;
border-radius: 50%;
-webkit-transition: all 300ms linear;
transition: all 300ms linear;
}
.checkbox:not(:checked) + label:before {
content: '\eac1';
left: 0;
color: var(--grey);
background-color: var(--dark-light);
}
.checkbox:checked + label:before {
content: '\eb8f';
left: 30px;
color: var(--yellow);
background-color: var(--dark-blue);
}
.checkbox:checked ~ .section .container .row .col-12 p{
color: var(--dark-blue);
}
.checkbox-tools:checked + label,
.checkbox-tools:not(:checked) + label{
position: relative;
padding: 15px;
width: 50px;
float: left;
font-size: 14px;
line-height: 20px;
letter-spacing: 1px;
margin: 0 auto;
margin-left: 5px;
margin-right: 5px;
margin-bottom: 10px;
text-align: center;
border-radius: 7px;
overflow: hidden;
cursor: pointer;
text-transform: uppercase;
color: var(--white);
-webkit-transition: all 300ms linear;
transition: all 300ms linear;
}
.checkbox-tools:not(:checked) + label{
background-color: var(--dark-light);
}
.checkbox-tools:checked + label{
background-color: transparent;
}
.checkbox-tools:not(:checked) + label:hover{
box-shadow: 0 8px 8px 0 rgba(0, 0, 0, 0.2);
}
.checkbox-tools:checked + label::before,
.checkbox-tools:not(:checked) + label::before{
position: absolute;
content: '';
top: 0;
left: 0;
width: 100%;
height: 100%;
border-radius: 4px;
background-image: linear-gradient(298deg, var(--red), var(--yellow));
z-index: -1;
}
.checkbox-tools:checked + label .uil,
.checkbox-tools:not(:checked) + label .uil{
font-size: 24px;
line-height: 24px;
display: block;
padding-bottom: 10px;
}
.checkbox:checked ~ .section .container .row .col-12 .checkbox-tools:not(:checked) + label{
background-color: var(--light);
color: var(--dark-blue);
box-shadow: 0 1x 4px 0 rgba(0, 0, 0, 0.05);
}
.checkbox-budget:checked + label,
.checkbox-budget:not(:checked) + label{
position: relative;
display: inline-block;
padding: 0;
padding-top: 20px;
padding-bottom: 20px;
width: 260px;
font-size: 52px;
line-height: 52px;
font-weight: 700;
letter-spacing: 1px;
margin: 0 auto;
margin-left: 5px;
margin-right: 5px;
margin-bottom: 10px;
text-align: center;
border-radius: 4px;
overflow: hidden;
cursor: pointer;
text-transform: uppercase;
-webkit-transition: all 300ms linear;
transition: all 300ms linear;
-webkit-text-stroke: 1px var(--white);
text-stroke: 1px var(--white);
-webkit-text-fill-color: transparent;
text-fill-color: transparent;
color: transparent;
}
.checkbox-budget:not(:checked) + label{
background-color: var(--dark-light);
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.1);
}
.checkbox-budget:checked + label{
background-color: transparent;
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
}
.checkbox-budget:not(:checked) + label:hover{
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
}
.checkbox-budget:checked + label::before,
.checkbox-budget:not(:checked) + label::before{
position: absolute;
content: '';
top: 0;
left: 0;
width: 100%;
height: 100%;
border-radius: 4px;
background-image: linear-gradient(138deg, var(--red), var(--yellow));
z-index: -1;
}
.checkbox-budget:checked + label span,
.checkbox-budget:not(:checked) + label span{
position: relative;
display: block;
}
.checkbox-budget:checked + label span::before,
.checkbox-budget:not(:checked) + label span::before{
position: absolute;
content: attr(data-hover);
top: 0;
left: 0;
width: 100%;
overflow: hidden;
-webkit-text-stroke: transparent;
text-stroke: transparent;
-webkit-text-fill-color: var(--white);
text-fill-color: var(--white);
color: var(--white);
-webkit-transition: max-height 0.3s;
-moz-transition: max-height 0.3s;
transition: max-height 0.3s;
}
.checkbox-budget:not(:checked) + label span::before{
max-height: 0;
}
.checkbox-budget:checked + label span::before{
max-height: 100%;
}
.checkbox:checked ~ .section .container .row .col-xl-10 .checkbox-budget:not(:checked) + label{
background-color: var(--light);
-webkit-text-stroke: 1px var(--dark-blue);
text-stroke: 1px var(--dark-blue);
box-shadow: 0 1x 4px 0 rgba(0, 0, 0, 0.05);
}
.checkbox-booking:checked + label,
.checkbox-booking:not(:checked) + label{
position: relative;
display: -webkit-inline-flex;
display: -ms-inline-flexbox;
display: inline-flex;
-webkit-align-items: center;
-moz-align-items: center;
-ms-align-items: center;
align-items: center;
-webkit-justify-content: center;
-moz-justify-content: center;
-ms-justify-content: center;
justify-content: center;
-ms-flex-pack: center;
text-align: center;
padding: 0;
padding: 6px 25px;
font-size: 14px;
line-height: 30px;
letter-spacing: 1px;
margin: 0 auto;
margin-left: 6px;
margin-right: 6px;
margin-bottom: 16px;
text-align: center;
border-radius: 4px;
cursor: pointer;
color: var(--white);
text-transform: uppercase;
background-color: var(--dark-light);
-webkit-transition: all 300ms linear;
transition: all 300ms linear;
}
.checkbox-booking:not(:checked) + label::before{
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.1);
}
.checkbox-booking:checked + label::before{
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
}
.checkbox-booking:not(:checked) + label:hover::before{
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
}
.checkbox-booking:checked + label::before,
.checkbox-booking:not(:checked) + label::before{
position: absolute;
content: '';
top: -2px;
left: -2px;
width: calc(100% + 4px);
height: calc(100% + 4px);
border-radius: 4px;
z-index: -2;
background-image: linear-gradient(138deg, var(--red), var(--yellow));
-webkit-transition: all 300ms linear;
transition: all 300ms linear;
}
.checkbox-booking:not(:checked) + label::before{
top: -1px;
left: -1px;
width: calc(100% + 2px);
height: calc(100% + 2px);
}
.checkbox-booking:checked + label::after,
.checkbox-booking:not(:checked) + label::after{
position: absolute;
content: '';
top: -2px;
left: -2px;
width: calc(100% + 4px);
height: calc(100% + 4px);
border-radius: 4px;
z-index: -2;
background-color: var(--dark-light);
-webkit-transition: all 300ms linear;
transition: all 300ms linear;
}
.checkbox-booking:checked + label::after{
opacity: 0;
}
.checkbox-booking:checked + label .uil,
.checkbox-booking:not(:checked) + label .uil{
font-size: 20px;
}
.checkbox-booking:checked + label .text,
.checkbox-booking:not(:checked) + label .text{
position: relative;
display: inline-block;
-webkit-transition: opacity 300ms linear;
transition: opacity 300ms linear;
}
.checkbox-booking:checked + label .text{
opacity: 0.6;
}
.checkbox-booking:checked + label .text::after,
.checkbox-booking:not(:checked) + label .text::after{
position: absolute;
content: '';
width: 0;
left: 0;
top: 50%;
margin-top: -1px;
height: 2px;
background-image: linear-gradient(138deg, var(--red), var(--yellow));
z-index: 1;
-webkit-transition: all 300ms linear;
transition: all 300ms linear;
}
.checkbox-booking:not(:checked) + label .text::after{
width: 0;
}
.checkbox-booking:checked + label .text::after{
width: 100%;
}
.checkbox:checked ~ .section .container .row .col-12 .checkbox-booking:not(:checked) + label,
.checkbox:checked ~ .section .container .row .col-12 .checkbox-booking:checked + label{
background-color: var(--light);
color: var(--dark-blue);
}
.checkbox:checked ~ .section .container .row .col-12 .checkbox-booking:checked + label::after,
.checkbox:checked ~ .section .container .row .col-12 .checkbox-booking:not(:checked) + label::after{
background-color: var(--light);
}
.link-to-page {
position: fixed;
top: 30px;
right: 30px;
z-index: 20000;
cursor: pointer;
width: 50px;
}
.link-to-page img{
width: 100%;
height: auto;
display: block;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<link rel="stylesheet" href="main.css" />
<link rel="stylesheet" href="main.js" />
<title>REXIN 3D-AR DEMO</title>
<style>
</style>
</head>
<body>
<div class="split left">
</div>
<div class="split right">
<div class="centered2">
<div class="section over-hide z-bigger">
<input class="checkbox" type="checkbox" name="general" id="general">
<div class="section over-hide z-bigger">
<div class="container pb-5">
<div class="row justify-content-center pb-5">
<div class="col-12 pb-5">
<input class="checkbox-tools" type="radio" name="tools" id="tool-1" checked>
<label class="for-checkbox-tools" for="tool-1">
<img src="https://upload.wikimedia.org/wikipedia/commons/c/c0/Location_dot_black.svg" width="100%" height="100%">
</label>
<br>
<input class="checkbox-tools" type="radio" name="tools" id="tool-2">
<label class="for-checkbox-tools" for="tool-2">
<img src="https://upload.wikimedia.org/wikipedia/commons/c/c0/Location_dot_black.svg" width="100%" height="100%">
</label>
<br>
<input class="checkbox-tools" type="radio" name="tools" id="tool-3">
<label class="for-checkbox-tools" for="tool-3">
<img src="https://upload.wikimedia.org/wikipedia/commons/c/c0/Location_dot_black.svg" width="100%" height="100%">
</label>
<br>
<input class="checkbox-tools" type="radio" name="tools" id="tool-4">
<label class="for-checkbox-tools" for="tool-4">
<img src="https://upload.wikimedia.org/wikipedia/commons/c/c0/Location_dot_black.svg" width="100%" height="100%">
</label>
<br>
<input class="checkbox-tools" type="radio" name="tools" id="tool-5">
<label class="for-checkbox-tools" for="tool-5">
<img src="https://upload.wikimedia.org/wikipedia/commons/c/c0/Location_dot_black.svg" width="100%" height="100%">
</label>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row2">
<div class="column2">
<div class="container2">
<img src="Assets/photos/terrassen.jpg" alt="Snow" style="width:100%">
<a href="terrassendach.html"> <button class="button" style="vertical-align:top">
<span>Terrassendach </span></button></a>
</div>
</div>
<div class="column2">
<div class="container2">
<img src="Assets/photos/pergolen.jpg" alt="Snow" style="width:100%">
<a href="pergolen.html"> <button class="button" style="vertical-align:top">
<span>Pergolen </span></button></a>
</div>
</div>
<div class="column2">
<div class="container2">
<img src="Assets/photos/carport.jpg" alt="Snow" style="width:100%">
<a href="carport.html"> <button class="button" style="vertical-align:top">
<span>Carport </span></button></a>
</div>
</div>
<div class="column2">
<div class="container2">
<img src="Assets/photos/Vordächer.jpg" alt="Snow" style="width:100%">
<a href="vordacher.html"> <button class="button" style="vertical-align:top">
<span>Vordächer </span></button></a>
</div>
</div>
</div>
<div class="row3">
<div class="column2">
<div class="container2">
<img src="Assets/photos/terrassen.jpg" alt="Snow" style="width:100%">
<a href="terrassendach.html"> <button class="button" style="vertical-align:top">
<span>Terrassendach </span></button></a>
</div>
</div>
<div class="column2">
<div class="container2">
<img src="Assets/photos/pergolen.jpg" alt="Snow" style="width:100%">
<a href="pergolen.html"> <button class="button" style="vertical-align:top">
<span>Pergolen </span></button></a>
</div>
</div>
<div class="column2">
<div class="container2">
<img src="Assets/photos/carport.jpg" alt="Snow" style="width:100%">
<a href="carport.html"> <button class="button" style="vertical-align:top">
<span>Carport </span></button></a>
</div>
</div>
<div class="column2">
<div class="container2">
<img src="Assets/photos/Vordächer.jpg" alt="Snow" style="width:100%">
<a href="vordacher.html"> <button class="button" style="vertical-align:top">
<span>Vordächer </span></button></a>
</div>
</div>
</div>
</div>
</body>
Try this! (Run code snippet to see)
Codepen: https://codepen.io/dhanushbadge/pen/kICBu
Made by: #Dhanush Badge
function show1(){
document.getElementById('div1').style.display ='none';
}
function show2(){
document.getElementById('div1').style.display = 'block';
}
body {
font-family: arial;
}
.hide {
display: none;
}
p {
font-weight: bold;
}
<p>How many check boxes do you want when clicked on a radio button?</p>
<input type="radio" name="tab" value="igotnone" onclick="show1();" />
None
<input type="radio" name="tab" value="igottwo" onclick="show2();" />
Two
<div id="div1" class="hide">
<hr><p>Okay Cool! Here are those two...</p>
<input type="checkbox" value="Yes" name="one">
One
<input type="checkbox" value="Yes" name="two">
Two
</div>

label only changes font-size but not moving up [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I'm trying to move the label above the input field when focus like this.
But in my other code, it only changes font-size and is not moving up. What am I missing?
I use the same CSS code for both:
CSS
input:focus + label > span {
font-size: 12px;
transform: translate3d(0, -80%, 0);
transition-timing-function: cubic-bezier(0.2, 1, 0.3, 1);
}
Target The Span Within The Lable
If you target the span contained in the label, you can control it with the below code.
input + label > span {
position: relative;
display: block;
bottom: -1em
}
Your code needs a lot of work, but start here:
body {
background-color: #f0f0f0;
}
form {
margin-left: 40%;
margin-top: 11%;
}
label {
font-family: monospace; 'Montserrat', sans-serif;
font-size: 19px;
margin-left: -26%;
z-index: -1;
/* border: 5px solid black;*/
}
.head {
margin-left: 43%;
margin-top: 5%;
font-size: 25px;
font-family: monospace;
}
form {
position: relative; }
.input-field {
display:block;
background: transparent;
border-width: 2px;
border-top: 0;
border-left: 0;
border-right: 0;
border: 0;
background: transparent;
outline: 0;
height: 23px;
border-color: black;
width: 130px;
z-index: 1;
margin-left: 0%;
}
/*input:focus {
transform: scale3d(1, 1, 1);
transition: width 5s;
transition-delay: 3s;
transition-timing-function: cubic-bezier(0.2, 1, 0.3, 1);
z-index: -1;
background: green; /* ::after background *
} */
label::after {
content: '';
position: absolute;
top: 100%;
left: 0;
width: 30%;
height: 20%;
transition: transform 0.8s;
}
label::after {
z-index: -1;
background: green; /* ::after background */
transform: scale3d(1, 0.1, 1);
transform-origin: 0% 0%;
}
input:focus + label::after {
transform: scale3d(1, -2, 1);
transition-timing-function: linear;
}
input:focus + label > span {
font-size: 14px;
transform: translate3d(0, -200%, 0);
transition-timing-function: cubic-bezier(0.2, 1, 0.3, 1);
}
input + label > span {
position: relative;
display: block;
bottom: -1em
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet">
<title>Test</title>
</head>
<body>
<p class="head">Sign In</p>
<form>
<div class="username">
<input type="text" name="name" class="input-field" id="user"/> <!--input filed-->
<label for="user">
<span class="username">Username</span>
</label>
</div>
</form>
</body>
</html
Filtered Code. You can Use This Code. This is working Fine.
.object {
position: relative;
z-index: 1;
display: inline-block;
width: 300px; /* input field width */
}
.input {
position: relative;
display: block;
float: right;
width: 30%;
border: none;
background: black;
color: yellow; /* font color when typing */
font-family: monospace;
/* for box shadows to show on iOS */
}
.input:focus {
outline: none;
}
.label {
display: inline-block;
color: black; /* label font color */
font-size: 18px;
font-family: monospace;
}
.label-content {
position: relative;
display: block;
padding: .6em 0;
}
.input--jiro {
padding: 0.85em 0.5em;
width: 100%; /* input width when focus */
background: blue ; /* input background color */
opacity: 0;
transition: opacity 0.3s;
}
.label-content--jiro {
transition: transform 0.3s 0.3s;
}
.label--jiro {
position: absolute;
left: 0;
padding: 0 0.85em;
width: 120%; /* underline width */
height: 100%;
}
label::after {
content: '';
position: absolute;
top: 100%;
left: 0;
width: 80%;
height: 100%;
transition: transform .8s;
}
label::after {
z-index: -1;
background: green; /* ::after background */
transform: scale3d(1, 0.1, 1);
transform-origin: 0% 0%; /* 0% 50%; * for middle */
}
input:focus + label::after {
transform: scale3d(1, -1, 1);
transition-timing-function: linear;
}
input:focus + label > span {
font-size: 12px;
transform: translate3d(0, -80%, 0);
transition-timing-function: cubic-bezier(0.2, 1, 0.3, 1);
}
<p class="head">Sign In</p>
<section>
<span class="object">
<input class="input input--jiro" type="text" id="input-10" /> <!-- input field -->
<label class="label label--jiro" for="input-10">
<span class="label-content label-content--jiro">Username</span> <!-- Label -->
</label>
</span>
</section>

Why is there some excess scale at the bottom? how to remove those?

There's a little royalblue background appearing (between border-bottom: 2px solid white; & ::after element) when I unfocus.
I don't know why is that happening.
body {
background-color: royalblue;/*#f0f0f0;*/
}
label {
font-family: 'Montserrat', sans-serif;
font-size: 14px;
z-index: -1;
border: 0;
color: white;
position: relative;
}
.head {
color: white;
margin-left: 44%;
font-family: monospace;
font-size: 25px;
}
/*.content {
margin-top: 10%;
margin-left: 41%;
}*/
.password {
margin-top: 8%;
}
form {
position: relative;
}
input {
position: absolute;
font-family: 'Montserrat', sans-serif;
font-size: 15px;
background: transparent;
border: 0; /* BORDER yes/no */
border-bottom: 2px solid white;
background: transparent;
outline: 0;
height: 25px;
width: 180px;
z-index: 1;
margin-top: 5px;
}
/*input:focus {
outline: 1;
}*/
label::after {
content: '';
position: absolute;
top: -2px;
left: 0;
width: 180px;
height: 25px;
border-radius: 2px;
transition: transform .3s;
}
label::after{
z-index: -1;
background: beige; /*#a86bf;*/
transform: scale3d(1, 0, 1);
transform-origin: 0% 0%;
}
input:focus {
border-radius: 1px;
}
input:focus + label::after,
input:valid + label::after {
transform: scale3d(1, -1, 1);
transition-timing-function: linear;
}
span {
position: relative;
margin-top: -30px;
display: block;
padding: .6em 0;
padding-left: -5px;
transition: top .5s ease, font-size .5s ease;
/* transition: transform 1s 2s;*/
top: 0;
}
input:focus + label > span,
input:valid + label > span {
top: -20px;
font-size: 11px;
padding-bottom: 15px;
}
/* font-family: monospace;*/
/*transform: translate3d(0, -80%, 0); */
/* transition-timing-function: linear;*/
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet">
<title>Test</title>
</head>
<body>
<p class="head">Sign In</p>
<form>
<div class="content">
<div class="username">
<input type="text" name="name" class="user-input" id="user" required /> <!--input field-->
<label class="user-label" for="user"><span>Username</span></label>
</div>
<div class="password">
<input type="text" name="name" class="pass-input" id="pass" required /> <!-- input field -->
<label class="pass-label" for="pass"><span>Password</span></label>
</div>
</div>
</form>
</body>
</html>
Update:
I changed to top: 1px;, also change border-bottom to black, now this is the result (full code). Why is there some excess scale at the bottom? how to remove those?
You have a top: -2px on label, and your problem is when you blur, so a solution is move top: -2px to input:focus + label::after and input:focus + label::after, so you dont have that gap when its not focused or validated
body {
background-color: royalblue;/*#f0f0f0;*/
}
label {
font-family: 'Montserrat', sans-serif;
font-size: 14px;
z-index: -1;
border: 0;
color: white;
position: relative;
}
.head {
color: white;
margin-left: 44%;
font-family: monospace;
font-size: 25px;
}
/*.content {
margin-top: 10%;
margin-left: 41%;
}*/
.password {
margin-top: 8%;
}
form {
position: relative;
}
input {
position: absolute;
font-family: 'Montserrat', sans-serif;
font-size: 15px;
background: transparent;
border: 0; /* BORDER yes/no */
border-bottom: 2px solid white;
background: transparent;
outline: 0;
height: 25px;
width: 180px;
z-index: 1;
margin-top: 5px;
}
/*input:focus {
outline: 1;
}*/
label::after {
content: '';
position: absolute;
left: 0;
width: 180px;
height: 25px;
border-radius: 2px;
transition: transform .3s;
}
label::after{
z-index: -1;
background: beige; /*#a86bf;*/
transform: scale3d(1, 0, 1);
transform-origin: 0% 0%;
}
input:focus {
border-radius: 1px;
}
input:focus + label,
input:valid + label {
top: -2px;
}
input:focus + label::after,
input:valid + label::after {
transform: scale3d(1, -1, 1);
transition-timing-function: linear;
}
span {
position: relative;
margin-top: -30px;
display: block;
padding: .6em 0;
padding-left: -5px;
transition: top .5s ease, font-size .5s ease;
top: 0;
}
input:focus + label > span,
input:valid + label > span {
top: -20px;
font-size: 11px;
padding-bottom: 15px;
}
/* font-family: monospace;*/
/*transform: translate3d(0, -80%, 0); */
/* transition-timing-function: linear;*/
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet">
<title>Test</title>
</head>
<body>
<p class="head">Sign In</p>
<form>
<div class="content">
<div class="username">
<input type="text" name="name" class="user-input" id="user" required /> <!--input field-->
<label class="user-label" for="user"><span>Username</span></label>
</div>
<div class="password">
<input type="text" name="name" class="pass-input" id="pass" required /> <!-- input field -->
<label class="pass-label" for="pass"><span>Password</span></label>
</div>
</div>
</form>
</body>
</html>
you have an extra code, you can see here in comment section
label::after {
content: '';
position: absolute;
/*top: -2px;*/
left: 0;
width: 180px;
height: 25px;
border-radius: 2px;
transition: transform .3s;
}
Add top:1px on label::after See Below.
label::after {
content: '';
position: absolute;
left: 0;
top: 1px;
width: 180px;
height: 25px;
border-radius: 2px;
transition: transform .3s;
}