Multiple HTML/CSS only sliders on one page not changing independently - html

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>

Related

So I am trying to make a photo gallery with html and css but its not working

body {
margin: 0;
padding: 0;
background: #ffffff;
}
.slidershow {
width: 700px;
height: 400px;
overflow: hidden;
}
.middle {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.navigation {
position: absolute;
bottom: 20px;
left: 50%;
transform: translate(-50%);
display: flex;
}
/*this is where the button is supposed to be but like I'm not sure where it went wrong.*/
.bar {
width: 50px;
height: 10px;
border: 2px solid #fff;
margin: 6px;
cursor: pointer;
transition: 0.4s;
}
.bar:hover {
background: #fff;
}
input[name="r"] {
position: absolute;
visibility: hidden;
}
//I made the slides here to show that when clicking the bottom would reveal the next picture.
.slides {
width: 500%;
height: 100%;
display: flex;
}
//this part is where the slide would slowly transition to the next picture.
.slide {
width: 20%;
transition: 0.6s;
}
.slide img {
width: 100%;
height: 100%;
}
#r1:checked~.s1 {
margin-left: 0;
}
#r2:checked~.s1 {
margin-left: -20%;
}
#r3:checked~.s1 {
margin-left: -40%;
}
#r4:checked~.s1 {
margin-left: -60%;
}
#r5:checked~.s1 {
margin-left: -80%;
}
#r6:checked~.s1 {
margin-left: -100%;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Image Gallery</title>
</head>
<body>
Home
<div class="slidershow middle">
<div class="slides">
<input type="radio" name="r" id="r1" checked>
<input type="radio" name="r" id="r2">
<input type="radio" name="r" id="r3">
<input type="radio" name="r" id="r4">
<input type="radio" name="r" id="r5">
<input type="radio" name="r" id="r6">
<div class="slide s1">
<img src="https://popmenucloud.com/lptemfjr/973db751-7915-4c33-abcf-784ef635b66e.jpg" width="285" height="350">
</div>
<div class="slide">
<img src="https://images.squarespace-cdn.com/content/v1/5ebe52753562c1382763652b/1626229881191-V13LZ5XOFEGAOW3P998O/image-asset.jpeg" width="200" height="200">
</div>
<div class="slide">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcT5F6N4b4ylX07XIJ7kGiT88pBwBi3sqq-VPw&usqp=CAU" width="200" height="198">
</div>
<div class="slide">
<img src="https://popmenucloud.com/lptemfjr/cd3e12fe-2e4c-4f25-af21-d30dc2c771ed.jpeg" width="320" height="404">
</div>
<div class="slide">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTqAnzTuMrG_oISwd5iqGOWQUndvg799wYY3A&usqp=CAU">
</div>
<div class="slide">
<img src="https://eatclub.com.au/wp-content/uploads/2019/06/Gotcha-Tea.jpg" width="377" height="460">
</div>
</div>
<div class="navigation">
<label for="r1" class="bar"></label>
<label for="r2" class="bar"></label>
<label for="r3" class="bar"></label>
<label for="r4" class="bar"></label>
<label for="r5" class="bar"></label>
<label for="r6" class="bar"></label> This part is where the pictures are but I don't think this where the error is.
</div>
</div>
</body>
</html>
So I am trying to make a photo gallery with buttons so that the user can see all 6 photos, but it doesn't even make the photos in a gallery. And it also just places the photos in a line.
I'm really not sure where it went wrong, I am looking at the code and I am really confused about what I did wrong.
I don't understand exactly what you want but I think I see you want to make a gallery system without using JS.
I hope the following is useful for you.
HTML
<div class="slider">
<div id="image1" class="slider-item">
<img src="https://popmenucloud.com/lptemfjr/973db751-7915-4c33-abcf-784ef635b66e.jpg" width="285" height="350">
</div>
<div id="image2" class="slider-item">
<img src="https://images.squarespace-cdn.com/content/v1/5ebe52753562c1382763652b/1626229881191-V13LZ5XOFEGAOW3P998O/image-asset.jpeg" width="200" height="200">
</div>
</div>
<div class="navigation">
Image 1
Image 2
</div>
CSS
.slider-item {
display: none;
}
:target {
display: block;
}
Example here: https://codepen.io/yasgo/pen/vYpvqbj
I have done the same using javascript
Example: https://jsfiddle.net/Karthik471/9dnhcp0e/13/
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Image Gallery</title>
</head>
<body>
Home
<div class="slidershow middle">
<div class="slides">
<input type="radio" name="r" id="r1" >
<input type="radio" name="r" id="r2" >
<input type="radio" name="r" id="r3" >
<input type="radio" name="r" id="r4" >
<input type="radio" name="r" id="r5" >
<input type="radio" name="r" id="r6" >
<div class="slide r1">
<img src="https://popmenucloud.com/lptemfjr/973db751-7915-4c33-abcf-784ef635b66e.jpg" width="285" height="350">
</div>
<div class="slide r2">
<img src="https://images.squarespace-cdn.com/content/v1/5ebe52753562c1382763652b/1626229881191-V13LZ5XOFEGAOW3P998O/image-asset.jpeg" width="200" height="200">
</div>
<div class="slide r3">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcT5F6N4b4ylX07XIJ7kGiT88pBwBi3sqq-VPw&usqp=CAU" width="200" height="198">
</div>
<div class="slide r4">
<img src="https://popmenucloud.com/lptemfjr/cd3e12fe-2e4c-4f25-af21-d30dc2c771ed.jpeg" width="320" height="404">
</div>
<div class="slide r5">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTqAnzTuMrG_oISwd5iqGOWQUndvg799wYY3A&usqp=CAU">
</div>
<div class="slide r6">
<img src="https://eatclub.com.au/wp-content/uploads/2019/06/Gotcha-Tea.jpg" width="377" height="460">
</div>
</div>
<div class="navigation">
<label for="r1" class="bar"></label>
<label for="r2" class="bar"></label>
<label for="r3" class="bar"></label>
<label for="r4" class="bar"></label>
<label for="r5" class="bar"></label>
<label for="r6" class="bar"></label>
This part is where the pictures are but I don't think this where the error is.
</div>
</div>
</body>
</html>
CSS
.slide{
display:none;
}
JS
let selectElement = document.querySelector('.slides');
let selectElement1 = document.querySelectorAll('.slide');
selectElement.addEventListener('change', (event) => {
/* alert( event.target.id ); */
let selectElement1 = document.querySelectorAll('.slide');
for (element of selectElement1) {
element.style.display = 'none';
}
let value = event.target.id;
let class_selected = document.getElementsByClassName(value);
if (class_selected[0].style.display == "none"){
class_selected[0].style.display = "block"
}
else{
class_selected[0].style.display = "none";
}
});
Hope that the following code is useful for you.
I have used the event listener and based on the radio click event to display the respective images
You need to add your css file
<head>
.
.
<link rel=”stylesheet” type=”text/css” href=”yourfile.css” />
.
.
</head>

