CSS3, multiple sliders will only display 1 main image at a time - html

Let me start off by stating I'm an absolute noob at webdesign and I mostly just use it for my game art portfolio. I'm somewhat familiar with HTML and CSS3 but that's where my coding skill pretty much end abrubtly.
I wanted a nice simple slider with thumbnails for my portfolio, and I found this one online and it seems to work for me for the most part.
I want to be able to duplicate this slider on my web page so I can dedicate an entire slider for each project I have and fill it with images.
However this slider doesn't allow me to do that. When I duplicate it, it only displays 1 main image corresponding to the clicked thumbnail at a time.
Here's the HTML:
<div id="project2">
<!-- Project slider -->
<div class="p-slider">
<input type="radio" name="slide_switch" id="id1"/>
<label for="id1">
<img src="images/content/3D/turtleneck_staf_2.jpg"/>
</label>
<img src="images/content/3D/turtleneck_staf_2.jpg"/>
<!--Lets show the second image by default on page load-->
<input type="radio" name="slide_switch" id="id2" checked="checked"/>
<label for="id2">
<img src="images/content/3D/turtleneck_staf_1.jpg"/>
</label>
<img src="images/content/3D/turtleneck_staf_1.jpg"/>
<input type="radio" name="slide_switch" id="id3"/>
<label for="id3">
<img src="images/content/3D/turtleneck_staf_3.jpg"/>
</label>
<img src="images/content/3D/turtleneck_staf_3.jpg"/>
<input type="radio" name="slide_switch" id="id4"/>
<label for="id4">
<img src="images/content/3D/turtleneck_staf_4.jpg"/>
</label>
<img src="images/content/3D/turtleneck_staf_4.jpg"/>
<input type="radio" name="slide_switch" id="id5"/>
<label for="id5">
<img src="images/content/3D/turtleneck_staf_5.jpg"/>
</label>
<img src="images/content/3D/turtleneck_staf_5.jpg"/>
</div>
</div>
<div id="project3">
<!-- Project slider -->
<div class="p-slider">
<input type="radio" name="slide_switch" id="id6"/>
<label for="id6">
<img src="images/content/3D/keep_it_low_poly_2.jpg"/>
</label>
<img src="images/content/3D/keep_it_low_poly_2.jpg"/>
<!--Lets show the second image by default on page load-->
<input type="radio" name="slide_switch" id="id7" checked="checked"/>
<label for="id7">
<img src="images/content/3D/keep_it_low_poly_1.jpg"/>
</label>
<img src="images/content/3D/keep_it_low_poly_1.jpg"/>
<input type="radio" name="slide_switch" id="id8"/>
<label for="id8">
<img src="images/content/3D/keep_it_low_poly_3.jpg"/>
</label>
<img src="images/content/3D/keep_it_low_poly_3.jpg"/>
<input type="radio" name="slide_switch" id="id9"/>
<label for="id9">
<img src="images/content/3D/keep_it_low_poly_4.jpg"/>
</label>
<img src="images/content/3D/keep_it_low_poly_4.jpg"/>
<input type="radio" name="slide_switch" id="id10"/>
<label for="id10">
<img src="images/content/3D/keep_it_low_poly_5.jpg"/>
</label>
<img src="images/content/3D/keep_it_low_poly_5.jpg"/>
</div>
</div>
Each slider is embedded in its own "project" div because I wanted to have each project to have a slightly different background color.
Then I ofcourse also have a CSS sheet that both sliders are linked to:
.p-slider{
width: 83%;
position: relative;
padding-top: 41.8%;
margin: 20px auto;
margin-bottom: 150px;
box-shadow: 0 10px 20px -5px rgba(0, 0, 0, 0.75);
}
.content .p-slider>img{
position: absolute;
left: 0; top: 0;
transition: all 0.5s;
width:100%;
}
.p-slider input[name='slide_switch'] {
display: none;
}
.p-slider label {
margin: 18px 0 0 18px;
border: 3px solid #999;
float: left;
cursor: pointer;
transition: all 0.5s;
opacity: 0.6;
}
.p-slider label img{
display: block;
width: 200px;
}
.p-slider input[name='slide_switch']:checked+label {
border-color: #666;
opacity: 1;
}
.p-slider input[name='slide_switch'] ~ img {
opacity: 0;
transform: scale(1.1);
}
.p-slider input[name='slide_switch']:checked+label+img {
opacity: 1;
transform: scale(1);
}
#media screen and (max-width: 800px) {
.p-slider label img{
/*display: block;*/
width: 100px;
}
}
Try to ignore the funky percentages, that's because the images I was using have a weird aspect ratio (1920 x 966), more on that below.
So that's the first problem. I have 2 sliders, and at any time when I click a thumbnail only 1 of them will display a main image. I want to be able to copy it dozens of times and have each slider display a corresponding main image.
My second problem is that fact that this slider wasn't really responsive when I found it. I partially solved it by using percentages instead of pixels, but I don't really know how to apply this to the thumbnails.
The web page needs to be able to be viewed on mobile devices aswell, thus this is an important feature.
And yes I realize that there are probably better and smarter ways of creating a responsive CSS slider, but like I said, I'm a total noob. This works for me.

