Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

trying to make canvas fill page under a title

i want the canvas to fill the whole webpage under the heading, maybe with a small margin between the edge of the canvas and the edge of the window. but i can’t get it to fill the screen and now the title is next to it instead of above it. any help is appreciated

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>shark?</title>
    <style>
        html, body {
            height: 100%;
            width: 100%;
            margin: 0;
        }
        .container {
            display: flex;
            align-items: center;
            justify-content: center;
            height: 100%;
            width: 100%;
        }
        canvas {
            background-color: dodgerblue;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>shark?</h1>
        <canvas></canvas>
    </div>
</body>
</html>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Adding the property flex-direction: column; to the container class to arrange the elements vertically.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>shark?</title>
    <style>
        html, body {
            height: 100%;
            width: 100%;
            margin: 0;
            overflow: hidden; /* Prevent scrollbars */
        }
        .container {
            display: flex;
            flex-direction: column; /* Arrange elements vertically */
            align-items: center;
            justify-content: center;
            height: 100%;
            width: 100%;
        }
        h1 {
            margin-top: 20px; /* Add margin above the heading */
        }
        canvas {
            background-color: dodgerblue;
            margin: 10px; /* Add margin around the canvas */
            flex: 1; /* Allow the canvas to fill available vertical space */
            width: calc(100% - 20px); /* Account for margin */
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>shark?</h1>
        <canvas></canvas>
    </div>
</body>
</html>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading