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

  • Home
  • SEARCH
  • 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 7572225
In Process

The Archive Base Latest Questions

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

I am making a chessboard in javascript. The chessboard’s squares (buttons) were originally designed

  • 0

I am making a chessboard in javascript. The chessboard’s squares (buttons) were originally designed to be 60px by 60px, but now they are 40px by 40px.

    button 
    {
      width:40px; 
      height:40px; 
      border: 0
    }

However, some of the pieces that were designed for this earlier chessboard are still 60px by 60px. Is there any way in Javascript to make the images shrink proportionally to fit the square size? Currently, the images fit the square size, but do not shrink, so when I say,

    square.style.backgroundImage = imgLink; // square is the button, imgLink is "WhiteKing.jpg" for example.

I get pieces like this –

enter image description here

If the WhiteKing.jpg had shrunk proportionally, it would have fit nicely. Is there a way to do this in Javascript? Any help would be really appreciated.

  • 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-30T15:52:21+00:00Added an answer on May 30, 2026 at 3:52 pm

    Most modern browsers have support for CSS background-image options like background-size, so you may really use something like this:

    button{
      width:40px; 
      height:40px; 
      border: 0;
      background-size: 100%; /* To fill the dimensions of container (button), or */
      background-size: 40px auto; /* to specify dimensions explicitly */
    }
    

    Of course you can use that in JavaScript too (but it’s better to add it to already existing CSS for button):

    square.style.backgroundSize = '100%';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Making good progress on rails now, but hit a snag on heroku deployment. After
Making a simple map app, plan on adding buttons to mark specific locations But
Making a winform in C#,there are several buttons, Click the button to achieve the
Making a mobile friendly site, I have a single field and a submit button.
for a school project, I am making a chessboard in java. there were certain
making an infinite loop in javascript, and jQuery... this is my current code: $(#bg2).css({opacity:
I'm trying to make a program that goes through all squares of a chessboard
Im making a game in Java with a few other people but we are
Im making a PyQt4 app which calls Imagemagick and ffmpeg, but it takes too
Making a link with javascript:void(0) violate the W3C standard. I need to have a

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.