Custom radio buttons to show/hide content

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).

Place Radio Buttons over image

I am trying to place some radio buttons over an image at an exact location. I have placed both in a Div but I am not sure what to do next. Here is where I want the radio buttons to be placed (red circles):
Here is my code so far:
.center {
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
}
body {
background-color: #979797
}
<div class="general">
<img src="https://via.placeholder.com/300" class="center">
<form action="">
<input type="radio" name="answer 1" value="apple">
<input type="radio" name="answer 2" value="chicken">
<input type="radio" name="answer 3" value="carrot">
</form>
</div>
Thank you so much in advance!
I would put the radio buttons in one div each and then give the div a background. Like this:
<html>
<head>
<style>
.general{}
.center {
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
}
.radio-size {
height: 100px;
width: 100px;
}
.bg-apple {
background-image:url('https://images.unsplash.com/photo-1513677785800-9df79ae4b10b?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1350&q=80');
background-size: cover;
}
.bg-chicken {
background-image:url('https://images.unsplash.com/photo-1426869981800-95ebf51ce900?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1350&q=80');
background-size: cover;
}
.bg-carrot {
background-image:url('https://images.unsplash.com/photo-1445282768818-728615cc910a?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1350&q=80');
background-size: cover;
}
</style>
<meta charset="UTF-8">
<title>Untitled Document</title>
</head>
<body bgcolor="#979797">
<div class="general">
<img src="https://images.unsplash.com/photo-1518796745738-41048802f99a?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1350&q=80" class="center" style="width:20%;" >
<form action="" style="background-img:url("")">
<div class="radio-size bg-apple">
<input type="radio" name="answer 1" value="apple">
</div>
<div class="radio-size bg-chicken">
<input type="radio" name="answer 1" value="chicken"> <br>
</div>
<div class="radio-size bg-carrot">
<input type="radio" name="answer 1" value="carrot">
</div>
</form>
</div>
</body>
</html>
note: The radio-buttons are all supposed to have the same "name" atribute, so that you can only choose one of them. If you want to be able to select multiple options, you should use checkbox instead.
Even though you say you want them over your image, in the picture you shared the radio buttons appear to be on the right side of the image. So i am a bit confused about what you actually want.
But i made a simple example below. You can position them how you like or comment below if you want my help.
P.S. as i said in my comment : The <body> bgcolor attribute is not supported in HTML5. Use CSS instead.
.center {
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
}
body {
background-color: #979797
}
form {
position:absolute;
right: 25%;
top: 50%;
transform:translateY(-50%) translateX(100%);
display: flex;
flex-direction: column;
}
.general {
position: relative;
}
<div class="general">
<img src="http://via.placeholder.com/640x360" class="center">
<form action="">
<input type="radio" name="answer 1" value="apple">
<input type="radio" name="answer 2" value="chicken">
<input type="radio" name="answer 3" value="carrot">
</form>
</div>
You can use the following solution using flexbox:
body {
background:#979797;
}
.question {
display:flex;
flex-direction:row;
flex-wrap:nowrap;
}
.answers {
display:flex;
flex-direction:column;
}
label.answer {
position:relative;
height:100px;
}
label.answer input[type="radio"] {
top:0;
left:0;
position:absolute;
}
<form action="">
<h2>Question 1:</h2>
<div class="question">
<img src="https://picsum.photos/300">
<div class="answers">
<label class="answer">
<img src="https://picsum.photos/100">
<input type="radio" name="answer1" value="apple">
</label>
<label class="answer">
<img src="https://picsum.photos/100">
<input type="radio" name="answer1" value="chicken">
</label>
<label class="answer">
<img src="https://picsum.photos/100">
<input type="radio" name="answer1" value="carrot">
</label>
</div>
</div>
<h2>Question 2:</h2>
<div class="question">
<img src="https://picsum.photos/300">
<div class="answers">
<label class="answer">
<img src="https://picsum.photos/100">
<input type="radio" name="answer2" value="apple">
</label>
<label class="answer">
<img src="https://picsum.photos/100">
<input type="radio" name="answer2" value="chicken">
</label>
<label class="answer">
<img src="https://picsum.photos/100">
<input type="radio" name="answer2" value="carrot">
</label>
</div>
</div>
</form>
I think you should try the following type of code for the above query. I have changed you HTML structure and have changed your current CSS completely:
.general{
width: fit-content;
}
.img{
display: flex;
align-items: end;
}
img{
border: 1px solid black;
}
body {
background-color: #979797
}
.options{
display: flex;
flex-direction: column;
}
.radio{
position: relative;
height: 50px;
}
input[type="radio"]{
position: absolute;
top: calc(50% - 4px);
right: 0;
margin: 0;
}
<div class="general">
<form action="">
<div class="img">
<img src="https://via.placeholder.com/150" class="center">
<div class="options" class="center">
<div class="radio">
<img src="https://via.placeholder.com/50">
<input type="radio" name="answer1" value="apple">
</div>
<div class="radio">
<img src="https://via.placeholder.com/50">
<input type="radio" name="answer1" value="chicken">
</div>
<div class="radio">
<img src="https://via.placeholder.com/50">
<input type="radio" name="answer1" value="carrot">
</div>
</div>
</div>
</form>
</div>
Remember that if the questions only have a single answer then, the name of the radio box should be same and the value should be different. Otherwise, all the radio buttons will get selected simultaneously and cannot be unselected.
I hope this code is helpful.
Thanks.

