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

Gap between content and border when using flex

I have a row of images in a div with a flex display, they are intended to lie plush against a bottom border, instead there is a gap.

<!DOCTYPE html>
<html>
    <head>
        <style>
            div {
                height: 100px;
                display: flex;
                align-items: flex-end;
                padding: 0;
                background-color: aquamarine;
                border-bottom: 2px solid hsl(0, 0%, 87%);
            }
            img {
                width: 80px;
            }
        </style>
    </head>
    <body>
        <div>
            <img src="https://urnabios.com/wp-content/uploads/2015/04/angel_oak_tree.jpg">
            <img src="https://cdn.thecoolist.com/wp-content/uploads/2016/05/Japanese-Cherry-beautiful-tree.jpg">
        </div>
    </body>
</html>

As you can see the padding of the div is 0, and the border is defined in absolute pixels. So how is this happening, and how might the intended layout be obtained?

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

>Solution :

Setting the ‘box-sizing’ of the div to ‘border-box’ would solve the problem.

<!DOCTYPE html>
<html>
    <head>
        <style>
            div {
                height: 100px;
                display: flex;
                align-items: flex-end;
                padding: 0;
                background-color: aquamarine;
                border-bottom: 2px solid hsl(0, 0%, 87%);
                box-sizing: border-box;
            }
            img {
                width: 80px;
            }
        </style>
    </head>
    <body>
        <div>
            <img src="https://urnabios.com/wp-content/uploads/2015/04/angel_oak_tree.jpg">
            <img src="https://cdn.thecoolist.com/wp-content/uploads/2016/05/Japanese-Cherry-beautiful-tree.jpg">
        </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