I have made an image slider that works fine until I try and make the images into links. I have tried several things but all come up with different problems.
For instance when I change
<img src="img/radish.jpg" alt="radish">
to
<a href ="radish.html"><img src="img/radish.jpg" alt="radish"></a>
The image dissapears this can be fixed from changing
.slider li input:checked ~ img{
opacity: 1;
visibility: visible;
z-index: 10;
}
To
.slider li input:checked ~ img a{
opacity: 1;
visibility: visible;
z-index: 10;
}
However the image is not a click-able link still again I have found a way to fix this by adding
.slider li input:checked ~ a{
position: absolute;
}
but after doing this my label goes from the bottom of the slider to above the slider which I just don't know how to fix.
Below is the HTML and CSS before attempting to change the images to links.If someone could help me find a way to make the images links without changing the positions of any elements I will be forever in your debt thanks Bashtoe
HTML
<ul class="slider">
<li>
<input type="radio" id="slide1" name="slide">
<label for="slide1"></label>
<img src="img/carrot.jpg" alt="carrot">
</li>
<li>
<input type="radio" id="slide2" name="slide" checked>
<label for="slide2"></label>
<img src="img/turnip.jpg" alt="turnip">
</li>
<li>
<input type="radio" id="slide3" name="slide">
<label for="slide3"></label>
<img src="img/radish.jpg" alt="radish">
</li>
<li>
<input type="radio" id="slide4" name="slide">
<label for="slide4"></label>
<img src="img/parsnip.jpg" alt ="parsnip">
</li>
<li>
<input type="radio" id="slide5" name="slide">
<label for="slide5"></label>
<img src="img/leek.jpg" alt="leek">
</li>
<li>
<input type="radio" id="slide6" name="slide">
<label for="slide6"></label>
<img src="img/onion.jpg" alt="onion">
</li>
</ul>
Relevant CSS
.slider{
height: 480px;
width: 1000px;
padding-bottom: 3.5em;
padding-top: 0.4em;
padding-left:6.2em;
margin:0 auto;
}
.slider li{
list-style: none;
position: absolute;
/*Creates a two bordered effect*/
-webkit-box-shadow: 0px 0px 0px 3px #3C7F1E, 0px 0px 0px 6px #4C1F0A;
-moz-box-shadow: 0px 0px 0px 3px #3C7F1E, 0px 0px 0px 6px #4C1F0A;
box-shadow: 0px 0px 0px 3px #3C7F1E, 0px 0px 0px 6px #4C1F0A;
}
.slider img{
height: 480px;
width: 800px;
vertical-align: top;
}
.slider input{
display:none;
}
.slider label{
background-color:#3C7F1E;
bottom: 8px;
cursor: pointer;
display: block;
height: 16px;
position: absolute;
width: 16px;
z-index: 10;
border: 1px solid gray;
box-shadow: inset 0px 0px 0px 2px white; /*Gives the button an outer ring */
-webkit-box-shadow: inset 0px 0px 0px 2px white; /*cross browser compatibility */
-moz-box-shadow: inset 0px 0px 0px 2px white;
-o-box-shadow: inset 0px 0px 0px 2px white;
/*makes the buttons circular */
-webkit-border-radius: 8px;
-moz-border-radius: 8px;
-o-border-radius: 8px;
border-radius: 8px;
}
.slider li input:checked ~ label{ /*Changes the color of the checked box */
background: #4C1F0A;
}
/*Sets the distance from the left for the corrisponding button */
.slider li:nth-child(1) label{
left: 16px;
}
.slider li:nth-child(2) label{
left: 64px;
}
.slider li:nth-child(3) label{
left: 112px;
}
.slider li:nth-child(4) label{
left: 160px;
}
.slider li:nth-child(5) label{
left: 208px;
}
.slider li:nth-child(6) label{
left: 256px;
}
/* Hides the images*/
.slider img{
opacity: 0;
visibility: hidden;
}
/*Displays the images when radio buttons are checked, note that the first starts as checked in the html*/
.slider li input:checked ~ img{
opacity: 1;
visibility: visible;
z-index: 10;
}