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 9154423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:25:31+00:00 2026-06-17T12:25:31+00:00

First post for me here. I’m using a div to crop thumbnail images all

  • 0

First post for me here.

I’m using a div to crop thumbnail images all in the same proportions (180wx170h). I’m getting stuck when dealing with portrait as well as landscape images. If am using this which is fine for portrait style images:

.crop img {max-height:170px; width:auto} 

.. and is fine for landscape style images:

.crop img {max-width:180px; height: auto;} is fine for landscape style images.  

So I basically want to crop the sides if landscape and top/bottom if portrait. Kind of like a prioritized max-height and max-width.

I know this could be done easily with PHP but I really only know CSS so that would be my first preference.

I need to maintain the aspect ratio of the image.

  • 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-06-17T12:25:31+00:00Added an answer on June 17, 2026 at 12:25 pm

    Edit 2019:

    If you want to keep <img> tags, please look into object-fit css property, support of it across browsers is quite good.

    And if you want to keep aspect ratio on width change, try padding-hack.


    As I understand you have blocks 180×170 px and you want to fill them completely with images. Try to move images to background and use background-size:cover.

    Demo http://jsfiddle.net/heuku/1/

    <div style="background-image:url(http://placekitten.com/100/200)"></div>
    <div style="background-image:url(http://placekitten.com/200/100)"></div>
    <div style="background-image:url(http://placekitten.com/200/200)"></div>
    
    div {
      width:180px;
      height:170px;
      background-repeat:no-repeat;
      background-size:cover;
    }
    

    Note that this solution not working in IE8 and below.

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

Sidebar

Related Questions

first post here as I'm stuck with my wonderful C++ function. The error I'm
First post here... I normally develop using PHP and Symfony with Propel and ActionScript
um, first post here, this place seems to be all over google and i
first post here ever so forgive me if I am totally ignorant of all
First post here, so I hope this is enough detail. I started using freebase-python
this is my first post here. I'm using an existing Flash widget but would
this is my first post here and i like to thank all the people
this is my first post here so I hope I provide all the right
My very first post here! I have been using this site for many years
This is my first post here, but I've using this site regularly to help

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.