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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:36:27+00:00 2026-06-08T04:36:27+00:00

Given any arbitrary image, I want to crop a square from the center of

  • 0

Given any arbitrary image, I want to crop a square from the center of the image and display it within a given square.

This question is similar to this: CSS Display an Image Resized and Cropped, but I don’t know the size of the image so I can’t use set margins.

  • 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-08T04:36:29+00:00Added an answer on June 8, 2026 at 4:36 am

    One solution is to use a background image centered within an element sized to the cropped dimensions.


    Basic example

    .center-cropped {
      width: 100px;
      height: 100px;
      background-position: center center;
      background-repeat: no-repeat;
    }
    <div class="center-cropped" 
         style="background-image: url('https://via.placeholder.com/200');">
    </div>

    Example with img tag

    This version retains the img tag so that we do not lose the ability to drag or right-click to save the image. Credit to Parker Bennett for the opacity trick.

    .center-cropped {
      width: 100px;
      height: 100px;
      background-position: center center;
      background-repeat: no-repeat;
      overflow: hidden;
    }
    
    /* Set the image to fill its parent and make transparent */
    .center-cropped img {
      min-height: 100%;
      min-width: 100%;
      /* IE 8 */
      -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
      /* IE 5-7 */
      filter: alpha(opacity=0);
      /* modern browsers */
      opacity: 0;
    }
    <div class="center-cropped" 
         style="background-image: url('https://via.placeholder.com/200');">
      <img src="https://via.placeholder.com/200" />
    </div>

    object-fit/-position

    See supported browsers.

    The CSS3 Images specification defines the object-fit and object-position properties which together allow for greater control over the scale and position of the image content of an img element. With these, it will be possible to achieve the desired effect:

    .center-cropped {
      object-fit: none; /* Do not scale the image */
      object-position: center; /* Center the image within the element */
      height: 100px;
      width: 100px;
    }
    <img class="center-cropped" src="https://via.placeholder.com/200" />
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to print in the screen this, given any number like 12: 0+12
For any given file data size, I want to be able to resize (or
For any given type i want to know its default value. In C#, there
A similar question was asked here in storing information in a given html element.
Given any arbitrary, one-line string, my goal is to render it into a bitmap
I recognize there is a similar question on here, from a fellow who wanted
Question Using XSLT 1.0, given a string with arbitrary characters how can I get
given any number, what's the best way to determine it is even? how many
Given any iterable, for example: ABCDEF Treating it almost like a numeral system as
Given any two sequences/vectors of M real numbers, I can easily compute their closeness

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.