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

How to prevent div being cut of when resized or even in normal window?

I have tried thing like overflow:auto and margin-left overflow:auto cuts of some part from left of the div and margin-left will not work when length of div is increased is there any better option.As you can see in below code you are not able to see the text.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>
        
    </title>
</head>
<style>
    body{
        min-height: 100vh;
        display: flex;
        justify-content: center;
        margin: 0 ;
        align-items: center;
        flex-direction: column;
        overflow: auto;
    }
    h1{
        width: 2500px;
        min-height: 300px;
        background: pink;
        color: black;
    }

</style>
<body>
        <h1>This is h1</h1>
</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

The issue with your code is that you are centering the items vertically in the flex.

This causes the div to shift to the left, thus going out of the page. Since you cannot scroll beyond the left boundary of the page, that part of the div becomes inaccessible.

You can fix this by making sure that the flex container is wide enough. Add the following line to the body style:

width: fit-content;
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