[英]Render CSS background-image in div for responsive view
I need some help with one of the web-page I am working on.我需要一些有关我正在处理的网页的帮助。 I have a div tag <div class="picContainer"></div>
in my HTML page, and below is the CSS class for the same.我的 HTML 页面中有一个 div 标签<div class="picContainer"></div>
,下面是相同的 CSS 类。
.picContainer{
position: relative;
background-image: url("Image.jpg");
height: 74%;
width: 30%;
left: 5%;
bottom: 2%;
box-shadow: 0 0 8px 8px #FAF9F6 inset;
background-size: cover;
}
This works perfectly fine when I view it on my laptop, but when tried to check the web-page on a Responsive Design View on firefox (ctrl-shift-m), the image gets cropped unlike how it's displayed on a laptop browser.当我在笔记本电脑上查看它时,这工作得很好,但是当尝试在 firefox (ctrl-shift-m) 上的响应式设计视图上检查网页时,图像被裁剪,与在笔记本电脑浏览器上的显示方式不同。 Is there any way to view the image on a mobile browser as exactly how it's displayed on the regular laptop browser?有没有办法在移动浏览器上查看图像,就像它在常规笔记本电脑浏览器上的显示方式一样?
You can change the background-image size, position and other properties specifically for mobile/tablet view by declaring responsive @media queries.您可以通过声明响应式@media 查询来更改背景图像大小、位置和其他专门针对移动/平板电脑视图的属性。
@media screen and (max-width: 662px) {
.picContainer{
width: auto;
background-size: contain;
}
}
Note* ^ You can adjust, change or add other style properties to suit your needs more.注意* ^ 您可以调整、更改或添加其他样式属性以更适合您的需要。 The screen size can also be changed to the screen size and also min-width rather than max屏幕大小也可以更改为屏幕大小和 min-width 而不是 max
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.