Dynamic width of the image in the slider (CSS)
I can't make the dynamic width of images in the website slider (HTML + CSS + JS). When opening the browser window, the width of the first slide is the full width of the window (as it should be), but if you stretch/expand the browser window, the width of the image does not change and subsequent slides go with the same width as when the page was initially opened in the browser. I tried width 100%, auto, inherit, and made different variations of object-fit, but it didn't bring any results. Be grateful for help.
#slider {
width: 100%;
max-width: 1920px;
height: -moz-calc(100vh - 100px);
height: -webkit-calc(100vh - 100px);
height: -o-calc(100vh - 100px);
position: relative;
display: block;
margin: 0px auto;
overflow: hidden;
border-radius: 3px;
}
#slider1 {
width: 100%;
max-width: 1920px;
height: -moz-calc(100vh - 100px);
height: -webkit-calc(100vh - 100px);
height: -o-calc(100vh - 100px);
position: absolute;
display: block;
}
.slider_items {
width: 100%;
max-width: 1920px;
height: -moz-calc(100vh - 100px);
height: -webkit-calc(100vh - 100px);
height: -o-calc(100vh - 100px);
}
.slider_info {
width: 100%;
height: 70px;
display: inline-block;
bottom: 90px;
position: relative;
background: rgba(104,204,204,.3);
z-index: 99;
}
.slider_img {
width: inherit;
max-width: 1920px;
height: -moz-calc(100vh - 100px);
height: -webkit-calc(100vh - 100px);
height: -o-calc(100vh - 100px);
}
<div id="slider">
<div id="slider_pager"></div>
<div id="slider1" align="center">
<div class="slider_items">
<img class="slider_img" src="//placehold.it/350x150"/>
<div class="slider_info">
<h2>Slide1 title</h2>
<p>This is the description for slide1 <a href="#">Learn more</a></p>
</div>
</div>
<div class="slider_items">
<img class="slider_img" src="//placehold.it/350x150"/>
<div class="slider_info">
<h2>Slide2 title</h2>
<p>This is the description for slide2 <a href="#">Learn more</a></p>
</div>
</div>
</div>
</div>
4
2 answers
FlexSlider to help you, it is initially adaptive
HTML:
<div class="flexslider">
<ul class="slides">
<li>
<img src="slide1.jpg" />
</li>
<li>
<img src="slide2.jpg" />
</li>
<li>
<img src="slide3.jpg" />
</li>
<li>
<img src="slide4.jpg" />
</li>
</ul>
</div>
JS:
$(window).load(function() {
$('.flexslider').flexslider({
animation: "slide"
});
});
2
Author: Vasin Yuriy, 2016-07-08 19:29:35
window.onresize = function(){ location.reload();}
And in CSS width:100%
, if I understand you correctly
-7
Author: Ivan, 2016-03-26 15:46:39