I have the following structure:
<div class="slideShow">
<div class="boxSlide">
<div class="imagens">
<img src="_imgs/_slideShow/1.png" />
<img src="_imgs/_slideShow/2.png" />
<img src="_imgs/_slideShow/3.png" />
</div>
<div class="anterior">
<span class="setaSpan"><</span>
<span class="boxSpan"></span>
</div>
<div class="proximo">
<span class="setaSpan">></span>
<span class="boxSpan"></span>
</div>
</div>
<div class="contador">
<span class="contaSlide">1</span>
<span class="contaSlide">2</span>
<span class="contaSlide">3</span>
</div>
</div>
TESTE
I would like to know if there is a way to make the height of div.slideShow
automatically adjusted to the height of the div's of its interior.
The idea here is for the browser to be adjusted (screen sizes) and the ratio stays the same.
Before div.slideShow
, only body
exists.
What I want to do is that, as the screen is being resized, or by pulling the broads of the browser or even through pre-set screens (nb's, tablet's, cell phones, etc ...) ), the height of the div.slideShow
, is adjusted to the height of your inner content that is already being resized correctly.
However, if I give fixed height to div.slideShow
, when the images decrease in size, I will have problems.
div.img
I have a imagem
with 300px
of height and resolve to change to another of 400px
of height or even 200px
. Keeping fixed height in div.slideShow
, I'll have problems. Hence the need for automatic adjustment .
How do I solve this problem?
Below the code running:
$(document).ready(function(e) {
quantasImagens = $("div.slideShow div.boxSlide div.imagens img").length-1;
contador = 0;
$("div.slideShow div.boxSlide div.anterior").click(function() {
contador = contador==quantasImagens ? -1 : contador;
contador++;
$("div.slideShow div.boxSlide div.imagens img").css("opacity",0);
$("div.slideShow div.boxSlide div.imagens img").eq(contador).css("opacity",1);
});
$("div.slideShow div.boxSlide div.proximo").click(function() {
contador = contador==0 ? quantasImagens+1 : contador;
contador--;
$("div.slideShow div.boxSlide div.imagens img").css("opacity",0);
$("div.slideShow div.boxSlide div.imagens img").eq(contador).css("opacity",1);
});
$("div.slideShow div.contador span.contaSlide").click(function() {
index = $(this).index();
$("div.slideShow div.boxSlide div.imagens img").css("opacity",0);
$("div.slideShow div.boxSlide div.imagens img").eq(index).css("opacity",1);
});
});
* {
margin:0;
padding:0;
}
div.slideShow {
position: relative;
width: 100%;
height:300px;
}
div.slideShow div.boxSlide,
div.slideShow div.contador {
position: relative;
display: block;
width: 100%;
}
div.slideShow div.boxSlide{
height:277px;
}
div.slideShow div.boxSlide div.imagens img {
position: absolute;
left: 0;
top: 0;
opacity: 0;
width: 100%;
}
div.slideShow div.boxSlide div.imagens img:first-child {
opacity: 1;
}
div.slideShow div.boxSlide div.anterior,
div.slideShow div.boxSlide div.proximo {
position: absolute;
display: block;
top: 100px;
}
div.slideShow div.boxSlide div.anterior {
left: 100px;
}
div.slideShow div.boxSlide div.proximo {
right: 100px;
}
div.slideShow div.boxSlide div.anterior span,
div.slideShow div.boxSlide div.proximo span {
position: absolute;
display: block;
width: 30px;
height: 30px;
}
div.slideShow div.boxSlide div.anterior span.boxSpan,
div.slideShow div.boxSlide div.proximo span.boxSpan {
background-color: rgb(200,200,200);
opacity: .5;
z-index: 1;
}
div.slideShow div.boxSlide div.anterior span.setaSpan,
div.slideShow div.boxSlide div.proximo span.setaSpan {
line-height: 30px;
text-align: center;
font-weight: bolder;
cursor: pointer;
z-index: 2;
}
div.slideShow div.boxSlide div span.setaSpan:hover + span.boxSpan {
opacity: 1;
}
div.slideShow div.contador {
/*top:240px;*/
background-color:rgba(240,240,240,.5);
}
div.slideShow div.contador span.contaSlide {
display: inline-block;
width: 30px;
height: 30px;
line-height: 30px;
text-align: center;
background-color: rgb(200,200,200);
cursor: pointer;
opacity: .5;
}
div.slideShow div.contador span.contaSlide:hover {
opacity: 1;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script><divclass="slideShow">
<div class="boxSlide">
<div class="imagens">
<img src="http://hotplateprensas.com.br/estilos/_imgs/_slideShow/1.png"/><imgsrc="http://hotplateprensas.com.br/estilos/_imgs/_slideShow/2.png" />
<img src="http://hotplateprensas.com.br/estilos/_imgs/_slideShow/3.png"/></div><divclass="anterior">
<span class="setaSpan"><</span>
<span class="boxSpan"></span>
</div>
<div class="proximo">
<span class="setaSpan">></span>
<span class="boxSpan"></span>
</div>
</div>
<div class="contador">
<span class="contaSlide">1</span>
<span class="contaSlide">2</span>
<span class="contaSlide">3</span>
</div>
</div>
oi