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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:20:53+00:00 2026-05-20T10:20:53+00:00

<html> <head> <style type=text/css> canvas { width: 100%; height: 100%; } </style> <script> function

  • 0
<html>
<head>

<style type="text/css">
    canvas { width: 100%; height: 100%; }
</style>

<script>
    function init() {
        canvas = document.getElementById('canvas');
        alert(canvas.width + "x" + canvas.height);
    }
</script>

</head>

<body onload="init();">
    <canvas id="canvas"> </canvas>
</body>

</html>

This code displays the size before it has been styled. I need the size after it has been styles. How can I do this?

  • 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-20T10:20:54+00:00Added an answer on May 20, 2026 at 10:20 am

    Your problem stems from the difference between the intrinsic dimensions of the canvas and the number of CSS pixels it takes up. The HTML specification says:

    The intrinsic dimensions of the canvas
    element equal the size of the
    coordinate space, with the numbers
    interpreted in CSS pixels. However,
    the element can be sized arbitrarily
    by a style sheet. During rendering,
    the image is scaled to fit this layout
    size.

    What this means is that your canvas defaults to a drawing space of 300x150px in terms of the coordinates used to draw images. However, your CSS rules will stretch the canvas to the size of the page (at least with regard to width). There will still only be 300px wide to logically draw on, but it will be scaled and physically rendered on whatever 100% of the page width corresponds to.

    Anyway, the width and height properties correspond to the intrinsic drawing dimensions of the canvas. Since you care about the CSS size, you can use window.getComputedStyle.

    http://jsfiddle.net/3DDsX/

    <head>
      <style>
        canvas { width: 100%; height: 100% }
      </style>
      <script>
        function init() {
          var canvas = document.getElementById('canvas');
          var style = getComputedStyle(canvas);
          alert(style.width + ' x ' + style.height);
        }
      </script>
    </head>
    <body onload="init();">
      <canvas id="canvas"></canvas>
    </body>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

<html> <head> <style type=text/css> div { border:1px solid #000; min-width: 50%; } </style> </head>
I have this code <html> <head> <style type=text/css> .frame {width: 50em; border: 1px solid
Code and preview: <html> <head> <title>Testing some CSS</title> <style type=text/css> .dDay { font-size:205% }
I have the following code <html> <head> <title>Test</title> <style type=text/css> <!-- body,td,th { color:
I am using the following html page: <html> <head> <title>AJAX Example</title> <meta http-equiv=Content-Type content=text/html;
Code: <html xmlns=http://www.w3.org/1999/xhtml> <head> <title>Unusual Array Lengths!</title> <script type=text/javascript> var arrayList = new Array();
I have this input text: <html><head><meta http-equiv=content-type content=text/html; charset=utf-8></head><body><table cellspacing=0 cellpadding=0 border=0 align=center width=603>
Here's the code I currently have. <!DOCTYPE html> <html> <head> <meta http-equiv=Content-Type content=text/html; charset=utf-8/>
I have the following HTML <html xmlns=http://www.w3.org/1999/xhtml > <head runat=server> <title></title> <style> .box {
I am using this HTML <html> <head> <Title>EBAY Search</title> </head> <script language=JavaScript src=ajaxlib.js></script> <body>

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.