You can't use same name "slide_switch" for all inputs. It groups them together, so only one of them could be checked. You have to use different name for every project.

<div class="slider-wrapper">
<ul class="s-thumbs">
<li><img src="img/thumb1.png" alt="" /><span>Image 1</span></li>
<li><img src="img/thumb2.png" alt="" /><span>Image 2</span></li>
<li><img src="img/thumb3.png" alt="" /><span>Image 3</span></li>
<li><img src="img/thumb4.png" alt="" /><span>Image 4</span></li>
<li><img src="img/thumb5.png" alt="" /><span>Image 5</span></li>
<li><img src="img/thumb6.png" alt="" /><span>Image 6</span></li>
<li><img src="img/thumb7.png" alt="" /><span>Image 7</span></li>
</ul>
</div><ul class="s-slides">
<li id="slide-1" class="slideLeft"><img src="img/slide1.png" alt="" /></li>
<li id="slide-2" class="slideRight"><img src="img/slide2.png" alt="" /></li>
<li id="slide-3" class="slideTop"><img src="img/slide3.png" alt="" /></li>
<li id="slide-4" class="slideBottom"><img src="img/slide4.png" alt="" /></li>
<li id="slide-5" class="zoomIn"><img src="img/slide5.png" alt="" /></li>
<li id="slide-6" class="zoomOut"><img src="img/slide6.png" alt="" /></li>
<li id="slide-7" class="rotate"><img src="img/slide7.png" alt="" /></li>
</ul>
</div>
I only give you HTML code & in this link you can check CSS code. So by using css you can make slide or you can change as you want.
Please check this link:-http://designmodo.com/slider-css3/ & https://www.sanwebe.com/2012/08/pure-css3-tutorials-examples

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>

css to highlight image of selected <Input> box

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;
}

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

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>

arrange text below image

