#myCarousel img{ width: 100%; height: 100%; object-fit: cover; } ...
<script> $(function () { function reinitSize() { var window_h = $(window).height(); var window_w = $(window).width(); var main_h = window_h - 80; if (window_w > 960) { $("#myCarousel img").css({ width: "auto", height: main_h + "px", margin:"0 auto" }); } } reinitSize(); $(window).resize(function () { reinitSize(); }); }) </script>
#myCarousel img{ width: 100%; height: 100%; object-fit: cover; }