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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:30:52+00:00 2026-05-20T18:30:52+00:00

I want a background image that automatically fits the div size. I have several

  • 0

I want a background image that automatically fits the div size.

I have several div of the same class, each with different dimensions, is it possible to set the width and the height of the image, exactly to the dimension of the div ?

Do you think is better to use img or background-image?

P.S I don’t know if is it possible to set the dimension of the background image, of course is possible for the tag img, but if I use the tag img the image is separated from the content (it dosen’t overlap as a background)

  • 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-20T18:30:52+00:00Added an answer on May 20, 2026 at 6:30 pm

    Personally if you’re going to modify things in this way, I think using img is better.

    You can literally just set the height and width of the div if that’s what you want.

    <div class="box"><img src="Path/to/image.png"/></div>
    

    and then the CSS would be something like this:

    .box {
         height: 300px;
         width: 300px;
    }
    
    .box img {
         height: 300px;
         width: 300px;
    }
    

    That’s one way of doing it anyway. You could also set it so that the height is 100% the size of the div, but the width is set to auto so that it scales with it. That way the image won’t distort. Like this:

    .box img {
         height: 300px;
         width: auto;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have many div's with the same background image and i want change this
I want to have a CSS div that has a background image (the full
I have a background image that I want to repeat across (repeat-x) however when
I have a header that has a css background image that I want to
I have a image that I want to display a DIV on the bottom
I have an image that I want to use as the background for every
I have a css background image that I want in front of my img
I have a background image that I want to show after the top header.
In my app, I want to have a single background image that I use
Basically I have a div that I want the background to be transparent. <div

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.