JSFiddle - React, Tailwind, and code Playground
HTML
<div id="container">
<canvas id="canvas"></canvas>
<div>something else...</div>
</div>
CSS
#container {
border: 1px solid blue;
width: 100%;
display: flex;
}
#canvas {
border: 1px solid red;
flex-grow: 1;
}
JavaScript
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
setInterval(function() {
var computed = getComputedStyle(canvas);
var w = parseInt(computed.getPropertyValue("width"), 10);
var h = parseInt(computed.getPropertyValue("height"), 10);
canvas.width = w;
canvas.height = h;
ctx.clearRect(0, 0, w, h);
ctx.beginPath();
ctx.arc(w/2, h/2, h/2, 0, Math.PI*2, true);
ctx.stroke();
}, 2000); // intentionally long to see the effect