An alternative to do this would be to set the width of the banners as follows:
.banner-holder{
width:100%;
}
.carousel figure{
width:100%;
}
Or rather than define the css
, takes the width of the window directly window.innerWidth
for(var i = 0; i < bannersWidth.length; i++){
bannersWidth[i].style.width == window.innerWidth + "px";
}
*Note that the object Window does not own the property offsetWidth
, possibly that’s why it doesn’t work.
*It won’t work either screen.width
because it returns the width of the screen and according to the question you want the width of the browser.
Follow a functional example:
function AjustaLarguras() {
var bannersWidth = document.querySelectorAll(".banner-holder,.carousel,.figure");
for (var i = 0; i < bannersWidth.length; i++) {
bannersWidth[i].style.width = window.offsetWidth + "px";
}
}
.banner-holder {
height: 50px;
border: 1px solid red;
}
.carousel {
height: 50px;
border: 1px solid green;
}
.figure {
height: 50px;
border: 1px solid blue;
}
<body onload="AjustaLarguras()">
<div class="banner-holder">
</div>
<div class="carousel">
</div>
<div class="figure">
</div>
</body>
figure { max-width: 100% }
does not answer ?– Caio Felipe Pereira
I will not use max-width because I need to position several, one after the other, to a Carousel
– Murilo Melo