我在将类添加到wordpress元素时遇到困难。我想将object-fit:cover元素添加到Wordpress函数中,但是我遇到了麻烦。

<!--    Row     -->
<article class="col-4">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('category-thumbnail'); ?></a>
</article>


我正在尝试通过CSS直接将object-fit:cover添加到img中,但是并没有影响它。完全感到困惑,因为它受宽度:100%和高度:自动影响。

.col-4 img{
width: 100%;
height: auto;
object-fit: cover;
}


我试过采用宽度和自动关闭功能,只是使用了object-fit:封面,但是它仍然没有在页面上生效。

在此先感谢您的帮助。

最佳答案

采用

.col-4 img{
  width: 100%;
  height: 200px; // height should be mentioned so that image can cover that place
  object-fit: cover; // Image will fill the 200px space
}


对于object-fit: cover,应提及高度,以便图像可以覆盖该高度。

我建议您使用背景图片而不是object-fit cover。请检查http://caniuse.com/#feat=object-fit与其他浏览器的兼容性。

有关如何使用背景尺寸封面的资料

https://css-tricks.com/perfect-full-page-background-image/

关于php - 向Wordpress函数添加类,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39836727/

10-11 22:34
查看更多