Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7414613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:08:07+00:00 2026-05-29T07:08:07+00:00

So I’m designing a WordPress theme and I have four divs (380×400) that I’m

  • 0

So I’m designing a WordPress theme and I have four divs (380×400) that I’m using thumbnails from the posts to fill as a background, the problem is, if the picture is landscape it leaves a gap at the bottom so I can’t use width:100% in the CSS, same problem with the height on a portrait image if I use height:100%.

What I was looking to do was to assign a width property of 100% if the height of the images is greater than the width(e.g. style.width='100%') and the height if the width is greater than the height. I’m looking for simplicity, I don’t mind using a jQuery solution but I’m really not familiar with jQuery. I also have no problem if the image is cropped off the edges just so long as the aspect ratio remains intact.

Attached is the Screenshot of the situation I’m describing.

Here’s the relevant code:

    <?php $thumbnail = '';
      $post_image_id = get_post_thumbnail_id($post_to_use->ID);
      if ($post_image_id) {
        $thumbnail = wp_get_attachment_image_src( $post_image_id, 'post-thumbnail', false);
        if ($thumbnail) (string)$thumbnail = $thumbnail[0];
        }
      if (!empty($thumbnail)) { ?>
<div class="item" id="post-<?php the_ID(); ?>">
   <img class="background" src="<?php echo $thumbnail; ?>" onload="changeWidth(this);">
<div class="date">
<?php the_date(); ?>
</div>

CSS:

.item, .no-thumbnail{
  width:380px;
  height:400px;
  margin:5px 0px;
  border:1px solid black;
  float:left;
  position:relative;
  margin:5px;
  display:inline;

}

.item img.background{
  position:absolute;
  left:0px;
  z-index:-500;
  width:150%;
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T07:08:09+00:00Added an answer on May 29, 2026 at 7:08 am

    Since you display thumbnails and text in a grid, the both good and easy way out is to make all the thumbnails the same size. You can and either trim the photos when you generate the thumbnails, or hide the rest with css. This will make your grid look cleaner and it is easier on the eyes if text and photos all line up.

    If you still want to show the entire thumbnail, you could use CSS/javascript/jQuery to show it when hovering over the “fixed size” thumbnail in the grid.

    Edit: created an example to show clipping centered thumbnails of different orientation/aspect ratios. All it takes is a container (mainly to set the width of the gallery), and <a href="..." style="background-image: url(...);"></a> to both show the thumbnail and provide a link for the full photo.

    I didn’t include title nor photographer in this example. The <a /> tag acts as a container – should be possible to add text within it and then position it as needed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to
I have a bunch of posts stored in text files formatted in yaml/textile (from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.