Created
April 19, 2020 21:45
-
-
Save victorwyee/84eee556ef12d239025910b60c48ee55 to your computer and use it in GitHub Desktop.
Setting a viewport height without stretching a featured image. #wordpress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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; ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .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