How can I position these thumbnails under the slider? - html

So, I found this cool css/html slider on a website, so I downloaded the code, and am going to study it. I've started to edit it and style it to my own needs, and I came upon this problem: when I added an image of a bigger size than the originals, the navigation thumbnails got covered. I want them under the slider.
CSS and HTML
* {
margin: 0;
padding: 0;
}
body {
background: #FFF;
}
.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.5s;
}
.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" id="id2" checked="checked" />
<label for="id2">
<img src="http://www.placehold.it/100" width="100" />
</label>
<img src="http://www.placehold.it/200X800" />
<input type="radio" name="slide_switch" id="id3" />
<label for="id3">
<img src="http://www.placehold.it/100/FF0000" width="100" />
</label>
<img src="http://www.placehold.it/640X320/FF0000" />
<input type="radio" name="slide_switch" id="id4" />
<label for="id4">
<img src="http://www.placehold.it/100/FF9900" width="100" />
</label>
<img src="http://www.placehold.it/640X320/FF9900" />
<input type="radio" name="slide_switch" id="id5" />
<label for="id5">
<img src="http://www.placehold.it/100/FFFF99" width="100" />
</label>
<img src="http://www.placehold.it/640X320/FFFF99" />
</div>
<script src="http://thecodeplayer.com/uploads/js/prefixfree.js" type="text/javascript"></script>

Start by restricting the width and height of the img to its container:
.slider > img {
max-width: 100%;
max-height: 100%;
}
Now, let's centre the image, this will look a lot better for images that don't span the width of the container:
.slider > img gets left: 50% and transform: translateX(-50%) (placed next to the existing scale transform).
Working Example
* {
margin: 0;
padding: 0;
}
body {
background: #FFF;
}
.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: 50%;
top: 0;
max-width: 100%;
max-height: 100%;
transition: all 0.5s;
}
.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) translateX(-50%);
}
.slider input[name='slide_switch']:checked+label+img {
opacity: 1;
transform: scale(1) translateX(-50%);
}
<div class="slider">
<input type="radio" name="slide_switch" id="id2" checked="checked" />
<label for="id2">
<img src="http://www.placehold.it/100" width="100" />
</label>
<img src="http://www.placehold.it/640X320" />
<input type="radio" name="slide_switch" id="id3" />
<label for="id3">
<img src="http://www.placehold.it/100/FF0000" width="100" />
</label>
<img src="http://www.placehold.it/1000X1000/FF0000" />
<input type="radio" name="slide_switch" id="id4" />
<label for="id4">
<img src="http://www.placehold.it/100/FF9900" width="100" />
</label>
<img src="http://www.placehold.it/640X320/FF9900" />
<input type="radio" name="slide_switch" id="id5" />
<label for="id5">
<img src="http://www.placehold.it/100/FFFF99" width="100" />
</label>
<img src="http://www.placehold.it/640X320/FFFF99" />
</div>
<script src="http://thecodeplayer.com/uploads/js/prefixfree.js" type="text/javascript"></script>

You can give a max-width and a max-height to your images so that they always fit in the container without stretching.
.slider>img {
position: absolute;
left: 0;
top: 0;
transition: all 0.5s;
/* ADD THESE LINES */
max-width: 100%;
max-height: 100%;
}

Related

How can I color checked label in css?

I wanted to color those labels under <div class="navigation"> as black whenever is active on the image. I've tried writing #r1:checked~.navigation label:nth-child(1){ background: #000; } in CSS but it doesn't work. Any help would be appreciated, I am new to web development.
Thank you~
.slidershow {
width: 1000px;
height: 600px;
border: 10px solid #ccc;
overflow: hidden;
}
.middle {
position: relative;
}
.navigation {
position: relative;
justify-content: center;
align-items: center;
right: auto;
display: flex;
}
.bar {
width: 20px;
height: 20px;
border: 2px solid rgba(0, 0, 0, .3);
margin: 6px;
cursor: pointer;
transition: .4s;
}
input[name="r"] {
position: absolute;
visibility: hidden;
}
.slides {
width: 500%;
height: 100%;
display: flex;
position: relative;
}
.slide {
width: 20%;
transition: .6s;
}
.slide img {
width: 100%;
height: 100%;
}
.bar:hover {
background: #E3DFFF;
}
.bar:active {
background: #000;
}
#r1:checked~.s1 {
margin: 0%;
}
#r2:checked~.s1 {
margin-left: -20%;
}
#r3:checked~.s1 {
margin-left: -40%;
}
<!-- ##Slider## -->
<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">
<div class="slide s1">
<img src="https://dummyimage.com/600x400/000000/00bf16&text=First+Image" alt="">
</div>
<div class="slide">
<img src="https://dummyimage.com/600x400/000000/00bf16&text=Second+Image" alt="">
</div>
<div class="slide">
<img src="https://dummyimage.com/600x400/000000/00bf16&text=Third+Image" alt="">
</div>
</div>
</div>
<div class="navigation">
<label for="r1" class="bar"></label>
<label for="r2" class="bar"></label>
<label for="r3" class="bar"></label>
</div>

The CSS image slider overlays the position of the elements

