Вы можете установить свойство max-width
на изображении или свойство переполнения на контейнере div, в зависимости от того, хотите ли вы, чтобы изображение масштабировалось или было обрезано:
max-width:
.mainDiv {
max-width: 1200px;
margin: auto;
width: 95%;
}
.tempImage {
background: url(https://via.placeholder.com/1200x183);
height: 183px;
}
img {
max-width: 100%;
}
<div class="mainDiv">
<h2>This one works</h2>
<div class="tempImage"></div>
<h2>So does this one</h2>
<img src="https://via.placeholder.com/1200x183" alt="">
</div>
переполнение:
.mainDiv {
max-width: 1200px;
margin: auto;
width: 95%;
overflow: hidden;
}
.tempImage {
background: url(https://via.placeholder.com/1200x183);
height: 183px;
}
<div class="mainDiv">
<h2>This one works</h2>
<div class="tempImage"></div>
<h2>So does this one</h2>
<img src="https://via.placeholder.com/1200x183" alt="">
</div>