[英]Fullscreen image width in img-tag
I'm using PHP snippet to add a simple image to top of my page, and now I'm trying to have it fullscreen (edge to edge).我正在使用 PHP 代码段将一个简单的图像添加到我的页面顶部,现在我试图让它全屏显示(边缘到边缘)。
Yet no matter what CSS I try, it never seems to work.然而,无论我尝试什么 CSS,它似乎都不起作用。
function add_custom_content(){ ?>
<?php if ( is_home() ) : ?>
<div class="custom-content x-container max width headerhero">
<img src="...x.jpg" alt="X.com" />
</div>
<?php endif; ?>
<?php }
add_action('x_before_view_global__index', 'add_custom_content');
And CSS is following: CSS如下:
.headerhero {
min-height:100%;
min-width:100%;
height:auto;
width:auto;
margin:auto;
object-fit: cover;
}
From what you're showing us your image has a width
and height
of auto
.从您向我们展示的内容来看,您的图像的width
和height
为auto
。 Apply to your image width: 100vw
and height: 100vh
.适用于您的图像width: 100vw
和height: 100vh
。 See example below请参阅下面的示例
body, div { margin: 0; padding: 0; } img { width: 100vw; height: 100vh; object-fit: cover; }
<div> <img src="https://picsum.photos/2000" alt="a random image"> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.