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

why the button is not contained in the container?

I am trying to display the button in the bottom-right part of the container but it is shown outside of the container borders. Can someone help me to fix this?

<head>
    <title>title</title>

    <style>
        .container{
            border: 1px solid black;
        }

        .myButton{
            font-size: 20px;
            border: 2px solid red;
            float: right;
        }
    </style>
    
</head>
<body>
    <div class="container">
        <h1>title</h1>
        <p>
            Lorem, ipsum dolor sit amet consectetur adipisicing elit. Eligendi velit consectetur,
            rem autem pariatur magnam aliquid? Necessitatibus quia quae, earum voluptate sit
            nobis vel et repudiandae esse fugiat, nemo debitis.
        </p>
        <button class="myButton">button</button>
    </div>
</body>

>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

When you used float: right the button went outside the flow of elements of the page. Try using flex instead.

<head>
    <title>title</title>

    <style>
        .container{
            border: 1px solid black;
        }

        .myButton{
            font-size: 20px;
            border: 2px solid red;
+           margin-right: 0;
+           margin-left: auto;
        }
+       .a{
+          display: flex;
+       }
    </style>
    
</head>
<body>
    <div class="container">
        <h1>title</h1>
        <p>
            Lorem, ipsum dolor sit amet consectetur adipisicing elit. Eligendi velit consectetur,
            rem autem pariatur magnam aliquid? Necessitatibus quia quae, earum voluptate sit
            nobis vel et repudiandae esse fugiat, nemo debitis.
        </p>
+     <div class="a">
+       <button class="myButton">button</button> 
+     </div>
        
    </div>
</body>
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