Make image full width

时间:2016-12-20 作者:user6738171

I am trying to make the featured image full width in my wordpress theme. I want it so that when you go to the individual posts page the featured image is full width at the top. (similar to (http://www.fashionmumblr.com/2016/12/12-days-vlogmas-giveaways.html) Does anyone have any suggestions for how I could achieve this?

        add_image_size(\'banner-image\', 9999, 9999, true);

and css

.banner-image img {
width:100%;
}

Here is my single.php

<?php
get_header();
the_post_thumbnail(\'banner-image\');
if (have_posts()) :
while (have_posts()) : the_post(); ?>
<article class="post">

<?php wpb_set_post_views(get_the_ID()); ?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_content(); ?>
<?php comments_template(); ?>
</article>
<?php endwhile;
else :
echo \'<p>No content found</p>\';
endif;
get_footer();

?>

Here is my header.php

<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo(\'charset\'); ?>">
<meta name="viewport" content="width=device-width">
<title><?php bloginfo(\'name\'); ?></title>
<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
<div class="container">
<!-- site-header -->
<header class="site-header">
<h1><a href="<?php echo home_url(); ?>"><?php bloginfo(\'name\'); ?></a></h1>
<h5><?php bloginfo(\'description\'); ?></h5>


        <?php wp_nav_menu(array(
\'menu\' => \'Primary Menu Links\', 
\'container_id\' => \'cssmenu\', 
\'walker\' => new CSS_Menu_Walker()
)); ?>

    </header>
1 个回复
最合适的回答,由SO网友:JHoffmann 整理而成

使用以下CSS仅针对单个帖子上的横幅图像:

body.sinlge .size-banner-image {
    width:100%;
}
只有当您的<div class="container"> 元素的宽度不受限制,否则横幅将仅延伸到容器宽度。

相关推荐

Images with overlay

我有一些图片在一个容器中,我想添加一个覆盖和图标。这不是现成的,但我找到了一些有用的代码:HTML:<div class=\"main\"> <span class=\"featured\"><img src=\"http://joshrodg.com/IMG_001-258x258.jpg\" title=\"\" alt=\"\"></span> </div> CSS:.featured {