0

I am a total CSS newbie so please forgive my asking such a simple question.

I'm using a flexbox to present two boxes. The first box contains some vertically aligned texts with a button. The second box contains an image.

I want the image to always be the same height as the content of the first box, so that the flexbox height is limited to the height of the content inside the first box.

And this is the current behavior:

enter image description here

    .sample-section {
        display: flex;
        flex-wrap: wrap;
        border-style: dashed;
    }
    
    .sample-child {
        flex: 1 0 auto;
        width: 400px;
        border-style:groove;
    }
    
    .sample-child img {
        width: 100%;
        max-height: 100%;
    }
<!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <link rel="stylesheet" href="styles.css">
    </head>
    <body>
        <div class="sample-section">
            <div class="sample-child">
                <h1>Headline</h5>
                <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
                <button>
                    My Button
                </button>
            </div>
            <div class="sample-child">
                <img src="http://via.placeholder.com/400x300" alt="">
            </div>
        </div>
    </body>
    </html>

I'm thankful for any help!

mfluehr
  • 2,832
  • 2
  • 23
  • 31
Womble Tristes
  • 393
  • 1
  • 4
  • 14

0 Answers0