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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:29:36+00:00 2026-05-25T20:29:36+00:00

I have this canvas: <canvas id=game width=280 height=280></canvas> The css styles the canvas via:

  • 0

I have this canvas:

<canvas id="game" width="280" height="280"></canvas>

The css styles the canvas via:

canvas
{
    width: inherit;
    height: 280px;
}

As the width can change, the canvas distorts the drawing. I need to know how to compensate for this. Anyone who can help me?

  • 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-25T20:29:37+00:00Added an answer on May 25, 2026 at 8:29 pm

    This is the same problem that the Mozilla Bespin team ran into. (back when they were using Canvas, before it merged with Ace)

    Don’t give the Canvas any CSS width/height rules. Doing so usually ends up as a pain. Put the Canvas in a Div that only has a single thing in it (the canvas itself)

    As the canvas-parent div changes size, change the size of the canvas (canvas.width and canvas.height) to match the size of the div.

    Since most browsers do not fire an event when a div changes size, you’ll simply have to check, say, every half second with a timer to see if the div has changed size. If it has, then you resize the canvas accordingly.

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

Sidebar

Related Questions

Here's my problem - I have some code like this: <mx:Canvas width=300 height=300> <mx:Button
I have this source code: var Game = function() { var canvas = document.getElementById('world');
I have this: <Canvas x:Name=LayoutRoot KeyDown=LayoutRoot_KeyDown> </Canvas> In a newly-minted Ag 3 application in
I have a main canvas 'blackboard' in a panel, this canvas has itself several
I have a MyCanvas class that extends JComponent. On this canvas I have drawn
I have designed this gui in netBeans which has a canvas , a couple
I have only this in my mxml source code: <?xml version=1.0 encoding=utf-8?> <mx:Canvas xmlns:mx=http://www.adobe.com/2006/mxml
I have a Grid inside a Canvas defined like this: <Canvas x:Name=outerCanvas> <Grid Grid.Row=1
This is the required behaviour: I have various controls present on the canvas e.g.
How can I construct this scenario? I want to build a game where the

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.