I want to have option buttons to have image and text below image. Right now i have managed to have image but dont know how to arrange text exactly below image without disturbing alignment.
<div>
<label>
<input type="radio" name="fb" value="small" />
<img src="http://placehold.it/20x20/35d/fff&text=f">
</label>
<label>
<input type="radio" name="fb" value="big" />
<img src="http://placehold.it/40x60/35d/fff&text=f">
</label>
<label>
<input id="fb3" type="radio" name="fb" value="med" />
<img src="http://cache1.asset-cache.net/gc/120523070-dogs-gods-gettyimages.jpg?v=1&c=IWSAsset&k=2&d=de2%2btiBrzaNEk9d4xwzh%2fvq8qyKYRsuWlpI1%2f65dmsaBkiniqNTDJkrq7zrUnaC6">
</label>
</div>
<div>
<label>
<input type="radio" name="fb" value="small1" text="ss" />
<img src="http://placehold.it/20x20/35d/fff&text=f" text="sdsdsd">
</label>
<label>
<input type="radio" name="fb" value="big1" />
<img src="http://placehold.it/40x60/35d/fff&text=f">
</label>
<label>
<input id="fb3" type="radio" name="fb" value="med1" />
<img src="http://cache1.asset-cache.net/gc/120523070-dogs-gods-gettyimages.jpg?v=1&c=IWSAsset&k=2&d=de2%2btiBrzaNEk9d4xwzh%2fvq8qyKYRsuWlpI1%2f65dmsaBkiniqNTDJkrq7zrUnaC6">
</label>
</div>
Here is Fiddle .
I am looking for output something like below
Also wish to generate option button in rows and column dynamically. Any idea related on how to achieve it?
Just set the to display: block;
.figures span, .figures img {
display: block;
}
you can write as
<label>
<input type="radio" name="fb" value="big1" />
<img src="http://placehold.it/40x60/35d/fff&text=f">
<span>your text</span>
</label>
Just add this css to the page:
<Style>
label{
float:left;
height:100px;/*can be modified*/
padding:10px;/*can be modified*/
width:50px;
}
</Style>
and after every image add and then the name as below:
<img src="http://placehold.it/20x20/35d/fff&text=f"><br/>
My name
To control how many images per row there is two ways.
1 - adding div for clear:
<div style='clear:both;'></div>
2- add everything inside a div and adjust the width of this div to until your reach to the proper count of images.
add this to the main div that you have
<div id="maincontainer" style="width:100px">
I updated the css by adding width:50px which means every label will be 50px... the main container is 100 => 2 items / row.
make the width of maincontainer to 150 -> 3 item / row....
According to your need, you can get desired output by using <br/> tag or without tag.
With <br /> Tag
fiddle
Without <br /> Tag
fiddle
In fiddle 1 i have used <br / > tag and in second i have used display:block; on images and display:inline-block on label. So use whatever you are ok with :)
You could wrap your images inside a <figure> tag and use <figcaption> for your text below it. I'm not sure what you mean in regards to "option buttons" though.
http://codepen.io/partypete25/pen/KzJOyY
<figure>
<img src="image-src-url" alt="">
<figcaption>Dog</figcaption>
</figure>
Change your CSS with this:
label > input + img {
/* IMAGE STYLES */
cursor: pointer;
background-position: 50% 50%;
background-repeat: no-repeat;
border-radius: 50%;
width: 50px;
height: 50px;
margin: 5px;
border: 1px solid #ccc;
float: left;
}
Demo

Checkboxes aligned in a row

