I am trying to build a interactive email content block that would show or hide content based on the selection. It worked before I tried to customize the label. It stopped working after I wrapped the input and label inside a div. I think it could be throwing my selectors off but I am not sure how remedy the problem.
.custom-radios input[type="radio"] + label span img {
opacity: 0;
transition: all 0.3s ease;
}
.custom-radios input[type="radio"]#red + label span {
background-color: red;
}
.custom-radios input[type="radio"]#blue + label span {
background-color: blue;
}
.custom-radios input[type="radio"]#green + label span {
background-color: green;
}
.custom-radios input[type="radio"]#orange + label span {
background-color: orange;
}
.custom-radios input[type="radio"]:checked + label span img {
opacity: 1;
}
#red{
display: none
}
#blue{
display: none
}
#green{
display: none
}
#orange{
display: none
}
input[type="red"]:checked ~ #red {
display: block
}
input[value="blue"]:checked ~ #blue {
display: block;
}
input[value="green"]:checked ~ #green {
display: block;
}
input[value="orange"]:checked ~ #orange {
display: block;
}
<div class="custom-radios">
<div>
<input type="radio" id="red" name="color" value="red">
<label for="red">
<span>
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/242518/check-icn.svg" alt="Checked Icon" />
</span>
</label>
</div>
<div>
<input type="radio" id="blue" name="color" value="blue">
<label for="blue">
<span>
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/242518/check-icn.svg" alt="Checked Icon" />
</span>
</label>
</div>
<div>
<input type="radio" id="green" name="color" value="green">
<label for="green">
<span>
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/242518/check-icn.svg" alt="Checked Icon" />
</span>
</label>
</div>
<div>
<input type="radio" id="orange" name="color" value="orange">
<label for="orange">
<span>
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/242518/check-icn.svg" alt="Checked Icon" />
</span>
</label>
</div>
<div class="spacer" style="line-height:26px;height:26px;mso-line-height-rule:exactly;"> </div>
<p style="margin:0;" id="red">
<img src="https://via.placeholder.com/580x200/FF0000/FFFFFF" width="580" alt="" style="width:100%;height:auto;max-width:580px;" />
</p>
<p style="margin:0;" id="blue">
<img src="https://via.placeholder.com/580x200/0000FF/FFFFFF" width="580" alt="" style="width:100%;height:auto;max-width:580px;" />
</p>
<p style="margin:0;" id="green">
<img src="https://via.placeholder.com/580x200/00FF00/FFFFFF" width="580" alt="" style="width:100%;height:auto;max-width:580px;" />
</p>
<p style="margin:0;" id="orange">
<img src="https://via.placeholder.com/580x200/FFA500/FFFFFF" width="580" alt="" style="width:100%;height:auto;max-width:580px;" />
</p>
<div class="spacer" style="line-height:26px;height:26px;mso-line-height-rule:exactly;"> </div>
</div>
I think selectors may be a weak point for you, again, I encourage you to check the CSS Selectors Reference from w3school.
Anyways, I made a simplified version, as similar as I could to you current structure, so you can see it working.
.hidden_input {
display: none;
}
#red_input+label>span {
background-color: red;
}
#blue_input+label>span {
background-color: blue;
}
label>span>img {
opacity: 0;
transition: all 0.3s ease;
}
.hidden_input:checked+label>span>img {
opacity: 1;
}
#red_content,
#blue_content {
display: none;
}
#red_input:checked~#red_content,
#blue_input:checked~#blue_content {
display: block;
}
<div class="custom-radios">
<input type="radio" id="red_input" class="hidden_input" name="color" value="red">
<label for="red_input">
<span>
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/242518/check-icn.svg"/>
</span>
</label>
<input type="radio" id="blue_input" class="hidden_input" name="color" value="blue">
<label for="blue_input">
<span>
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/242518/check-icn.svg"/>
</span>
</label>
<div class="spacer" style="line-height:26px;height:26px;mso-line-height-rule:exactly;"> </div>
<p style="margin:0;" id="red_content">
<img src="https://via.placeholder.com/580x200/FF0000/FFFFFF" width="580" style="width:100%;height:auto;max-width:580px;" />
</p>
<p style="margin:0;" id="blue_content">
<img src="https://via.placeholder.com/580x200/0000FF/FFFFFF" width="580" style="width:100%;height:auto;max-width:580px;" />
</p>
</div>
You can also play and place elements wherever you want in your HTML code, and then set their position with grid (it's just another option).
Related
As I said Why when radio button is checked the images are not sliding out of out of container? because I want to create image slider with pure css. I have used also with position:absolute; with left:-517px; along with targeting direct id's it is also not working. So is there any problem with my code?
.img-container{
width:1550px;
border:4px solid black;
padding:6px;
}
.crousel{
width:516px;
border:6px solid magenta;
height:350px;
display:flex;
}
img{
padding:6px;
}
.toggle-button:checked ~ .box {
translate(X):transform(-517px);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=">
<title></title>
</head>
<body>
<div class="img-container">
<div class="crousel">
<label for="toggle1"></label>
<img src="https://cdn.pixabay.com/photo/2020/10/06/11/50/dog-5632005__340.jpg" alt="" class="box">
<label for="toggle2"></label>
<img src="https://cdn.pixabay.com/photo/2020/09/12/09/26/gorilla-5565295__340.jpg" alt="" class="box">
<label for="toggle3"></label>
<img src="https://cdn.pixabay.com/photo/2020/09/14/17/19/beach-5571545__340.jpg" alt="" class="box">
</div>
</div>
<div class="buttons">
<input type="radio" name="button" id="toggle1" class="toggle-button">
<input type="radio" name="button" id="toggle2" class="toggle-button">
<input type="radio" name="button" id="toggle3" class="toggle-button">
</div>
</body>
</html>
You can do this like that way...
.slider {
width: 500px;
display: block;
position: relative;
overflow: hidden;
}
.rollSlider {
display: flex;
width: 1500px;
}
img {
max-width: 500px;
}
input#slide1:checked ~ .slider .rollSlider {
transform: translate(0px);
transition: all 300ms ease;
}
input#slide2:checked ~ .slider .rollSlider {
transform: translate(-500px);
transition: all 300ms ease;
}
input#slide3:checked ~ .slider .rollSlider {
transform: translate(-1000px);
transition: all 300ms ease;
}
<input id="slide1" type="radio" name="slide" checked>
<input id="slide2" name="slide" type="radio">
<input id="slide3" name="slide" type="radio">
<div class="slider">
<div class="rollSlider">
<label for="slide1">
<img src="https://images.pexels.com/photos/4040806/pexels-photo-4040806.jpeg">
</label>
<label for="slide2">
<img src="https://images.pexels.com/photos/4686833/pexels-photo-4686833.jpeg">
</label>
<label for="slide3">
<img src="https://images.pexels.com/photos/4722021/pexels-photo-4722021.jpeg">
</label>
</div>
</div>
Explanation
I want to switch between images selecting radios, but I'd like it to be HTML/CSS only. As you can see in the code below, it does work, but in my main code the radio button and the image are within their own divs, which then this code won't work because ~ only acts if .radio-image is directly preceded by input.radio3:checked; also in my main code, the images comes before the radio button.
I also wrote an example like it'd in my main code.
Codes
working code
input.radio1:checked~.image1 {
display: block;
}
input.radio1:checked~.image2 {
display: none;
}
input.radio1:checked~.image3 {
display: none;
}
input.radio2:checked~.image2 {
display: block;
}
input.radio2:checked~.image1 {
display: none;
}
input.radio2:checked~.image3 {
display: none;
}
input.radio3:checked~.image3 {
display: block;
}
input.radio3:checked~.image1 {
display: none;
}
input.radio3:checked~.image2 {
display: none;
}
<input type="radio" name="test" class="radio1" checked/>
<input type="radio" name="test" class="radio2" />
<input type="radio" name="test" class="radio3" />
<div class="image1">
<img src="http://placehold.it/50x50">
</div>
<div class="image2">
<img src="http://placehold.it/75x75">
</div>
<div class="image3">
<img src="http://placehold.it/100x100">
</div>
main code example
input.radio1:checked~.image1 {
display: block;
}
input.radio1:checked~.image2 {
display: none;
}
input.radio1:checked~.image3 {
display: none;
}
input.radio2:checked~.image2 {
display: block;
}
input.radio2:checked~.image1 {
display: none;
}
input.radio2:checked~.image3 {
display: none;
}
input.radio3:checked~.image3 {
display: block;
}
input.radio3:checked~.image1 {
display: none;
}
input.radio3:checked~.image2 {
display: none;
}
<section class="testSection">
<div class="firstDiv">
<div class="image1">
<img src="http://placehold.it/50x50">
</div>
<div class="image2">
<img src="http://placehold.it/75x75">
</div>
<div class="image3">
<img src="http://placehold.it/100x100">
</div>
</div>
<div class="secondDiv">
<form class="testForm">
<div class="thirdDiv">
<div class="inputDiv">
<input type="radio" name="test" class="radio1" checked />
</div>
<div class="inputDiv">
<input type="radio" name="test" class="radio2" />
</div>
<div class="inputDiv">
<input type="radio" name="test" class="radio3" />
</div>
</div>
</form>
</div>
</section>
Thanks in advance,
Luiz.
I have a row of options which are checkbox and an image.. I'd like it when the user selects the image or the checkbox that it highlights the image with a border or whatever.. can I achieve this with pure css?
here's a snipet
<style>
.highlight {
opacity: 0.7;
}
.highlight:hover {
opacity: 1;
}
</style>
<li class="wpProQuiz_questionListItem" data-pos="0">
<span style="display:none;">1. </span>
<label>
<input class="wpProQuiz_questionInput" type="checkbox" name="question_1_1" value="1" style="
/* display: none !important; */"> <img src="http://www.iq-tests.co/wp-content/uploads/2018/09/1a.png" alt="" width="10%" height="10%" class="alignnone size-medium wp-image-594"></label>
</li>
<li class="wpProQuiz_questionListItem" data-pos="0">
<span style="display:none;">1. </span>
<label>
<input class="wpProQuiz_questionInput" type="checkbox" name="question_1_2" value="1" style="
/* display: none !important; */"> <img src="http://www.iq-tests.co/wp-content/uploads/2018/09/1b.png" alt="" width="10%" height="10%" class="alignnone size-medium wp-image-594"></label>
</li>
You mean like this? you can use the css adjacent sibling selector
.highlight {
opacity: 0.7;
}
.highlight:hover {
opacity: 1;
}
.wpProQuiz_questionInput:checked + img {
border: 1px solid #f00;
}
<li class="wpProQuiz_questionListItem" data-pos="0">
<span style="display:none;">1. </span>
<label for="1">
<input id="1" class="wpProQuiz_questionInput" type="checkbox" name="question_1_1" value="1"> <img src="http://www.iq-tests.co/wp-content/uploads/2018/09/1a.png" alt="pic1" width="10%" height="10%" class="alignnone size-medium wp-image-594"></label>
</li>
<li class="wpProQuiz_questionListItem" data-pos="0">
<span style="display:none;">1. </span>
<label for="2">
<input id="2" class="wpProQuiz_questionInput" type="checkbox" name="question_1_2" value="1"> <img src="http://www.iq-tests.co/wp-content/uploads/2018/09/1b.png" alt="pic2" width="10%" height="10%" class="alignnone size-medium wp-image-594"></label>
</li>
If you want give effect on click then you have to use:
.highlight:active,.highlight:focus {
border:1px solid red;
}
I am writing a blog post for a friend of mine, on the ghost platform. This blog post is going to be a very long post about multiple different objects, each requiring their own image slider. I'd like to re-use the same CSS for all 20 or so sliders on the page, only changing the html.
I followed a slider tutorial online, that created a html/css only slider, as Ghost doesnt support scripting in their individual blog posts.
Unfortunately, when i click on one thumbnail, the image in all the other sliders disapears, and is only shown in that particular slider, making scrolling down the page a very boring experience.
Anyone able to spot the error? Here is an excerpt using only two sliders. take a look at the result further down:
<style>
* {margin: 0; padding: 0;}
body {background: #ccc;}
.slider{
width: 640px;
position: relative;
padding-top: 320px;
margin: 100px auto;
box-shadow: 0 10px 20px -5px rgba(0, 0, 0, 0.75);
}
.slider>img{
position: absolute;
left: 0; top: 0;
transition: all 0.2s;
}
.slider input[name='slide_switch'] {
display: none;
}
.slider label {
margin: 18px 0 0 18px;
border: 3px solid #999;
float: left;
cursor: pointer;
transition: all 0.5s;
opacity: 0.6;
}
.slider label img{
display: block;
}
.slider input[name='slide_switch']:checked+label {
border-color: #666;
opacity: 1;
}
.slider input[name='slide_switch'] ~ img {
opacity: 0;
transform: scale(1.1);
}
.slider input[name='slide_switch']:checked+label+img {
opacity: 1;
transform: scale(1);
}
</style>
**The xx: **
Insert image
About
Gallery of the xx
<div class="slider">
<input type="radio" name="slide_switch" id="id1"/>
<label for="id1">
<img src="http://thecodeplayer.com/uploads/media/3yiC6Yq.jpg" width="100"/>
</label>
<img src="http://thecodeplayer.com/uploads/media/3yiC6Yq.jpg"/>
<input type="radio" name="slide_switch" id="id2"/>
<label for="id2">
<img src="http://thecodeplayer.com/uploads/media/40Ly3VB.jpg" width="100"/>
</label>
<img src="http://thecodeplayer.com/uploads/media/40Ly3VB.jpg"/>
<input type="radio" name="slide_switch" id="id3"/>
<label for="id3">
<img src="http://thecodeplayer.com/uploads/media/00kih8g.jpg" width="100"/>
</label>
<img src="http://thecodeplayer.com/uploads/media/00kih8g.jpg"/>
<input type="radio" name="slide_switch" id="id4"/>
<label for="id4">
<img src="http://thecodeplayer.com/uploads/media/2rT2vdx.jpg" width="100"/>
</label>
<img src="http://thecodeplayer.com/uploads/media/2rT2vdx.jpg"/>
<input type="radio" name="slide_switch" id="id5"/>
<label for="id5">
<img src="http://thecodeplayer.com/uploads/media/8k3N3EL.jpg" width="100"/>
</label>
<img src="http://thecodeplayer.com/uploads/media/8k3N3EL.jpg"/>
</div>
**The yy**
Insert image
About
Gallery of the yy
<div class="slider">
<input type="radio" name="slide_switch" id="id6"/>
<label for="id6">
<img src="http://thecodeplayer.com/uploads/media/3yiC6Yq.jpg" width="100"/>
</label>
<img src="http://thecodeplayer.com/uploads/media/3yiC6Yq.jpg"/>
<input type="radio" name="slide_switch" id="id7"/>
<label for="id7">
<img src="http://thecodeplayer.com/uploads/media/40Ly3VB.jpg" width="100"/>
</label>
<img src="http://thecodeplayer.com/uploads/media/40Ly3VB.jpg"/>
<input type="radio" name="slide_switch" id="id8"/>
<label for="id8">
<img src="http://thecodeplayer.com/uploads/media/00kih8g.jpg" width="100"/>
</label>
<img src="http://thecodeplayer.com/uploads/media/00kih8g.jpg"/>
<input type="radio" name="slide_switch" id="id9"/>
<label for="id9">
<img src="http://thecodeplayer.com/uploads/media/2rT2vdx.jpg" width="100"/>
</label>
<img src="http://thecodeplayer.com/uploads/media/2rT2vdx.jpg"/>
<input type="radio" name="slide_switch" id="id10"/>
<label for="id10">
<img src="http://thecodeplayer.com/uploads/media/8k3N3EL.jpg" width="100"/>
</label>
<img src="http://thecodeplayer.com/uploads/media/8k3N3EL.jpg"/>
</div>
All of your radio buttons have the same name, so they're all considered a part of the same group. Only one radio button can be active in any one group. Each group should have a different name so they are grouped separately. Doing so will affect your current CSS but changing your attribute selector from name= to name^= or name*= will allow you to give each radio button set a different name. In the example below, we appended _1 to the second set.
* {
margin: 0;
padding: 0;
}
body {
background: #ccc;
}
.slider {
width: 640px;
position: relative;
padding-top: 320px;
margin: 100px auto;
box-shadow: 0 10px 20px -5px rgba(0, 0, 0, 0.75);
}
.slider>img {
position: absolute;
left: 0;
top: 0;
transition: all 0.2s;
}
.slider input[name^='slide_switch'] {
display: none;
}
.slider label {
margin: 18px 0 0 18px;
border: 3px solid #999;
float: left;
cursor: pointer;
transition: all 0.5s;
opacity: 0.6;
}
.slider label img {
display: block;
}
.slider input[name^='slide_switch']:checked+label {
border-color: #666;
opacity: 1;
}
.slider input[name^='slide_switch']~img {
opacity: 0;
transform: scale(1.1);
}
.slider input[name^='slide_switch']:checked+label+img {
opacity: 1;
transform: scale(1);
}
<div class="slider">
<input type="radio" name="slide_switch_1" id="id1" checked>
<label for="id1">
<img src="http://thecodeplayer.com/uploads/media/3yiC6Yq.jpg" width="100">
</label>
<img src="http://thecodeplayer.com/uploads/media/3yiC6Yq.jpg">
<input type="radio" name="slide_switch_1" id="id2">
<label for="id2">
<img src="http://thecodeplayer.com/uploads/media/40Ly3VB.jpg" width="100">
</label>
<img src="http://thecodeplayer.com/uploads/media/40Ly3VB.jpg">
<input type="radio" name="slide_switch_1" id="id3">
<label for="id3">
<img src="http://thecodeplayer.com/uploads/media/00kih8g.jpg" width="100">
</label>
<img src="http://thecodeplayer.com/uploads/media/00kih8g.jpg">
<input type="radio" name="slide_switch_1" id="id4">
<label for="id4">
<img src="http://thecodeplayer.com/uploads/media/2rT2vdx.jpg" width="100">
</label>
<img src="http://thecodeplayer.com/uploads/media/2rT2vdx.jpg">
<input type="radio" name="slide_switch_1" id="id5">
<label for="id5">
<img src="http://thecodeplayer.com/uploads/media/8k3N3EL.jpg" width="100">
</label>
<img src="http://thecodeplayer.com/uploads/media/8k3N3EL.jpg">
</div>
<div class="slider">
<input type="radio" name="slide_switch" id="id6" checked>
<label for="id6">
<img src="http://thecodeplayer.com/uploads/media/3yiC6Yq.jpg" width="100">
</label>
<img src="http://thecodeplayer.com/uploads/media/3yiC6Yq.jpg">
<input type="radio" name="slide_switch" id="id7">
<label for="id7">
<img src="http://thecodeplayer.com/uploads/media/40Ly3VB.jpg" width="100">
</label>
<img src="http://thecodeplayer.com/uploads/media/40Ly3VB.jpg">
<input type="radio" name="slide_switch" id="id8">
<label for="id8">
<img src="http://thecodeplayer.com/uploads/media/00kih8g.jpg" width="100">
</label>
<img src="http://thecodeplayer.com/uploads/media/00kih8g.jpg">
<input type="radio" name="slide_switch" id="id9">
<label for="id9">
<img src="http://thecodeplayer.com/uploads/media/2rT2vdx.jpg" width="100">
</label>
<img src="http://thecodeplayer.com/uploads/media/2rT2vdx.jpg">
<input type="radio" name="slide_switch" id="id10">
<label for="id10">
<img src="http://thecodeplayer.com/uploads/media/8k3N3EL.jpg" width="100">
</label>
<img src="http://thecodeplayer.com/uploads/media/8k3N3EL.jpg">
</div>
I have radio button input with label, however I cannot align them horizontally, it just appeared one by one vertically, how can I make it align one by one horizontally.
<div class="cc-selector-2" align="right">
{{range $index,$url := .Avatars}}
<label for="pic1">
<input type="radio" name="avatar" id={{$url}} value={{$url}} />
<img src={{$url}} alt="" height="40" width="40"/>
</label>
{{end}}
</div>
<style>
.cc-selector-2 input{
position:absolute;
z-index:999;
}
label {
display: block;
text-align: center;
margin-bottom:0px;
font-size: .85em;
background-color:buttonface;
}
</style>
Just play with display: inline-block ;)
cc-selector-2{
text-align: center;
}
label {
display: inline-block;
margin:auto;
font-size: .85em;
background-color:buttonface;
}
input {
margin: 0;
}
<div class="cc-selector-2" align="right">
<label for="pic1">
<input type="radio" name="avatar" id={{$url}} value={{$url}} />
<img src={{$url}} alt="" height="40" width="40"/>
</label>
<label for="pic1">
<input type="radio" name="avatar" id={{$url}} value={{$url}} />
<img src={{$url}} alt="" height="40" width="40"/>
</label>
</div>