I am coding a simple landing page. In theory, each div you code will show below the previous one and so forth.
I made a little navbar and then expected the slider to appear below it. Then, I wanted to add an image below the slider (the one with brands' logos). Problem is, the image appears below the navbar. I am guessing there is something with the position of the slider but I can't figure out what it is.
I'd rather not use position: absolute or position: relative to position all my elements, so I am here to understand what the problem might be.
html {
font-family: "Arial", Helvetica, sans-serif;
}
/*---navigation--*/
.top-nav {
height: 105px;
display: flex;
align-items: center;
}
ul.main-nav {
display: flex;
align-items: center;
list-style-type: none;
margin: 0;
padding: 0;
background-color: #333;
height: 40px;
}
ul.main-nav li {
display: block;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 15px;
font-weight: 700;
color: #FCAF17;
}
ul.main-nav li:hover {
cursor: pointer;
color: #FFFFFF;
}
/* main slider */
.slider {
width: 100%;
height: 100%;
left: 0;
top: 25%;
opacity: 1;
z-index: 0;
display: flex;
display: -webkit-flex;
display: -ms-flexbox;
flex-flow: row 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);
}
/* image slider position */
.slide1 {
position: absolute;
left: 0;
}
.slide2 {
position: absolute;
left: 100%;
}
.slide3 {
position: absolute;
left: 200%;
}
/* slider pagination */
.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 control */
input {
visibility: hidden;
}
.slide-radio1:checked~.slider {
-webkit-transform: translateX(0%);
transform: translateX(0%);
}
.slide-radio2:checked~.slider {
-webkit-transform: translateX(-100%);
transform: translateX(-100%);
}
.slide-radio3:checked~.slider {
-webkit-transform: translateX(-200%);
transform: translateX(-200%);
}
/*----------slider end----------------*/
.box {
background-color: blue;
}
<!--navigation-->
<div class="top-nav">
<img src="http://remote.fizzmod.com/ibNZlyN7LX319Mlx/frontend/images/logo.jpg"></img>
</div>
<ul class="main-nav">
<li>HOMBRE</li>
<li>MUJER</li>
<li>NIÑOS</li>
<li>Carrito</li>
</ul>
<!--image slider-->
<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">
<input type="radio" name="slider" class="slide-radio3" id="slider_3">
<div class="slider-pagination">
<label for="slider_1" class="page1"></label>
<label for="slider_2" class="page2"></label>
<label for="slider_3" class="page3"></label>
</div>
<div class="slider slide1">
<div>
<img src="http://remote.fizzmod.com/ibNZlyN7LX319Mlx/frontend/images/racing-980x400.jpg">
</div>
</div>
<div class="slider slide2">
<div>
<img src="http://remote.fizzmod.com/ibNZlyN7LX319Mlx/frontend/images/evoACCURACY_980x400px.jpg">
</div>
</div>
<div class="slider slide3">
<div>
<img src="http://remote.fizzmod.com/ibNZlyN7LX319Mlx/frontend/images/racing-980x400.jpg">
</div>
</div>
</div>
<div class="brands">
<img src="http://remote.fizzmod.com/ibNZlyN7LX319Mlx/frontend/images/marcas.jpg">
</div>
Live demo
first thing you can add Position : relative and second add height to div like i added <div class="demo" style="opacity:0;"> <img src="http://remote.fizzmod.com/ibNZlyN7LX319Mlx/frontend/images/racing-980x400.jpg"> </div>
<div class="css-slider-wrapper">
<div class="demo" style="opacity:0;"> <img src="http://remote.fizzmod.com/ibNZlyN7LX319Mlx/frontend/images/racing-980x400.jpg"> </div>
<input name="slider" class="slide-radio1" checked="" id="slider_1" type="radio">
<input name="slider" class="slide-radio2" id="slider_2" type="radio">
<input name="slider" class="slide-radio3" id="slider_3" type="radio">
<div class="slider-pagination">
<label for="slider_1" class="page1"></label>
<label for="slider_2" class="page2"></label>
<label for="slider_3" class="page3"></label>
</div>
<div class="slider slide1">
<div>
<img src="http://remote.fizzmod.com/ibNZlyN7LX319Mlx/frontend/images/racing-980x400.jpg">
</div>
</div>
<div class="slider slide2">
<div>
<img src="http://remote.fizzmod.com/ibNZlyN7LX319Mlx/frontend/images/evoACCURACY_980x400px.jpg">
</div>
</div>
<div class="slider slide3">
<div>
<img src="http://remote.fizzmod.com/ibNZlyN7LX319Mlx/frontend/images/racing-980x400.jpg">
</div>
</div>
</div>
use style :
.css-slider-wrapper {
position: relative;
}
.slide1 {
left: 0;
}
try it i thing it's work other give me Demo line https://jsfiddle.net/

How to add text to a image that works as radio button?

