Skip to content

Instantly share code, notes, and snippets.

@victorwyee
Created April 19, 2020 21:45
Show Gist options
  • Select an option

  • Save victorwyee/84eee556ef12d239025910b60c48ee55 to your computer and use it in GitHub Desktop.

Select an option

Save victorwyee/84eee556ef12d239025910b60c48ee55 to your computer and use it in GitHub Desktop.
Setting a viewport height without stretching a featured image. #wordpress
<?php if ( has_post_thumbnail() && ! post_password_required() ) : ?>
<div class="featured-image" style='background-image: url(" <?= get_the_post_thumbnail_url(get_the_ID(), 'full'); ?>");'></div>
<?php endif; ?>
.featured-image img {
width: 100%;
}
.featured-image {
position: relative;
min-height: 30rem;
height: 75vh;
max-width: 1600px;
margin-left: auto;
margin-right: auto;
margin-top: 1em;
background-position: center center;
background-repeat: no-repeat;
background-size: cover;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment