如何拉伸图像响应以填充整个屏幕
我想知道如何将图像扩展到标记为黑色的部分([)。这是我的代码(我正在尝试使其响应迅速):
body {
background: #aeddd5;
}
.main {
max-width: 900px;
margin: auto;
}
img {
width: 100%;
height: 100%;
}
<body>
<div class="main">
<img src="./img/cf60903b8674148b9ab6ba194833fd2f_page-0001.jpg">
</div>
</body>
我拥有的
我想拥有这样的东西:
I want to know how can I extend the image to the part ([) marked in black. This is my code (I'm trying to make it responsive):
body {
background: #aeddd5;
}
.main {
max-width: 900px;
margin: auto;
}
img {
width: 100%;
height: 100%;
}
<body>
<div class="main">
<img src="./img/cf60903b8674148b9ab6ba194833fd2f_page-0001.jpg">
</div>
</body>
What I have
I want to have something like this:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用
object> object-fit < /code>
属性,添加
display:block
到图像中,以消除图像留下的多余空间,用于内联元素并声明大小用VH
和vw
You can stretch the image with the
object-fit
property, adddisplay: block
to the image for eliminate the excess space left by the images for being inline elements and declared a size coverting all the page with the relative length unitsvh
andvw
似乎您想为所有屏幕视图拉伸图像。
Seems like you want to stretch the image for all screen views.
更改
高度:100%
<代码>高度:100VH 并添加object-fit:cover
Change
height:100%
toheight:100vh
and addobject-fit:cover
html: -
我想这应该为您解决。我只是为水上颜色做了另一个划分,然后将身体颜色更改为黑色。添加了一些填充&amp;颜色到图像背景。
HTML:-
I guess this should work out for you. I just made another division for the aqua color and changed the body color to black. Added some padding & color to image background.