Bear with me as I'm not well versed with front end design. How can I get the following checkboxes aligned and stacked neatly as in the picture?
Right now I have them in a row of 9 checkboxes but they're not aligned and are spaced according to the length of the text.
As seen here:
JSFiddle
HTML:
<div class="tags">
<div class="col">
<label>
<input type="checkbox" rel="accounting" />Accounting</label>
<label>
<input type="checkbox" rel="courier" />Courier</label>
<label>
<input type="checkbox" rel="project-management" />Project Management</label>
<label>
<input type="checkbox" rel="video-games" />Video Games</label>
<label>
<input type="checkbox" rel="dentistry" />Dentistry</label>
<label>
<input type="checkbox" rel="librarian" />Librarian</label>
<label>
<input type="checkbox" rel="programmer" />Programmer</label>
<label>
<input type="checkbox" rel="architect" />Architect</label>
</div>
<div class="col">
<label>
<input type="checkbox" rel="photographer" />Photographer</label>
<label>
<input type="checkbox" rel="it" />IT</label>
<label>
<input type="checkbox" rel="artist" />Artist</label>
<label>
<input type="checkbox" rel="web-developer" />Web Developer</label>
<label>
<input type="checkbox" rel="web-designer" />Web Designer</label>
<label>
<input type="checkbox" rel="neurologist" />Neurologist</label>
<label>
<input type="checkbox" rel="veterinarian" />Veterinarian</label>
<label>
<input type="checkbox" rel="teacher" />Teacher</label>
</div>
<div class="col">
<label>
<input type="checkbox" rel="character-animator" />Character Animator</label>
<label>
<input type="checkbox" rel="salesman" />Salesman</label>
<label>
<input type="checkbox" rel="telemarketing" />Telemarketeing</label>
<label>
<input type="checkbox" rel="construction" />Construction</label>
<label>
<input type="checkbox" rel="lawyer" />Lawyer</label>
<label>
<input type="checkbox" rel="actor" />Actor</label>
<label>
<input type="checkbox" rel="policeman" />Policeman</label>
<label>
<input type="checkbox" rel="forestry" />Forestry</label>
</div>
</div>
<!-- end tags -->
CSS:
.filter {
width: 850px;
padding: 25px;
border: 1px solid black;
margin: 25px;
float: left;
}
.col {
width: 100%;
display: block;
margin-right: 10px;
}
label{
vertical-align: top;
float: left;
width: 160px;
}
Edit
I'd use a table layout. Simply add the following CSS:
.tags {
display: table;
}
.col {
display: table-row;
}
.col label {
display: table-cell;
}
Updated fiddle: http://jsfiddle.net/5sz6qdos/13/
Others might use flexbox but I have never used it myself, so not sure how to implement that.
I would probably go a different route, however, to make it more semantic and setup to be more flexible:
<ul class="tags">
<li class="tag"><label>...
....<!--put ALL of your label elements in a single parent element-->
</ul>
and
.tag {
display: block;
float: left;
width: 25%; /*for if you want 4 columns, or*/
width: 120px; /*if you want specific widths*/
}
.tags:after { content: ""; display: table; clear: both; } /*clearfix*/
Using percentages will flex all the columns, or using fixed pixels will allow the elements to flow (my preference).
first of all change your html code like that:
<input type="checkbox" name="accounting" id="accounting" rel="accounting" />
<label for="accounting">Accounting</label>
Do this for every checkbox.
Then Do the follwoing css
.tags{clear:both}
.col{float:left;width:120px;/*adjust your width */}
.col lable, .col input{display:inline-block;}
.col label{width:120px;/*adjust your width */}
.col input{width:20px;/*adjust your width */}
For starters, you're using the label tag wrong. They should not have an input inside them. And how I would do what you're trying to do is something like this:
<div class="col">
<label>Job</label>
<input>
<label>Job</label>
<input>
</div>
<div class="col">
<label>Job</label>
<input>
<label>Job</label>
<input>
</div>
Then in your CSS...
.col {
display: inline-block;
width: 33.3%;
vertical-align: top;}
label {
display: inline-block;
width: 100px;}
input {
display: inline-block;
width: calc(100% - 100px);}
To make sure the columns, labels, and inputs all touch nicely, you have to remove the whitespace. You can either remove it from the code itself, connect elements with comment tags, or set the font-size to 0 on the container. And it wouldn't hurt to throw this in your CSS:
* {
box-sizing: border-box;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;}
So you're kinda having the same problem I mentioned belwo... the text can't be what you're basing off of. You have to set an actual width.
http://jsfiddle.net/tueez7bx/6/
This works, but extends past your limits. You should really consider my other options I provide below.
Also, you can't use ids the way you are. That is incorrect. You'll need to change all the #col to .col.
Second Edit
So based on a comment provided below I have come to realize the goal of what you're trying. Sadly because of the flexibility of text and items you would need to have defined widths for each to line up perfectly. If you don't know what the longest string will be then you will have a problem with risking that string breaking below the words or running into the next checkbox.
You can see that here: http://jsfiddle.net/5sz6qdos/22/
However.. if you extend the width of your container and just have a greater width you will be able to avoid this...
You can see what I am imagining you're asking here: http://jsfiddle.net/5sz6qdos/28/
Before Edit
You're doing well overall...
http://jsfiddle.net/5sz6qdos/3/
.col {
width: 160px;
float: left;
margin-right: 10px;
}
label{
display: block;
}
This does define a width and doesn't allow for full flexibility. It does however give you the option of going to responsive layouts with this data.
To get the boxes the way you want them you cannot use pure CSS. You will need a mix of Javascript. Checkboxes themselves can not be edited with CSS directly. You will need to hide the checkbox with display: none and add an image for the boxes themselves. Once you have done this you will need to use jQuery to check and uncheck each box. That is the only way to get the exact look.
SO has a lot of answers out there for the jQuery part.
Thanks to all for the knowledge and push in the right direction.
Here is the working solution I found while setting line widths.
JSFiddle
HTML
<div class="filter">
<h3 style="text-align: center;">Blog Profession Filters</h3>
<ul class="checkbox">
<li>
<input type="checkbox" id="cb1" rel="accounting" value="accounting" />
<label for="cb1">Accounting</label>
</li>
<li>
<input type="checkbox" id="cb2" rel="project-management" value="project-management" />
<label for="cb2">Project Management</label>
</li>
<li>
<input type="checkbox" id="cb3" rel="information technology" value="information-technology" />
<label for="cb3">Information Technology</label>
</li>
<li>
<input type="checkbox" id="cb4" rel="courier" value="courier" />
<label for="cb4">Courier</label>
</li>
<li>
<input type="checkbox" id="cb5" rel="video-games" value="video-games" />
<label for="cb5">Video Games</label>
</li>
<li>
<input type="checkbox" id="cb6" rel="web-development" value="web-development" />
<label for="cb6>">Web Development</label>
</li>
<li>
<input type="checkbox" id="cb7" rel="veterinarian" value="veterinarian" />
<label for="cb6>">Veterinarian</label>
</li>
<li>
<input type="checkbox" id="cb8" rel="web-designer" value="web-designer" />
<label for="cb6>">Web Designer</label>
</li>
<li>
<input type="checkbox" id="cb9" rel="attorney" value="attorney" />
<label for="cb9>">Attorney</label>
</li>
<li>
<input type="checkbox" id="cb10" rel="medical-practitioner" value="medical-practitioner" />
<label for="cb10>">Medical Practitioner</label>
</li>
<li>
<input type="checkbox" id="cb11" rel="telemarketing" value="telemarketing" />
<label for="cb11>">Telemarketing</label>
</li>
<li>
<input type="checkbox" id="cb12" rel="construction" value="construction" />
<label for="cb12>">Construction</label>
</li>
</ul>
</div>
<div id="results">
<ul class="results">
<li class="accounting" style="list-style-type:none"> Accounting
</li>
<li class="project-management" style="list-style-type:none"> Game QA Project Management
</li>
<li class="information-technology" style="list-style-type:none"> Information Technology
</li>
<li class="courier" style="list-style-type:none"> Courier / Parcel Delivery
</li>
<li class="video-games" style="list-style-type:none"> Video Games
</li>
<li class="web-development" style="list-style-type:none"> Web Development
</li>
<li class="veterinarian" style="list-style-type:none"> Veterinarian
</li>
<li class="web-designer" style="list-style-type:none"> Wed Designer
</li>
<li class="attorney" style="list-style-type:none"> Attorney
</li>
<li class="medical-practitioner" style="list-style-type:none"> Medical Practitioner
</li>
<li class="telemarketing" style="list-style-type:none"> Telemarketing
</li>
<li class="construction" style="list-style-type:none"> Construction
</li>
</ul>
</div>
CSS
.filter {
width: 850px;
padding: 25px;
border: 1px solid black;
margin: 25px;
}
ul.checkbox {
margin: 0;
padding: 0;
margin-left: 20px;
list-style: none;
}
ul.checkbox li input {
margin-right: .25em;
}
ul.checkbox li {
border: 1px transparent solid;
display:inline-block;
width:12em;
}
ul.checkbox li label {
margin-left:;
}
ul.checkbox li:hover, ul.checkbox li.focus {
background-color: lightyellow;
border: 1px gray solid;
width: 12em;
}
.results {
width: 850px;
padding: 25px;
border: 1px solid black;
margin: 25px;
}