html - 制作特色图片背景图片

标签 html css wordpress background background-image

在我的 wordpress 帖子上,我想在页面顶部添加全宽的帖子缩略图。我希望它覆盖页面的整个宽度,并且当页面变大时图像裁剪或放大。(类似于 https://www.inthefrow.com/2016/10/3-amazing-places-eat-mykonos.html )我下面的代码是一个正在进行的工作。它可以使图片成为背景图片,但不是全宽。它只会是图片的宽度。我将不胜感激任何帮助。提前致谢。

样式.php

<?php
get_header();
if (have_posts()) :
while (have_posts()) : the_post(); ?>
<article class="post">
    
    
        <?php $featuredImage = wp_get_attachment_url( get_post_thumbnail_id($post->ID), 'full' ); ?>
<div class="banner" style="background:url(<?php echo $featuredImage; ?>) no-repeat;"></div>
    
    
    
<?php wpb_set_post_views(get_the_ID()); ?>    
    <div class="post-info">    
    <h1 class="post-title"><?php the_title(); ?></h1>
   <h2 class="post-date"><?php echo strip_tags(get_the_term_list( $post->ID, 'location', 'Location: ', ', ', ' • ' ));?><?php the_date('F m, Y'); ?></h2>

    </div>
    <div class="post-content"><?php the_content(); ?></div>
    <div id="wrapper-footer"><div class="post-footer"><h1 class="post-footer-comment"><?php comments_popup_link ('No Comments', '1 Comment', '% Comments', 'post-footer-comment-count', 'none'); ?></h1><div class="share"><span>share</span> <?php get_template_part( 'share-buttons-post' ); ?></div></div>
        <div class="post-footer-bloglovin"><h1>never miss a post</h1><h2><a href="#">follow by email'</a></h2></div></div>
 <?php get_template_part( 'prevandnextpost' ); ?>
     <?php get_template_part( 'related-posts' ); ?>

<?php comments_template(); ?>
</article>
<?php endwhile;
else :
echo '<p>No content found</p>';
endif;
get_footer();
 
?>

CSS

.banner {
      max-width: 100%;
    width:100%;
        height:700px;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-attachment: fixed;
}

最佳答案

background-size: cover;

会做

关于html - 制作特色图片背景图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41522657/

相关文章:

javascript - 搜索结果应出现在 3 个字符之后

javascript - WordPress REST API 与 Vue.js - 显示 ajax 响应,数组未更新

css - 侧边栏在较小的屏幕上位于底部

javascript - 当通过直接输入或按钮更改输入值时突出显示一行

html - 如何在带阴影的表格上制作三 Angular 形?

jquery - 无法仅在数据表中的灰色行中更改 td 的背景颜色

html - 为什么我的 html 表单的密码输入字段有浅蓝色背景?

php - 如何在 wordpress 画廊弹出窗口中插入描述?

html - CSS二级下拉菜单消失

javascript - 无法将内部图像放入此 ReactJS 应用程序的父容器中