I made a subscribe button for a mailing list and it works on PC/desktop view, but not on mobile devices (touchscreens).
You can click it and it works on desktop, but it doesn't do anything when you touch it on a mobile device.
It's just plain html and CSS. The code is below along with the media only properties.
Thanks in advance!
HTML
<div class="main">
<form
action="mailto:info#feudalerockband.com?subject=Mailing List"
method="POST"
enctype="text/plain"
name="EmailForm"
id="singular-form">
<button class="shown" type="button" id="subs">Subscribe to our mailing list!</button>
<div id="email-input">
<input type="text" placeholder="Email" id="email" name="Email Address">
<button type="button" class="addbut1">Subscribe</button>
</div>
<div id="success">Successfully subscribed to mailing list!</div>
</form>
</div>
CSS
.main {
align-items: center;
margin: auto;
width: 25rem;
height: 5rem;
padding: 12px;
background-color: rgb(41,47,51);
text-align: center;
border-radius: 1rem;
overflow: hidden;
transition: width .6s cubic-bezier(0.68, -0.55, 0.27, 1.55);
}
.main>#singular-form {
position: relative;
width: 100%;
height: 100%;
background-color: rgb(41,47,51);
}
.main>#singular-form button {
width: 9rem;
padding: 0;
border: none;
outline: none;
border-radius: 3rem;
cursor: pointer;
}
.main>#singular-form>#subs {
padding: 0;
width: 100%;
color: white;
font-weight: bold;
background-color: transparent;
z-index: 3;
}
.main>#singular-form>#email-input {
z-index: 2;
}
.main>#singular-form>#email-input>input {
display: inline-block;
height: 100%;
width: 100%;
border-radius: 10px;
background-color: white;
box-sizing: border-box;
border: none;
outline: none;
padding: 0 26% 0 3%;
opacity: 0;
transform: scale(0);
transition: all .6s ease .4s;
}
.main>#singular-form>#email-input>button {
position: absolute;
top: 0;
right: 0;
height: 100%;
border-radius: 5px;
background-color: rgb(13, 110, 253);
color: white;
opacity: 0;
transform: scale(0);
transition: all .6s ease .4s;
}
.main>#singular-form>#success {
display: flex;
justify-content: center;
align-items: center;
color: white;
font-weight: bold;
z-index: 1;
}
.main>#singular-form>#subs,
.main>#singular-form>#email-input,
.main>#singular-form>#success {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
transform: scale(0);
opacity: 0;
}
.main>#singular-form>#subs {
transition: all .6s ease;
}
.main>#singular-form>#email-input {
transform: scale(1);
opacity: 1;
transition: all .6s ease .4s;
}
.main>#singular-form>#success {
transition: all .2s ease .6s;
}
.main>#singular-form>#subs.shown,
.main>#singular-form>#email-input.shown,
.main>#singular-form>#success.shown,
.main>#singular-form>#email-input>button.shown,
.main>#singular-form>#email-input>input.shown {
transform: scale(1);
opacity: 1;
}
MEDIA ONLY VIEW
.main {
max-width: 350px;
margin: auto;
}
you must change the type of button to submit or leave it with out type
just like this
<button type="submit" class="addbut1">Subscribe</button>
or
<button class="addbut1">Subscribe</button>
so the code will be like this
<div class="main">
<form
action="mailto:info#feudalerockband.com?subject=Mailing List"
method="POST"
enctype="text/plain"
name="EmailForm"
id="singular-form">
<button class="shown" type="button" id="subs">Subscribe to our mailing list!</button>
<div id="email-input">
<input type="text" placeholder="Email" id="email" name="Email Address">
<button class="addbut1">Subscribe</button>
</div>
<div id="success">Successfully subscribed to mailing list!</div>
</form>
</div>
Related
When I click my <a> tag for the popup box, the images in the background (with overlay effects) are glowing up, and I don't know why. If anybody know something I write the code under here.
As you can see I've put href to #popup1 in the first <a> tag, and it opens the popup box, but in the background you can see the image like glowing, the border too.
I've changed the display tag and other CSS tags, but nothing.
Here is the Codepen.
the problem is actually you add pop-up before container 2 so that's why it is glowing.
So, if you dont want to make this glow just add your pop-up division after both
containers like this.
Dont change your Css. you just have to change position of divisions like this
<div class="container1" style="cursor:default;">
<div class="container2">
<div class="content">
<a id="ant" href="#popup1" onclick="show('popup2')">
<div class="content-overlay"></div>
<img class="content-image" src="https://i.postimg.cc/5tNkjkV5/2.png" style="z-index: 0;height: 200px;width: 330px;border:2px solid rgb(205,144,76);padding:0;">
<div class="content-details fadeIn-bottom" style="background-size:cover;">
<h3 class="content-title" style="font-family: 'Roboto', sans-serif;">ANTIPASTI</h3>
<p class="content-text"></p>
</div>
</a>
</div>
</div>
<div class="container2">
<div class="content">
<a id="prim">
<div class="content-overlay"></div>
<img class="content-image" src="https://i.postimg.cc/5tNkjkV5/2.png" style="border:2px solid rgb(205,144,76);padding:0; height:200px; width:330px;">
<div class="content-details fadeIn-bottom">
<h3 class="content-title" style="font-family: 'Roboto', sans-serif;"> PRIMI PIATTI </h3>
<p class="content-text"></p>
</div>
</a>
</div>
</div>
</div>
<div id="popup1" class="popup">
×
<h2>The Popup Has Arrived</h2>
<p>QUESTI SONO GLI ANTIPASTI</p>
</div>
<a href="#ant" class="close-popup"></a
It depends on the order of your HTML-Elements. This example will fix the problem
.container1 {
display: flex;
width: 100%;
flex-wrap: wrap;
margin-top: 110px;
align-content: space-around;
justify-content: center;
transition: all 0.2s linear;
}
.container1 > div {
padding: 40px;
justify-content: center;
}
*,
*:before,
*:after {
margin: 0;
padding: 0;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.main-title {
color: #2d2d2d;
text-align: center;
text-transform: capitalize;
padding: 0.7em 0;
}
.container {
padding: 1em 0;
float: left;
width: 50%;
}
#media screen and (max-width: 640px) {
.container {
display: block;
width: 100%;
}
}
#media screen and (min-width: 900px) {
.container {
width: 33.33333%;
}
}
.container .title {
color: #1a1a1a;
font-family: 'Roboto', sans-serif;
text-align: center;
margin-bottom: 10px;
}
.content {
position: relative;
width: 100%;
max-width: 400px;
height: 100%;
margin: auto;
overflow: hidden;
transition: transform 0.4s;
}
.content .content-overlay {
/* background: rgba(70,34,0);*/
background: rgba(214, 142, 60, 70%);
/* background: rgb(214,142,60);*/
position: absolute;
height: 97%;
width: 100%;
left: 30px;
top: 0;
bottom: 0;
right: 0;
opacity: 0;
-webkit-transition: all 0.4s ease-in-out 0s;
-moz-transition: all 0.4s ease-in-out 0s;
transition: all 0.4s ease-in-out 0s;
}
.content:hover .content-overlay {
opacity: 0.5;
}
.content-details {
position: absolute;
text-align: center;
padding-left: 1em;
padding-right: 1em;
width: 100%;
top: 50%;
left: 50%;
opacity: 0;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
-webkit-transition: all 0.3s ease-in-out 0s;
-moz-transition: all 0.3s ease-in-out 0s;
transition: all 0.3s ease-in-out 0s;
}
.content:hover .content-details {
top: 50%;
left: 50%;
right: 50%;
opacity: 1;
}
.content-details h3 {
color: #fff;
font-weight: 500;
text-align: center;
letter-spacing: 0.15em;
margin-bottom: 0.5em;
padding-left: 20px;
text-transform: uppercase;
}
.content-details p {
color: #fff;
font-size: 0.8em;
text-align: center;
padding-left: 20px;
}
.fadeIn-bottom {
top: 80%;
}
.fadeIn-top {
top: 20%;
}
.fadeIn-left {
left: 20%;
}
.fadeIn-right {
left: 80%;
}
h1 {
font-size: 3em;
text-align: center;
color: #00898e;
margin: 0;
padding: 30vh 0 1em;
}
h2 {
text-align: center;
white-space: nowrap;
color: #00898e;
}
a {
text-decoration: none;
color: #fff;
}
p {
text-align: left;
}
.btn {
display: inline-block;
padding: 10px 20px;
border: 2px solid #00898e;
border-radius: 10px;
transition: background 0.3s;
}
.btn:hover {
background: #00898e;
}
.popup {
position: fixed;
padding: 10px;
max-width: 500px;
border-radius: 10px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: rgba(255, 255, 255, 0.9);
visibility: hidden;
opacity: 0;
/* "delay" the visibility transition */
-webkit-transition: opacity 0.5s, visibility 0s linear 0.5s;
transition: opacity 0.5s, visibility 0s linear 0.5s;
z-index: 1;
}
.popup:target {
visibility: visible;
opacity: 1;
/* cancel visibility transition delay */
-webkit-transition-delay: 0s;
transition-delay: 0s;
}
.popup-close {
position: absolute;
padding: 10px;
max-width: 500px;
border-radius: 10px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: rgba(255, 255, 255, 0.9);
}
.popup .close {
position: absolute;
right: 5px;
top: 5px;
padding: 5px;
color: #000;
transition: color 0.3s;
font-size: 2em;
line-height: 0.6em;
font-weight: bold;
}
.popup .close:hover {
color: #00e5ee;
}
.close-popup {
background: rgba(0, 0, 0, 0.7);
cursor: default;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
opacity: 0;
visibility: hidden;
/* "delay" the visibility transition */
-webkit-transition: opacity 0.5s, visibility 0s linear 0.5s;
transition: opacity 0.5s, visibility 0s linear 0.5s;
}
.popup:target + .close-popup {
opacity: 1;
visibility: visible;
/* cancel visibility transition delay */
-webkit-transition-delay: 0s;
transition-delay: 0s;
}
<div class="container1" style="cursor: default">
<div class="container2">
<div class="content">
<a id="ant" href="#popup1" onclick="show('popup2')">
<div class="content-overlay"></div>
<img
class="content-image"
src="https://i.postimg.cc/5tNkjkV5/2.png"
style="z-index: 0; height: 200px; width: 330px; border: 2px solid rgb(205, 144, 76); padding: 0"
/>
<div class="content-details fadeIn-bottom" style="background-size: cover">
<h3 class="content-title" style="font-family: 'Roboto', sans-serif">ANTIPASTI</h3>
<p class="content-text"></p>
</div>
</a>
</div>
</div>
<div class="container2">
<div class="content">
<a id="prim">
<div class="content-overlay"></div>
<img
class="content-image"
src="https://i.postimg.cc/5tNkjkV5/2.png"
style="border: 2px solid rgb(205, 144, 76); padding: 0; height: 200px; width: 330px"
/>
<div class="content-details fadeIn-bottom">
<h3 class="content-title" style="font-family: 'Roboto', sans-serif">PRIMI PIATTI</h3>
<p class="content-text"></p>
</div>
</a>
</div>
</div>
<!-- The popup should be entered as the last element so that it overlays the other elements -->
<div id="popup1" class="popup">
×
<h2>The Popup Has Arrived</h2>
<p>QUESTI SONO GLI ANTIPASTI</p>
</div>
</div>
I have 3 input box and I want to give padding between them.
I can't understand where to put padding.
Link to codepen
I have 3 Input boxes.
#import url(https://fonts.googleapis.com/css?family=Montserrat);
body {
display: inline-block;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
font-family: Montserrat;
background: #313E50;
}
.text-input {
position: relative;
margin-top: 50px;
display: inline-block;
}
.text-input input[type="text"] {
display: inline-block;
width: 300px;
height: 40px;
box-sizing: border-box;
outline: none;
border: 1px solid lightgray;
border-radius: 3px;
padding: 10px 10px 10px 100px;
transition: all 0.1s ease-out;
}
.text-input input[type="text"]+label {
position: absolute;
top: 0;
left: 0;
bottom: 0;
height: 40px;
line-height: 40px;
color: white;
border-radius: 3px 0 0 3px;
padding: 0 20px;
background: #E03616;
-webkit-transform: translateZ(0) translateX(0);
transform: translateZ(0) translateX(0);
transition: all 0.3s ease-in;
transition-delay: 0.2s;
}
.text-input input[type="text"]:focus+label {
-webkit-transform: translateY(-120%) translateX(0%);
transform: translateY(-120%) translateX(0%);
border-radius: 3px;
transition: all 0.1s ease-out;
}
.text-input input[type="text"]:focus {
padding: 10px;
transition: all 0.3s ease-out;
transition-delay: 0.2s;
}
<div class="text-input">
<input type="text" id="input1" placeholder="Try typing something in here!">
<label for="input1">Name</label>
</div>
<div class="text-input">
<input type="text" id="input1" placeholder="Try typing something in here!">
<label for="input1">Name</label>
</div>
<div class="text-input">
<input type="text" id="input1" placeholder="Try typing something in here!">
<label for="input1">Name</label>
</div>
Add margin-right on .text-input
.text-input{
position: relative;
margin-top: 50px;
display: inline-block;
margin-right: 50px;/*Add This*/
https://codepen.io/anon/pen/GLzJvM
please try this css :
.text-input {
margin-left: 10px;
margin-right: 10px;
}
I'm trying to align three buttons inside a form, but the central one is always fixed at the bottom.
jsfiddle sketch
---HTML---
<form action="view.php" method="GET">
<button class="option delete-option" type="button"></button>
<button class="btn" type="submit">59752fbd5f346</button>
<button class="option edit-option" type="button"></button>
</form>
---CSS---
.btn {
font-family: 'Arima Madurai', cursive;
background-color: Transparent;
color: black;
cursor: pointer;
font-size: 16px;
max-width: 300px;
position: relative;
width: 100%;
border: 1px solid;
overflow: hidden;
}
.btn span {
font-family: 'Arima Madurai', cursive;
}
.btn:after {
background: red;
content: "";
height: 155px;
left: -75px;
opacity: .2;
position: absolute;
top: -50px;
-webkit-transform: rotate(35deg);
transform: rotate(35deg);
-webkit-transition: all 2000ms cubic-bezier(0.19, 1, 0.22, 1);
transition: all 2000ms cubic-bezier(0.19, 1, 0.22, 1);
width: 50px;
z-index: -10;
}
.btn:hover:after {
left: 120%;
-webkit-transition: all 2000ms cubic-bezier(0.19, 1, 0.22, 1);
transition: all 2000ms cubic-bezier(0.19, 1, 0.22, 1);
}
.option{
opacity: 0.5;
transition: 200ms;
width: 32px;
height: 32px;
border: 0;
position: relative;
}
.option:hover{
opacity: 1;
}
.delete-option{
background: url("http://icons.iconarchive.com/icons/awicons/vista-artistic/32/delete-icon.png") no-repeat scroll 0 0 transparent;
}
.edit-option{
background: url("http://icons.iconarchive.com/icons/custom-icon-design/mono-general-2/32/edit-icon.png") no-repeat scroll 0 0 transparent;
}
I noticed also that opening the Page from Mozilla, the central button seems to be fixed at the top.
You can make the form a flexbox:
form {
display: flex;
justify-content: space-between;
width: 70%; /* just for demo */
}
.delete-option {
background: url(http://icons.iconarchive.com/icons/awicons/vista-artistic/32/delete-icon.png) no-repeat scroll 0 0 transparent;
}
.btn {
font-family: 'Arima Madurai', cursive;
background-color: Transparent;
color: black;
cursor: pointer;
font-size: 16px;
max-width: 300px;
position: relative;
width: 100%;
border: 1px solid;
overflow: hidden;
}
.edit-option {
background: url(http://icons.iconarchive.com/icons/custom-icon-design/mono-general-2/32/edit-icon.png) no-repeat scroll 0 0 transparent;
}
.option {
opacity: 0.5;
transition: 200ms;
width: 32px;
height: 32px;
border: 0;
position: relative;
}
<form action="view.php" method="GET">
<button class="option delete-option" type="button"></button>
<button class="btn" type="submit">59752fbd5f346</button>
<button class="option edit-option" type="button"></button>
</form>
Use Vertical-align:middle; property
Try this
.option,.btn{
vertical-align:middle;
}
Link for Reference
I have this simple HTML/CSS slider with only 2 slides.
I need to make it autoplay the slides every 7 seconds.
I am not familiar with jquery or javascript, so it would be easier for me to implement a css solution...
Can you help?
You can see it in action right now at
http://www.hotelgalatas.com/test/
Thanks!
body {
overflow: hidden;
width: 100%;
height: 100%;
padding: 0;
margin: 0;
}
/* Slider wrapper*/
.css-slider-wrapper {
display: block;
background: #FFF;
overflow: hidden;
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
}
/* Slider */
.slider {
width: 100%;
height: 100%;
background: #ccc;
position: absolute;
left: 0;
top: 0;
opacity: 1;
z-index: 0;
display: flex;
display: -webkit-flex;
display: -ms-flexbox;
flex-direction: row;
flex-wrap: wrap;
-webkit-flex-align: center;
-webkit-align-items: center;
align-items: center;
justify-content: center;
align-content: center;
-webkit-transition: -webkit-transform 1600ms;
transition: -webkit-transform 1600ms, transform 1600ms;
-webkit-transform: scale(1);
transform: scale(1);
}
/* each slide background color */
.slide1 {
background: #00bcd7;
left: 0;
}
.slide2 {
background: #009788;
left: 100%;
}
.slider>div {
text-align: center;
}
/* Slider inner slide effect */
.slider h2 {
color: #FFF;
font-weight: 900;
text-transform: uppercase;
font-size: 45px;
line-height: 120%;
opacity: 0;
-webkit-transform: translateX(500px);
transform: translateX(500px);
}
.slider .button {
color: #FFF;
padding: 5px 30px;
background: rgba(255, 255, 255, 0.3);
text-decoration: none;
opacity: 0;
font-size: 15px;
line-height: 30px;
display: inline-block;
-webkit-transform: translateX(-500px);
transform: translateX(-500px);
}
.slider h2,
.slider .button {
-webkit-transition: opacity 800ms, -webkit-transform 800ms;
transition: transform 800ms, opacity 800ms;
-webkit-transition-delay: 1s;
/* Safari */
transition-delay: 1s;
}
/* Next and Prev arrows */
.control {
position: absolute;
top: 50%;
width: 50px;
height: 50px;
margin-top: -25px;
z-index: 55;
}
.control label {
z-index: 0;
display: none;
text-align: center;
line-height: 50px;
font-size: 50px;
color: #FFF;
cursor: pointer;
opacity: 0.2;
}
.control label:hover {
opacity: 0.5;
}
.next {
right: 1%;
}
.previous {
left: 1%;
}
/* Slider Pager */
.slider-pagination {
position: absolute;
bottom: 20px;
width: 100%;
left: 0;
text-align: center;
z-index: 1000;
}
.slider-pagination label {
width: 10px;
height: 10px;
border-radius: 50%;
display: inline-block;
background: rgba(255, 255, 255, 0.2);
margin: 0 2px;
border: solid 1px rgba(255, 255, 255, 0.4);
cursor: pointer;
}
/* Slider Pager arrow event */
.slide-radio1:checked~.next .numb2,
.slide-radio2:checked~.previous .numb1 {
display: block;
z-index: 1
}
/* Slider Pager event */
.slide-radio1:checked~.slider-pagination .page1,
.slide-radio2:checked~.slider-pagination .page2 {
background: rgba(255, 255, 255, 1)
}
/* Slider slide effect */
.slide-radio1:checked~.slider {
-webkit-transform: translateX(0%);
transform: translateX(0%);
}
.slide-radio2:checked~.slider {
-webkit-transform: translateX(-100%);
transform: translateX(-100%);
}
.slide-radio1:checked~.slide1 h2,
.slide-radio2:checked~.slide2 h2,
.slide-radio1:checked~.slide1 .button,
.slide-radio2:checked~.slide2 .button {
-webkit-transform: translateX(0);
transform: translateX(0);
opacity: 1
}
#media only screen and (max-width: 767px) {
.slider h2 {
font-size: 20px;
}
.slider>div {
padding: 0 2%
}
.control label {
font-size: 35px;
}
.slider .button {
padding: 0 15px;
}
}
<div class="css-slider-wrapper">
<input type="radio" name="slider" class="slide-radio1" checked id="slider_1">
<input type="radio" name="slider" class="slide-radio2" id="slider_2">
<div class="slider-pagination">
<label for="slider_1" class="page1"></label>
<label for="slider_2" class="page2"></label>
</div>
<div class="next control">
<label for="slider_1" class="numb1"><i class="fa fa-arrow-circle-right"></i>
</label>
<label for="slider_2" class="numb2"><i class="fa fa-arrow-circle-right"></i>
</label>
</div>
<div class="previous control">
<label for="slider_1" class="numb1"><i class="fa fa-arrow-circle-left"></i>
</label>
<label for="slider_2" class="numb2"><i class="fa fa-arrow-circle-left"></i>
</label>
</div>
<div class="slider slide1">
<div>
<h2>First Slide Text</h2>
Button1 Button2 </div>
</div>
<div class="slider slide2">
<div>
<h2>Second Slide Text</h2>
Button1 Button2 </div>
</div>
</div>
to deal with time you have to use javascript/jquery.
you can access the slides by using class names and add/hide the elements every 7 seconds and use them with setInterval function.
var interval = setInterval(function () {document.getElementById('previous-control').addClass('hide'); document.getElementById('next-control').addClass('show'); }, 7000);
where you have to add the hide and show classes in css with display none and block
I have a switch button. But it doesn't work with the input type radio. If I try with checkbox button it works. Why? How can I solve, maintaining the radio input?
#charset "utf-8";
/* CSS Document */
/* ---------- GENERAL ---------- */
body {
background: #4a4a4a;
color: #151515;
font: 100%/1.5em "Lato", sans-serif;
margin: 0;
}
input {
font-family: inherit;
font-size: 100%;
line-height: normal;
margin: 0;
}
input[type="radio"] {
box-sizing: border-box;
padding: 0;
}
/* ---------- SWITCH ---------- */
.container {
height: 64px;
left: 50%;
margin: -32px 0 0 -80px;
position: absolute;
top: 50%;
width: 160px;
}
.switch {
background: #fff;
border-radius: 32px;
display: block;
height: 64px;
position: relative;
width: 160px;
}
.switch label {
color: #fff;
font-size: 48px;
font-weight: 300;
line-height: 64px;
text-transform: uppercase;
-webkit-transition: color .2s ease;
-moz-transition: color .2s ease;
-ms-transition: color .2s ease;
-o-transition: color .2s ease;
transition: color .2s ease;
width: 100px;
}
.switch label:nth-of-type(1) {
left: -75%;
position: absolute;
text-align: right;
}
.switch label:nth-of-type(2) {
position: absolute;
right: -75%;
text-align: left;
}
.switch input {
height: 64px;
left: 0;
opacity: 0;
position: absolute;
top: 0;
width: 160px;
z-index: 2;
}
.switch input:checked~label:nth-of-type(1) { color: #fff; }
.switch input:checked~label:nth-of-type(2) { color: #808080; }
.switch input~:checked~label:nth-of-type(1) { color: #808080; }
.switch input~:checked~label:nth-of-type(2) { color: #fff; }
.switch input:checked~.toggle {
left: 4px;
}
.switch input~:checked~.toggle {
left: 100px;
}
.switch input:checked {
z-index: 0;
}
.toggle {
background: #4a4a4a;
border-radius: 50%;
height: 56px;
left: 0;
position: absolute;
top: 4px;
-webkit-transition: left .2s ease;
-moz-transition: left .2s ease;
-ms-transition: left .2s ease;
-o-transition: left .2s ease;
transition: left .2s ease;
width: 56px;
z-index: 1;
}
.c-window{
display: block;
position: absolute;
width: 235px;
height: 235px;
margin: 0 auto;
border-radius: 100%;
border: 8px solid #FFB399;
background: #5ddfe8;
box-shadow: 0px 0px 5px rgba(0,0,0,0.25) inset;
overflow: hidden;
transition: background 1s ease-in-out;
}
input[type="radio"]:checked ~ .c-window {
background: #111;
}
<div class="container">
<div class="c-window"></div>
<div class="switch white">
<input type="radio" name="switch" id="switch-off">
<input type="radio" name="switch" id="switch-on" checked>
<label for="switch-off">On</label>
<label for="switch-on">Off</label>
<span class="toggle"></span>
</div> <!-- end switch -->
</div> <!-- end container -->
I'd like that the .c-window changes the background colour when it switch
you had a few typos, as mentioned by #fcalderan in comments.
you need to have .c-window as sibling, change the HTML markup and add z-index:-1 to it.
and you need to specify which input is going to change the background color.
/* CSS Document */
/* ---------- GENERAL ---------- */
body {
background: #4a4a4a;
color: #151515;
font: 100%/1.5em"Lato", sans-serif;
margin: 0;
}
input {
font-family: inherit;
font-size: 100%;
line-height: normal;
margin: 0;
}
input[type="radio"] {
box-sizing: border-box;
padding: 0;
}
/* ---------- SWITCH ---------- */
.container {
height: 64px;
left: 50%;
margin: -32px 0 0 -80px;
position: absolute;
top: 50%;
width: 160px;
}
.switch {
background: #fff;
border-radius: 32px;
display: block;
height: 64px;
position: relative;
width: 160px;
}
.switch label {
color: #fff;
font-size: 48px;
font-weight: 300;
line-height: 64px;
text-transform: uppercase;
-webkit-transition: color .2s ease;
-moz-transition: color .2s ease;
-ms-transition: color .2s ease;
-o-transition: color .2s ease;
transition: color .2s ease;
width: 100px;
}
.switch label:first-of-type {
left: -75%;
position: absolute;
text-align: right;
}
.switch label:last-of-type {
position: absolute;
right: -75%;
text-align: left;
}
.switch input {
height: 64px;
left: 0;
opacity: 0;
position: absolute;
top: 0;
width: 160px;
z-index: 2;
}
.switch input:checked~label:first-of-type {
color: #fff;
}
.switch input:checked~label:last-of-type {
color: #808080;
}
.switch input:checked~label:first-of-type {
color: #808080;
}
.switch input:checked~label:last-of-type {
color: #fff;
}
.switch input:checked {
z-index: 0;
}
.switch input:checked~.toggle {
left: 4px;
}
.switch input~:checked~.toggle {
left: 100px;
}
.toggle {
background: #4a4a4a;
border-radius: 50%;
height: 56px;
left: 0;
position: absolute;
top: 4px;
-webkit-transition: left .2s ease;
-moz-transition: left .2s ease;
-ms-transition: left .2s ease;
-o-transition: left .2s ease;
transition: left .2s ease;
width: 56px;
z-index: 1;
}
.c-window {
display: block;
position: absolute;
width: 235px;
height: 235px;
margin: 0 auto;
border-radius: 100%;
border: 8px solid #FFB399;
background: #5ddfe8;
box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.25) inset;
overflow: hidden;
transition: background 1s ease-in-out;
z-index:-1
}
input:last-of-type[type="radio"]:checked ~ .c-window {
background: #111;
}
<div class="container">
<div class="switch white">
<input type="radio" name="switch" id="switch-off">
<input type="radio" name="switch" id="switch-on" checked>
<label for="switch-off">On</label>
<label for="switch-on">Off</label>
<span class="toggle"></span>
<div class="c-window"></div>
</div>
<!-- end switch -->
</div>
<!-- end container -->
Can't you do it in javascript/jQuery?
HTML:
<div class="container">
<div class="c-window"></div>
<div class="switch white">
<input type="radio" name="switch" value="0" id="switch-off" class="switch">
<input type="radio" name="switch" value="1" id="switch-on" class="switch" checked>
<label for="switch-off">On</label>
<label for="switch-on">Off</label>
<span class="toggle"></span>
</div> <!-- end switch -->
</div> <!-- end container -->
jQuery (to catch the change event):
$(document).ready(function(){
$('.switch').on('change', function(ev){
if ($(this).val() == 0){
//do some stuff you want when off
}else{
//do some stuff you want when on
}
});
});
If you want to use ~ selector your code should go like this
body, html {
margin: 0;
padding: 0;
}
.content {
display: flex;
height: 100vh;
align-items: center;
justify-content: center;
position: relative;
}
.c-window {
position: absolute;
transition: all 0.3s ease-in;
width: 235px;
height: 235px;
border-radius: 50%;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
background: #aaa;
border: 5px solid black;
z-index: 1;
}
input {
position: relative;
z-index: 2;
}
#switch-off:checked ~ .c-window {
background: blue;
}
#switch-on:checked ~ .c-window {
background: #aaa;
}
<div class="content">
<input type="radio" name="switch" id="switch-off">
<input type="radio" name="switch" id="switch-on" checked>
<div class="c-window"></div>
</div>