How to align radio button horizontally

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>

Checkbox not aligning despite CSS code applied

I am trying to get my checkboxes and labels aligned (into two a column), but it isn't working. Any idea what I can do to get it fixed?
Jsfiddle here: http://jsfiddle.net/wfju61oq/1/
.option label {
display: block;
padding-left: 15px;
text-indent: -15px;
}
.option input {
width: 13px;
height: 13px;
padding: 0;
margin:0;
vertical-align: bottom;
position: relative;
top: -1px;
*overflow: hidden;
}
Try this:
.option label {
display: block;
width: 220px;
}
.option input {
float:right;
}
Working fiddle here.
label {
display: block;
width: 300px;
text-align: right;
margin-right: 10px;
}
Here is a working JSFiddle:
http://jsfiddle.net/wfju61oq/8/
Warning: you have a &character in one of your id: this is incorrect.
demo - http://jsfiddle.net/victor_007/wfju61oq/10/
remove margin:0 for label and position:relative; top:-1px;
added border for better view of vertical alignment
.option label {
display: block;
padding-left: 15px;
text-indent: -15px;
width: 150px;
border: 1px solid red;
}
.option input {
width: 13px;
height: 13px;
vertical-align: bottom;
*overflow: hidden;
float: right;
}
<div class="option">
<fieldset>
<legend>Which Service Do You Require?</legend>
<label for="Hostess">Hostess
<input type="checkbox" id="Hostess" value="Hostess" />
</label>
<label for="usher">Usher
<input type="checkbox" id="usher" value="usher" />
</label>
<label for="welcomeguests">Welcome Guests
<input type="checkbox" id="welcomeguests" value="welcomeguests" />
</label>
<label for="guestlists">Guest Lists
<input type="checkbox" id="guestlists" value="guestlists" />
</label>
<label for="seatguests">Seat Guests
<input type="checkbox" id="seatguests" value="seatguests" />
</label>
<label for="servebuffmeal">Serve Buffet Meal
<input type="checkbox" id="servebuffmeal" value="servebuffmeal" />
</label>
<label for="servesitmeal">Serve Sit-Down Meal
<input type="checkbox" id="servesitmeal" value="servesitmeal" />
</label>
<label for="clearplates">Clear Plates
<input type="checkbox" id="clearplates" value="clearplates" />
</label>
<label for="cleartables">Clear Tables
<input type="checkbox" id="cleartables" value="cleartables" />
</label>
<label for="returnhplates">Return Hired Plates
<input type="checkbox" id="returnhplates" value="returnhplates" />
</label>
<label for="refilljuggs">Refill Jugs
<input type="checkbox" id="refilljugs" value="refilljuggs" />
</label>
<label for="">Serve V.I.P Guests
<input type="checkbox" id="servevipguests" value="servevipguests" />
</label>
<label for="">Cross-Check Invite List
<input type="checkbox" id="crosscheckivlist" value="crosscheckivlist" />
</label>
<label for="">Meet & Greet Guests
<input type="checkbox" id="Meet&GreetGuests" value="Meet&GreetGuests" />
</label>
<div style="clear: both"></div>
<label>Other
<input id="other" name="other" type="text" placeholder="Other" />
</label>
</fieldset>
</div>