I want to use in image as radio button. That works as expected. However the code I found is applying a border to the image when it is active. Instead of the border I want the active image to be covered by a green tick "✓". I don't really know how to do it. Thanks for your help. Below my code with the frame.
HTML:
<fieldset id="theme" style="margin:0; padding:0; border:none;">
<div style="margin-top:10px;">
<figure style="float:left; margin:0;">
<label id="styleinput">
<input type="radio" name="theme" value="defaultlayout"/>
<img src="./static/images/darklayout.png" style="max-width:170px; margin-right:20px;"/>
<figcaption id="caption" style="margin-left:10px; font-size:12px;"><b>Default</b><br><a>Preview</a></figcaption>
</label>
</figure>
<figure style="float:left; margin:0;">
<label id="styleinput">
<input type="radio" name="theme" value="defaultlayout"/>
<img src="./static/images/lightlayout.png" style="max-width:170px; margin-right:20px;"/>
<figcaption id="caption" style="margin-left:10px; font-size:12px;"><b>Light</b><br><a>Preview</a></figcaption>
</label>
</figure>
</div>
</fieldset>
CSS:
#styleinput > input{ /* HIDE RADIO */
visibility: hidden; /* Makes input not-clickable */
position: absolute; /* Remove input from document flow */
}
#styleinput > input + img{ /* IMAGE STYLES */
cursor:pointer;
border:2px solid transparent;
}
#styleinput > input:checked + img{ /* (RADIO CHECKED) IMAGE STYLES */
border:2px solid #f00;
}
https://jsfiddle.net/k4a71tnt/
In the code snippet example below, you'll notice that I've wrapped the img in a containing element in order to use a pseudo-element to display a styled checkmark (utf8 character) on selection.
#styleinput>input {
/* HIDE RADIO */
visibility: hidden;
/* Makes input not-clickable */
position: absolute;
/* Remove input from document flow */
}
#styleinput>input+.img-container {
/* IMAGE STYLES */
cursor: pointer;
position: relative;
margin-right: 20px;
}
#styleinput>input+.img-container img {
max-width: 170px;
}
#styleinput>input+.img-container:before {
/* IMAGE STYLES */
content: "\2713";
opacity: 0;
transition: .7s;
left: 0;
right: 0;
top: 0;
bottom: 0;
display: block;
margin: auto;
position: absolute;
font-size: 20px;
text-align: center;
font-weight: bold;
background: rgba(0, 128, 0, 0.5);
color: white;
border-radius: 100%;
width: 50px;
height: 50px;
line-height: 50px;
}
#styleinput>input:checked+.img-container:before {
/* (RADIO CHECKED) IMAGE STYLES */
opacity: 1;
}
<fieldset id="theme" style="margin:0; padding:0; border:none;">
<div style="margin-top:10px;">
<figure style="float:left; margin:0;">
<label id="styleinput">
<input type="radio" name="theme" value="defaultlayout"/>
<div class="img-container"><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAYAAABccqhmAAAQYElEQVR4Xu3ce2xkZRnH8ed9z2yBhQRElLC0c047w3JZAjHEyCUoEhKNCmK8EiAQgVVQEJGEP0wMf5BoBCSYqAh4DRgIIuIFBRHBQIwiKpBVLjPtOdNyUyCCbNilnfc1U1nSlm5n1sN72qfvd//teZ/zPJ/nzK9TOsUI/xBAIFoBE+3kDI4AAkIA8BAgELEAARDx8hkdAQKAZwCBiAUIgIiXz+gIEAA8AwhELEAARLx8RkeAAOAZQCBiAQIg4uUzOgIEAM8AAhELEAARL5/RESAAeAYQiFiAAIh4+YyOAAHAM4BAxAIEQMTLZ3QECACeAQQiFiAAIl4+oyNAAPAMIBCxAAEQ8fIZHQECgGcAgYgFCICIl8/oCBAAPAMIRCxAAES8fEZHgADgGUAgYgECIOLlMzoCBADPAAIRCxAAES+f0REgAHgGEIhYgACIePmMjgABwDOAQMQCBEDEy2d0BAgAngEEIhYgACJePqMjQADwDCAQsQABEPHyGR0BAoBnAIGIBQiAiJfP6AgQADwDCEQsQABEvHxGR4AA4BlAIGIBAiDi5TM6AgQAzwACEQsQABEvn9ERIAB4BhCIWIAAiHj5jI4AAcAzgEDEAgRAxMtndAQIAJ4BBCIWIAAiXj6jI0AA8AwgELEAARDx8hkdAQKAZwCBiAUIgIiXz+gIEAA8AwhELEAARLx8RkeAAOAZQCBiAQIg4uUzOgIrMQCSZpoeKt4e5MS/2RizhjUhoF/AeW/MZuN9IbXaA+12+58rYaYVEwDNen1D19rzrJePisibVgIOPSAQSsB49ycvybVmKPlhq9XaGuo+/eouewCsX7d+r27tlUvFyGkisuz99APj6wi8kQLOu0lr7XntPP/pG1l30FrL+oJrpukRXsyPRWTdoA1zHQKrUcAZuXrtrrueu2nTpleqnG/ZAqCRZe+VrtwiVnaucmDuhcC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2AagECQPX6aB6BcgIEQDk/TiOgWoAAUL0+mkegnAABUM6P0wioFiAAVK+P5hEoJ0AAlPPjNAKqBQgA1eujeQTKCRAA5fw4jYBqAQJA9fpoHoFyAgRAOT9OI6BagABQvT6aR6CcAAFQzo/TCKgWIABUr4/mESgnQACU8+M0AqoFCADV66N5BMoJEADl/DiNgGoBAkD1+mgegXICBEA5P04joFqAAFC9PppHoJzAfwE01N559axr3wAAAABJRU5ErkJggg=="/></div>
<figcaption id="caption" style="margin-left:10px; font-size:12px;"><b>Default</b><br><a>Preview</a></figcaption>
</label>
</figure>
<figure style="float:left; margin:0;">
<label id="styleinput">
<input type="radio" name="theme" value="defaultlayout"/>
<div class="img-container"><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAYAAABccqhmAAAQYElEQVR4Xu3ce2xkZRnH8ed9z2yBhQRElLC0c047w3JZAjHEyCUoEhKNCmK8EiAQgVVQEJGEP0wMf5BoBCSYqAh4DRgIIuIFBRHBQIwiKpBVLjPtOdNyUyCCbNilnfc1U1nSlm5n1sN72qfvd//teZ/zPJ/nzK9TOsUI/xBAIFoBE+3kDI4AAkIA8BAgELEAARDx8hkdAQKAZwCBiAUIgIiXz+gIEAA8AwhELEAARLx8RkeAAOAZQCBiAQIg4uUzOgIEAM8AAhELEAARL5/RESAAeAYQiFiAAIh4+YyOAAHAM4BAxAIEQMTLZ3QECACeAQQiFiAAIl4+oyNAAPAMIBCxAAEQ8fIZHQECgGcAgYgFCICIl8/oCBAAPAMIRCxAAES8fEZHgADgGUAgYgECIOLlMzoCBADPAAIRCxAAES+f0REgAHgGEIhYgACIePmMjgABwDOAQMQCBEDEy2d0BAgAngEEIhYgACJePqMjQADwDCAQsQABEPHyGR0BAoBnAIGIBQiAiJfP6AgQADwDCEQsQABEvHxGR4AA4BlAIGIBAiDi5TM6AgQAzwACEQsQABEvn9ERIAB4BhCIWIAAiHj5jI4AAcAzgEDEAgRAxMtndAQIAJ4BBCIWIAAiXj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8MVKZxziKw2gUIgNW+YeZDYAkBAoDHA4GIBQiAiJfP6AgQADwDCEQssOoDwIs8PzQzvfj/ry/ixTN6fALTtdrpIuayqH4LUEXCxfcoMbFGgSg/B0AAaHxU6TmEAAEQQpWaCCgRIACULIo2EQghQACEUKUmAkoECAAli6JNBEIIEAAhVKmJgBIBAkDJomgTgRACBEAIVWoioESAAFCyKNpEIIQAARBClZoIKBEgAJQsijYRCCFAAIRQpSYCSgQIACWLok0EQggQACFUqYmAEgECQMmiaBOBEAIEQAhVaiKgRIAAULIo2kQghAABEEKVmggoESAAlCyKNhEIIUAAhFClJgJKBAgAJYuiTQRCCBAAIVSpiYASAQJAyaJoE4EQAgRACFVqIqBEgABQsijaRCCEAAEQQpWaCCgRIACULIo2EQghQACEUKUmAkoECAAli6JNBEIIEAAhVKmJgBIBAkDJomgTgRACBEAIVWoioESAAFCyKNpEIIQAARBClZoIKBEgAJQsijYRCCFAAIRQpSYCSgQIACWLok0EQggQACFUqYmAEgECQMmiaBOBEAIEQAhVaiKgRIAAULIo2kQghAABEEKVmggoESAAlCyKNhEIIUAAhFClJgJKBAgAJYuiTQRCCBAAIVSpiYASAQJAyaJoE4EQAgRACFVqIqBEgABQsijaRCCEAAEQQpWaCCgRIACULIo2EQghQACEUKUmAkoECAAli6JNBEIIEAAhVKmJgBIBAkDJomgTgRACBEAIVWoioESAAFCyKNpEIIQAARBClZoIKBEgAJQsijYRCCFAAIRQpSYCSgQIACWLok0EQggQACFUqYmAEgECQMmiaBOBEAIEQAhVaiKgRIAAULIo2kQghAABEEKVmggoESAAlCyKNhEIIUAAhFClJgJKBAgAJYuiTQRCCBAAIVSpiYASAQJAyaJoE4EQAgRACFVqIqBEgABQsijaRCCEAAEQQpWaCCgRIACULIo2EQghQACEUKUmAkoECAAli6JNBEIIEAAhVKmJgBIBAkDJomgTgRACBEAIVWoioESAAFCyKNpEIIQAARBClZoIKBEgAJQsijYRCCFAAIRQpSYCSgQIACWLok0EQggQACFUqYmAEgECQ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dAAJTz4zQCqgUIANXro3kEygkQAOX8OI2AagECQPX6aB6BcgIEQDk/TiOgWoAAUL0+mkegnAABUM6P0wioFiAAVK+P5hEoJ0AAlPPjNAKqBQgA1eujeQTKCRAA5fw4jYBqAQJA9fpoHoFyAgRAOT9OI6BagABQvT6aR6CcAAFQzo/TCKgWIABUr4/mESgnQACU8+M0AqoFCADV66N5BMoJEADl/DiNgGoBAkD1+mgegXICBEA5P04joFqAAFC9PppHoJwAAVDOj9MIqBYgAFSvj+YRKCdAAJTz4zQCqgUIANXro3kEygkQAOX8OI2AagECQPX6aB6BcgIEQDk/TiOgWoAAUL0+mkegnAABUM6P0wioFiAAVK+P5hEoJ0AAlPPjNAKqBQgA1eujeQTKCRAA5fw4jYBqAQJA9fpoHoFyAgRAOT9OI6BagABQvT6aR6CcAAFQzo/TCKgWIABUr4/mESgnQACU8+M0AqoFCADV66N5BMoJEADl/DiNgGoBAkD1+mgegXICBEA5P04joFqAAFC9PppHoJzAfwE01N559axr3wAAAABJRU5ErkJggg=="/></div>
<figcaption id="caption" style="margin-left:10px; font-size:12px;"><b>Light</b><br><a>Preview</a></figcaption>
</label>
</figure>
</div>
</fieldset>
The solution to your problem will be to add an overlay span which wraps around your element figure with a background-image having the transparent tick.
Refer the below code snippet and let me know if you face any issues during implementation.
#styleinput > input {
/* HIDE RADIO */
visibility: hidden;
/* Makes input not-clickable */
position: absolute;
/* Remove input from document flow */
}
#styleinput > input + img {
/* IMAGE STYLES */
cursor: pointer;
border: 2px solid transparent;
}
#styleinput > input:checked + img {
/* (RADIO CHECKED) IMAGE STYLES */
border: 2px solid #f00;
}
#styleinput > input:checked ~ span.overlay-image {
display: block;
}
.parent {
float: left;
margin: 0;
position: relative;
}
.overlay-image {
position: absolute;
display: none;
top: 0px;
right: 0px;
bottom: 0px;
left: 0px;
background-image: url('http://www.clker.com/cliparts/2/k/n/l/C/Q/transparent-green-checkmark-md.png');
background-size: 60% 60%;
background-position: top center;
background-repeat: no-repeat;
}
<fieldset id="theme" style="margin:0; padding:0; border:none;">
<div style="margin-top:10px;">
<figure class="parent">
<label id="styleinput">
<input type="radio" name="theme" value="defaultlayout" />
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAYAAABccqhmAAAQYElEQVR4Xu3ce2xkZRnH8ed9z2yBhQRElLC0c047w3JZAjHEyCUoEhKNCmK8EiAQgVVQEJGEP0wMf5BoBCSYqAh4DRgIIuIFBRHBQIwiKpBVLjPtOdNyUyCCbNilnfc1U1nSlm5n1sN72qfvd//teZ/zPJ/nzK9TOsUI/xBAIFoBE+3kDI4AAkIA8BAgELEAARDx8hkdAQKAZwCBiAUIgIiXz+gIEAA8AwhELEAARLx8RkeAAOAZQCBiAQIg4uUzOgIEAM8AAhELEAARL5/RESAAeAYQiFiAAIh4+YyOAAHAM4BAxAIEQMTLZ3QECACeAQQiFiAAIl4+oyNAAPAMIBCxAAEQ8fIZHQECgGcAgYgFCICIl8/oCBAAPAMIRCxAAES8fEZHgADgGUAgYgECIOLlMzoCBADPAAIRCxAAES+f0REgAHgGEIhYgACIePmMjgABwDOAQMQCBEDEy2d0BAgAngEEIhYgACJePqMjQADwDCAQsQABEPHyGR0BAoBnAIGIBQiAiJfP6AgQADwDCEQsQABEvHxGR4AA4BlAIGIBAiDi5TM6AgQAzwACEQsQABEvn9ERIAB4BhCIWIAAiHj5jI4AAcAzgEDEAgRAxMtndAQIAJ4BBCIWIAAiXj6jI0AA8AwgELEAARDx8hkdAQKAZwCBiAUIgIiXz+gIEAA8AwhELEAARLx8RkeAAOAZQCBiAQIg4uUzOgIrMQCSZpoeKt4e5MS/2RizhjUhoF/AeW/MZuN9IbXaA+12+58rYaYVEwDNen1D19rzrJePisibVgIOPSAQSsB49ycvybVmKPlhq9XaGuo+/eouewCsX7d+r27tlUvFyGkisuz99APj6wi8kQLOu0lr7XntPP/pG1l30FrL+oJrpukRXsyPRWTdoA1zHQKrUcAZuXrtrrueu2nTpleqnG/ZAqCRZe+Vrt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Io2kQghAABEEKVmggoESAAlCyKNhEIIUAAhFClJgJKBAgAJYuiTQRCCBAAIVSpiYASAQJAyaJoE4EQAgRACFVqIqBEgABQsijaRCCEAAEQQpWaCCgRIACULIo2EQghQACEUKUmAkoECAAli6JNBEIIEAAhVKmJgBIBAkDJomgTgRACBEAIVWoioESAAFCyKNpEIIQAARBClZoIKBEgAJQsijYRCCFAAIRQpSYCSgQIACWLok0EQggQACFUqYmAEgECQMmiaBOBEAIEQAhVaiKgRIAAULIo2kQghAABEEKVmggoESAAlCyKNhEIIUAAhFClJgJKBAgAJYuiTQRCCBAAIVSpiYASAQJAyaJoE4EQAgRACFVqIqBEgABQsijaRCCEAAEQQpWaCCgRIACULIo2EQghQACEUKUmAkoECAAli6JNBEIIEAAhVKmJgBIBAkDJomgTgRACBEAIVWoioESAAFCyKNpEIIQAARBClZoIKBEgAJQsijYRCCFAAIRQpSYCSgQIACWLok0EQggQACFUqYmAEgECQMmiaBOBEAIEQAhVaiKgRIAAULIo2kQghAABEEKVmggoESAAlCyKNhEIIUAAhFClJgJKBAgAJYuiTQRCCBAAIVSpiYASAQJAyaJoE4EQAgRACFVqIqBEgABQsijaRCCEAAEQQpWaCCgRIACULIo2EQghQACEUKUmAkoECAAli6JNBEIIEAAhVKmJgBIBAkDJomgTgRACBEAIVWoioESAAFCyKNpEIIQAARBClZoIKBEgAJQsijYRCCFAAIRQpSYCSgQIACWLok0EQggQACFUqYmAEgECQMmiaBOBEAIEQAhVaiKgRIAAULIo2kQghAABEEKVmggoESAAlCyKNhEIIUAAhFClJgJKBFZ/AKTpJ42Y78zdh3PuxYnJzu5KdkSbCAQTaNSz88TIlQtu8FS7yNcFu6mImJDF59Zujoye4K2/deH9dt3y8m4PPfPM5qr64D4IrESBZpZ9xXu5aH5v/qF2URwast/KAqAx3GhK0n184TDGyDGtPL8n5JDURmClC4zVs7uMkXfP7dM4+VFrMj85ZO+VBUDv3cZovV5YY0fmDeTlqnYnPzvkkNRGYCULrB8e3reb1A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3kEygkQAOX8OI2AagECQPX6aB6BcgIEQDk/TiOgWoAAUL0+mkegnAABUM6P0wioFiAAVK+P5hEoJ0AAlPPjNAKqBQgA1eujeQTKCRAA5fw4jYBqAQJA9fpoHoFyAgRAOT9OI6BagABQvT6aR6CcAAFQzo/TCKgWIABUr4/mESgnQACU8+M0AqoFCADV66N5BMoJEADl/DiNgGoBAkD1+mgegXICBEA5P04joFqAAFC9PppHoJzAfwE01N559axr3wAAAABJRU5ErkJggg=="
style="max-width:170px; margin-right:20px;" />
<span class="overlay-image"></span>
<figcaption id="caption" style="margin-left:10px; font-size:12px;"><b>Default</b>
<br><a>Preview</a></figcaption>
</label>
</figure>
<figure class="parent">
<label id="styleinput">
<input type="radio" name="theme" value="defaultlayout" />
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAYAAABccqhmAAAQYElEQVR4Xu3ce2xkZRnH8ed9z2yBhQRElLC0c047w3JZAjHEyCUoEhKNCmK8EiAQgVVQEJGEP0wMf5BoBCSYqAh4DRgIIuIFBRHBQIwiKpBVLjPtOdNyUyCCbNilnfc1U1nSlm5n1sN72qfvd//teZ/zPJ/nzK9TOsUI/xBAIFoBE+3kDI4AAkIA8BAgELEAARDx8hkdAQKAZwCBiAUIgIiXz+gIEAA8AwhELEAARLx8RkeAAOAZQCBiAQIg4uUzOgIEAM8AAhELEAARL5/RESAAeAYQiFiAAIh4+YyOAAHAM4BAxAIEQMTLZ3QECACeAQQiFiAAIl4+oyNAAPAMIBCxAAEQ8fIZHQECgGcAgYgFCICIl8/oCBAAPAMIRCxAAES8fEZHgADgGUAgYgECIOLlMzoCBADPAAIRCxAAES+f0REgAHgGEIhYgACIePmMjgABwDOAQMQCBEDEy2d0BAgAngEEIhYgACJePqMjQADwDCAQsQABEPHyGR0BAoBnAIGIBQiAiJfP6AgQADwDCEQsQABEvHxGR4AA4BlAIGIBAiDi5TM6AgQAzwACEQsQABEvn9ERIAB4BhCIWIAAiHj5jI4AAcAzgE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ppHoJwAAVDOj9MIqBYgAFSvj+YRKCdAAJTz4zQCqgUIANXro3kEygkQAOX8OI2AagECQPX6aB6BcgIEQDk/TiOgWoAAUL0+mkegnAABUM6P0wioFiAAVK+P5hEoJ0AAlPPjNAKqBQgA1eujeQTKCRAA5fw4jYBqAQJA9fpoHoFyAgRAOT9OI6BagABQvT6aR6CcAAFQzo/TCKgWIABUr4/mESgnQACU8+M0AqoFCADV66N5BMoJEADl/DiNgGoBAkD1+mgegXICBEA5P04joFqAAFC9PppHoJwAAVDOj9MIqBYgAFSvj+YRKCdAAJTz4zQCqgUIANXro3kEygkQAOX8OI2AagECQPX6aB6BcgIEQDk/TiOgWoAAUL0+mkegnAABUM6P0wioFiAAVK+P5hEoJ0AAlPPjNAKqBQgA1eujeQTKCRAA5fw4jYBqAQJA9fpoHoFyAgRAOT9OI6BagABQvT6aR6CcAAFQzo/TCKgWIABUr4/mESgnQACU8+M0AqoFCADV66N5BMoJEADl/DiNgGoBAkD1+mgegXICBEA5P04joFqAAFC9PppHoJzAfwE01N559axr3wAAAABJRU5ErkJggg=="
style="max-width:170px; margin-right:20px;" />
<span class="overlay-image"></span>
<figcaption id="caption" style="margin-left:10px; font-size:12px;"><b>Light</b>
<br><a>Preview</a></figcaption>
</label>
</figure>
</div>
</fieldset>

