我正在尝试在wordpress中构建主题, 但无法确定调整浏览器窗口大小时如何调整背景图片的大小。当我获取图像并将其设置为”完整”或其他任何预设大小时, 我不会调整大小:
在我的首页-php中:
<?php
// check if the post or page has a Featured Image assigned to it.
if ( has_post_thumbnail() ) {
// the_post_thumbnail();
$backgroundImg = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' );?>
<header id="hero" style="background: url('<?php echo $backgroundImg[0]; ?>') no-repeat center center fixed;"></header>
<?php }
?>
在我的css文件中:
header {
max-width: 100vw;
height: 95vh;
background-size: cover;
}
它只是保持不变。.非常感谢你的帮助!
#1
有一种更简单的方法来获取帖子的缩略图网址。另外, 最好在style属性中设置background-image属性:
<?php
// check if the post or page has a Featured Image assigned to it.
if ( has_post_thumbnail() ) {
// the_post_thumbnail();
$backgroundImg = get_the_post_thumbnail_url($post->ID, 'full'); ?>
<header id="hero" style="background-image: url('<?= $backgroundImg; ?>');"></header>
<?php }
?>
&CSS应该是:
header {
max-width: 100vw;
height: 95vh;
background-size: cover;
background-repeat: no-repeat;
background-position: center;
background-attachment: fixed;
}
评论前必须登录!
注册