WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Background image width and height (2 posts)

  1. cableghost
    Member
    Posted 2 years ago #

    I'm trying to set a background image to a fill a div. Since the div surrounding the background image cannot be dynamic, I'm trying to fit the image within the div, whether it be to stretch it, or reduce it.

    Below is the functioning code I have to present the image. Every time I try resizing it via css, or style, it either does not appear, or it is tiled.

    <?php
    $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array( 5600,1000), false, '');
    ?>
    <div class="gad-box">
    <div style="background: url(<?php echo $src[0]; ?> ) !important; height:100%; width:100%;">

    CSS for main div:
    .gad-box{ float:left; height: 280px; width: 336px; margin: 0 7px 0 0; }

    Thanks for the help.

  2. cableghost
    Member
    Posted 2 years ago #

    Determined there is no way to 'crop' background images during load.

Topic Closed

This topic has been closed to new replies.

About this Topic