css ~ selector does not apply style to all targeted elements (z-index to next/prev labels)

I have the following pure css slideshow and I'm trying to implement "next/prev" buttons in addition to the thumbnails (both are labels pointing to a <input type="radio">).
The thumbnails are labels with an image inside, so I created more labels for the buttons. The problem is that I can't figure out how to correctly hide them all except for the ones next to the checked input.
I've tried the following code:
.slider input[name='slide_switch'] ~ label.next,
.slider input[name='slide_switch'] ~ label.previous
{
z-index: -1
}
.slider input[name='slide_switch']:checked ~ label.next,
.slider input[name='slide_switch']:checked ~ label.previous {
z-index: 1
}
That should target all <label class="next"> and <label class="previous"> in the HTML, but for some reason it's not working, I "can see" more than one button,one upon another, because I gave them opacity: 0.6 and they don't look semi-transparent. However the last two of them show the correct opacity and are working, if I'm in the last picture I can click the previous button and it'll take me to the 4th picture, and if I click next it takes me to the 5th (unfortunately this happens with all pictures).
I'm working it here: https://jsfiddle.net/5v6ajfup/
The HTML code:
<div class="slider">
<input type="radio" name="slide_switch" id="id1"/>
<label class="thumbnail" for="id1">
<img src="http://thecodeplayer.com/uploads/media/3yiC6Yq.jpg" width="100"/>
</label>
<img src="http://thecodeplayer.com/uploads/media/3yiC6Yq.jpg"/>
<label class="next" for="id2">></label>
<input type="radio" name="slide_switch" id="id2" checked="checked"/>
<label class="thumbnail" for="id2">
<img src="http://thecodeplayer.com/uploads/media/40Ly3VB.jpg" width="100"/>
</label>
<img src="http://thecodeplayer.com/uploads/media/40Ly3VB.jpg"/>
<label class="previous" for="id1">></label>
<label class="next" for="id3">></label>
<input type="radio" name="slide_switch" id="id3"/>
<label class="thumbnail" for="id3">
<img src="http://thecodeplayer.com/uploads/media/00kih8g.jpg" width="100"/>
</label>
<img src="http://thecodeplayer.com/uploads/media/00kih8g.jpg"/>
<label class="previous" for="id2">></label>
<label class="next" for="id4">></label>
<input type="radio" name="slide_switch" id="id4"/>
<label class="thumbnail" for="id4">
<img src="http://thecodeplayer.com/uploads/media/2rT2vdx.jpg" width="100"/>
</label>
<img src="http://thecodeplayer.com/uploads/media/2rT2vdx.jpg"/>
<label class="next" for="id5">></label>
<label class="previous" for="id3">></label>
<input type="radio" name="slide_switch" id="id5"/>
<label class="thumbnail" for="id5">
<img src="http://thecodeplayer.com/uploads/media/8k3N3EL.jpg" width="100"/>
</label>
<img src="http://thecodeplayer.com/uploads/media/8k3N3EL.jpg"/>
<label class="previous" for="id4">></label>
</div>
The CSS code:
* { margin: 0; padding: 0 }
body { background: #ccc }
.slider {
width: 640px;
position: relative;
padding-top: 320px;
margin: 20px auto;
box-shadow: 0 10px 20px -5px rgba(0, 0, 0, 0.75);
}
.slider > img {
position: absolute;
left: 0; top: 0;
transition: all 0.5s;
display: block
}
.slider input[name='slide_switch'] {
display: none;
}
.slider label.next, .slider label.previous {
position: absolute;
left: 0; top: 0;
display: block;
font-size:3em;
opacity: 0.6;
cursor: pointer;
color: white;
}
.slider label.next { left: 560px; line-height: 320px }
.slider label.previous { left: 50px; line-height: 320px; transform: rotateY(180deg) }
.slider label.thumbnail {
margin: 18px 0 0 18px;
border: 3px solid #999;
float: left;
cursor: pointer;
transition: all 0.5s;
opacity: 0.6;
}
.slider label.thumbnail:hover { opacity: 0.8 }
.slider label.thumbnail img {
display: block;
}
.slider input[name='slide_switch']:checked + label.thumbnail {
border-color: #666;
opacity: 1;
}
.slider input[name='slide_switch'] ~ label.next,
.slider input[name='slide_switch'] ~ label.previous
{
z-index: -1
}
.slider input[name='slide_switch']:checked ~ label.next,
.slider input[name='slide_switch']:checked ~ label.previous {
z-index: 1
}
.slider input[name='slide_switch'] ~ img {
opacity: 0;
transform: scale(1.1);
}
.slider input[name='slide_switch']:checked + label.thumbnail + img {
opacity: 1;
transform: scale(1);
}
(Source)
This rule
.slider input[name='slide_switch']:checked ~ label.next,
.slider input[name='slide_switch']:checked ~ label.previous {
z-index: 1
}
will target all label.next/label.previous that comes after an input[name='slide_switch'], and not only the immediate one's up until next input[name='slide_switch'].
You either need to target each input[name='slide_switch'] specific label using their for attribute, or use nth-of-type
Updated based on a comment
Solution 1 - Preferred
Instead of changing the :checked rule above, wrap each group of input/image/thumb/arrow in a div and change this rule's .slider > img selector to slider > div > img
Updated fiddle
Stack snippet
* { margin: 0; padding: 0 }
body { background: #ccc }
.slider {
width: 640px;
position: relative;
padding-top: 320px;
margin: 20px auto;
box-shadow: 0 10px 20px -5px rgba(0, 0, 0, 0.75);
}
.slider > div > img {
position: absolute;
left: 0; top: 0;
transition: all 0.5s;
display: block
}
.slider input[name='slide_switch'] {
display: none;
}
.slider label.next, .slider label.previous {
position: absolute;
left: 0; top: 0;
display: block;
font-size:3em;
opacity: 0.6;
cursor: pointer;
color: white;
}
.slider label.next { left: 560px; line-height: 320px }
.slider label.previous { left: 50px; line-height: 320px; transform: rotateY(180deg) }
.slider label.thumbnail {
margin: 18px 0 0 18px;
border: 3px solid #999;
float: left;
cursor: pointer;
transition: all 0.5s;
opacity: 0.6;
}
.slider label.thumbnail:hover { opacity: 0.8 }
.slider label.thumbnail img {
display: block;
}
.slider input[name='slide_switch']:checked + label.thumbnail {
border-color: #666;
opacity: 1;
}
.slider input[name='slide_switch'] ~ label.next,
.slider input[name='slide_switch'] ~ label.previous
{
z-index: -1
}
.slider input[name='slide_switch']:checked ~ label.next,
.slider input[name='slide_switch']:checked ~ label.previous {
z-index: 1
}
.slider input[name='slide_switch'] ~ img {
opacity: 0;
transform: scale(1.1);
}
.slider input[name='slide_switch']:checked + label.thumbnail + img {
opacity: 1;
transform: scale(1);
}
<div class="slider">
<div>
<input type="radio" name="slide_switch" id="id1" />
<label class="thumbnail" for="id1">
<img src="http://thecodeplayer.com/uploads/media/3yiC6Yq.jpg" width="100" />
</label>
<img src="http://thecodeplayer.com/uploads/media/3yiC6Yq.jpg" />
<label class="next" for="id2">></label>
</div>
<div>
<input type="radio" name="slide_switch" id="id2" checked/>
<label class="thumbnail" for="id2">
<img src="http://thecodeplayer.com/uploads/media/40Ly3VB.jpg" width="100" />
</label>
<img src="http://thecodeplayer.com/uploads/media/40Ly3VB.jpg" />
<label class="previous" for="id1">></label>
<label class="next" for="id3">></label>
</div>
<div>
<input type="radio" name="slide_switch" id="id3" />
<label class="thumbnail" for="id3">
<img src="http://thecodeplayer.com/uploads/media/00kih8g.jpg" width="100" />
</label>
<img src="http://thecodeplayer.com/uploads/media/00kih8g.jpg" />
<label class="previous" for="id2">></label>
<label class="next" for="id4">></label>
</div>
<div>
<input type="radio" name="slide_switch" id="id4" />
<label class="thumbnail" for="id4">
<img src="http://thecodeplayer.com/uploads/media/2rT2vdx.jpg" width="100" />
</label>
<img src="http://thecodeplayer.com/uploads/media/2rT2vdx.jpg" />
<label class="next" for="id5">></label>
<label class="previous" for="id3">></label>
</div>
<div>
<input type="radio" name="slide_switch" id="id5" />
<label class="thumbnail" for="id5">
<img src="http://thecodeplayer.com/uploads/media/8k3N3EL.jpg" width="100" />
</label>
<img src="http://thecodeplayer.com/uploads/media/8k3N3EL.jpg" />
<label class="previous" for="id4">></label>
</div>
</div>
Solution 2
Replace this rule
.slider input[name='slide_switch']:checked ~ label.next,
.slider input[name='slide_switch']:checked ~ label.previous {
z-index: 1
}
with this
.slider input#id1:checked ~ label[for="id2"],
.slider input#id2:checked ~ label[for="id1"],
.slider input#id2:checked ~ label[for="id3"],
.slider input#id3:checked ~ label[for="id2"],
.slider input#id3:checked ~ label[for="id4"],
.slider input#id4:checked ~ label[for="id3"],
.slider input#id4:checked ~ label[for="id5"],
.slider input#id5:checked ~ label[for="id4"]
{
z-index: 1;
}
You aren't using the tilde selector correctly. All sibling elements after the left hand of the tilde will actually match.
https://stackoverflow.com/questions/10782054/what-does-the-tilde-squiggle-twiddle-css-selector-mean
So even though your code is setting the z-index to -1, that is getting overwritten in most cases by this (since this rule is more specific):
.slider input[name='slide_switch']:checked ~ label.next,
.slider input[name='slide_switch']:checked ~ label.previous {
z-index: 1;
}

How can I display the checkbox over the images for selection?

I want to display a checkbox for selection on the right bottom of every image..
How can i do something like this?
Please remember that clicking on image has a unique event(that i'll manage to do!) , but clicking on that check box should select/deselect that one?
This can be done with pure CSS, assuming you have fixed width and height for all images. The trick is setting absolute position for the checkbox then assign bottom and right to zero.
HTML sample:
<div class="container">
<img src="image1.jpg" />
<input type="checkbox" class="checkbox" id="check1" />
</div>
<div class="container">
<img src="image2.jpg" />
<input type="checkbox" class="checkbox" id="check2" />
</div>
CSS:
.container { position: relative; width: 100px; height: 100px; float: left; margin-left: 10px; }
.checkbox { position: absolute; bottom: 0px; right: 0px; }
Live test case.
As for click events, just apply click handler to each checkbox and it will work just fine.. see in this updated fiddle.
You can use a "label" tag that contains an "img" tag inside.
Here's an example of using an image as a checkbox and radio.
* {
font-family: Lato;
margin: 0;
padding: 0;
--transition: 0.15s;
--border-radius: 0.5rem;
--background: #ffc107;
--box-shadow: #ffc107;
}
.cont-bg {
min-height: 100vh;
background-image: radial-gradient(
circle farthest-corner at 7.2% 13.6%,
rgba(37, 249, 245, 1) 0%,
rgba(8, 70, 218, 1) 90%
);
padding: 1rem;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.cont-title {
color: white;
font-size: 1.25rem;
font-weight: 600;
margin-bottom: 1rem;
}
.cont-main {
display: flex;
flex-wrap: wrap;
align-content: center;
justify-content: center;
}
.cont-checkbox {
width: 150px;
height: 100px;
border-radius: var(--border-radius);
box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
background: white;
transition: transform var(--transition);
}
.cont-checkbox:first-of-type {
margin-bottom: 0.75rem;
margin-right: 0.75rem;
}
.cont-checkbox:active {
transform: scale(0.9);
}
input {
display: none;
}
input:checked + label {
opacity: 1;
box-shadow: 0 0 0 3px var(--background);
}
input:checked + label img {
-webkit-filter: none; /* Safari 6.0 - 9.0 */
filter: none;
}
input:checked + label .cover-checkbox {
opacity: 1;
transform: scale(1);
}
input:checked + label .cover-checkbox svg {
stroke-dashoffset: 0;
}
label {
display: inline-block;
cursor: pointer;
border-radius: var(--border-radius);
overflow: hidden;
width: 100%;
height: 100%;
position: relative;
opacity: 0.6;
}
label img {
width: 100%;
height: 70%;
object-fit: cover;
clip-path: polygon(0% 0%, 100% 0, 100% 81%, 50% 100%, 0 81%);
-webkit-filter: grayscale(100%); /* Safari 6.0 - 9.0 */
filter: grayscale(100%);
}
label .cover-checkbox {
position: absolute;
right: 5px;
top: 3px;
z-index: 1;
width: 20px;
height: 20px;
border-radius: 50%;
background: var(--box-shadow);
border: 2px solid #fff;
transition: transform var(--transition),
opacity calc(var(--transition) * 1.2) linear;
opacity: 0;
transform: scale(0);
}
label .cover-checkbox svg {
width: 13px;
height: 11px;
display: inline-block;
vertical-align: top;
fill: none;
margin: 5px 0 0 3px;
stroke: #fff;
stroke-width: 2;
stroke-linecap: round;
stroke-linejoin: round;
stroke-dasharray: 16px;
transition: stroke-dashoffset 0.4s ease var(--transition);
stroke-dashoffset: 16px;
}
label .info {
text-align: center;
margin-top: 0.2rem;
font-weight: 600;
font-size: 0.8rem;
}
<div class="cont-bg">
<div class="cont-title">Checkbox</div>
<div class="cont-main">
<div class="cont-checkbox">
<input type="checkbox" id="myCheckbox-1" />
<label for="myCheckbox-1">
<img
src="https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/2021-mazda-mx-5-miata-mmp-1-1593459650.jpg?crop=0.781xw:0.739xh;0.109xw,0.0968xh&resize=480:*"
/>
<span class="cover-checkbox">
<svg viewBox="0 0 12 10">
<polyline points="1.5 6 4.5 9 10.5 1"></polyline>
</svg>
</span>
<div class="info">Mazda MX-5 Miata</div>
</label>
</div>
<div class="cont-checkbox">
<input type="checkbox" id="myCheckbox-2" />
<label for="myCheckbox-2">
<img
src="https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/2020-chevrolet-corvette-c8-102-1571146873.jpg?crop=0.548xw:0.411xh;0.255xw,0.321xh&resize=980:*"
/>
<span class="cover-checkbox">
<svg viewBox="0 0 12 10">
<polyline points="1.5 6 4.5 9 10.5 1"></polyline>
</svg>
</span>
<div class="info">Toyota Supra</div>
</label>
</div>
</div>
<div class="cont-title">Radio</div>
<div class="cont-main">
<div class="cont-checkbox">
<input type="radio" name="myRadio" id="myRadio-1" />
<label for="myRadio-1">
<img
src="https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/2021-mazda-mx-5-miata-mmp-1-1593459650.jpg?crop=0.781xw:0.739xh;0.109xw,0.0968xh&resize=480:*"
/>
<span class="cover-checkbox">
<svg viewBox="0 0 12 10">
<polyline points="1.5 6 4.5 9 10.5 1"></polyline>
</svg>
</span>
<div class="info">Mazda MX-5 Miata</div>
</label>
</div>
<div class="cont-checkbox">
<input type="radio" name="myRadio" id="myRadio-2" />
<label for="myRadio-2">
<img
src="https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/2020-chevrolet-corvette-c8-102-1571146873.jpg?crop=0.548xw:0.411xh;0.255xw,0.321xh&resize=980:*"
/>
<span class="cover-checkbox">
<svg viewBox="0 0 12 10">
<polyline points="1.5 6 4.5 9 10.5 1"></polyline>
</svg>
</span>
<div class="info">Toyota Supra</div>
</label>
</div>
</div>
</div>
If only selecting/dis-selecting of the checkbox is your requirement then What I would suggest is as under :
Step 1: Place the image and the checkbox inside a block (may it be a div or table)
Step 2: Provide that block relative position with some specific height and width.
Step 3: For checkbox, give it absolute position and set the right and bottom gaps (based on your requirement).
For instance, the code should look like this
<div class="img_block">
<img src="image-path" alt="" />
<input type="checkbox" class="chkbox" />
</div>
<div class="img_block">
<img src="image-path" alt="" />
<input type="checkbox" class="chkbox" />
</div>
And the css for the same is
.img_block {position:relative; width:230px; margin-right:20px; margin-bottom:10px; height:30px;}
.chkbox {position:absolute; right:5px; bottom:3px;}
I hope this suits your requirement.
If it were me I would try usign jQuery for this.Lets pretend that each image is in each own div and the checkbo has an id of check:
$('div').click(function()
{
//you select the checkbox and ad the code to do what you want to it
('#check').
});