I'm a beginner to CSS and I'm trying to create a page with some tables and charts (using chart.js). My goal is to have a div filling 100% of the width of the page and inside of it two divs:
A div with a table near a chart - 66% of the screen
1a. Table will be 75% of div
1b. Chart will take the rest 25% of the div
A div with a chart - 33 %
or to make it more visual: something like this:
The purple is the main div, the blues are the two divs (66% and 33%) inside the main div and the reds (light and dark reds) are the div table and the div contain the 25% chart. The yellows are the canvas for the charts.
In order to get that I wrote something like this (I'm ignoring other style attributes shown in the image [like padding, margin, etc.] for simplicity) :
<div id="mainPurple" style="width: 100%;">
<div id="leftBlue" style="width: 66%;">
<div id="table" style="width: 75%;">
<table>...</table>
</div>
<div id="donutContainer" style="width: 25%; height: 100%;">
<canvas id="donutChart"></canvas>
</div>
</div>
<div id="rightBlue" style="width: 33%; height: 100%">
<canvas id="pie"></canvas>
</div>
</div>
Like I expected, the purple main div size was determined by the left blue div size that was determined by the table div. What did not happen like I expected is the divs containing the charts, did not stretch to the full height their parent div but instead got this weird ratio:
The only way I could change the size of the chart divs (like in the first picture) was by setting fixed size to the canvas: <canvas id="pie" height="300">
(Which is not good enough because I want it to be aligned for every screen. Trying to set the canvas style attribute did not change the canvas at all.
I assume I'm missing something very basic here but even after reading these answers:
make canvas as wide and as high as parent
I still wasn't able to fix it.