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 does the image leave the margins of its parent container when I increase the width?

I have spent some time trying to work this out but with no luck.
I’m trying to align the text elements along side the image like this picture below. I was able to do this with absolute positioning.

absolute positioning

However I also want my page to be responsive so I decided to use a flex box container to put the text elements and the image elements side by side and get the equal distancing when I resized the window. However when I increase the size of my image the content area just ignore its padding margins and parent container. It creates a scroll on the window width and a plain white background.

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

responsive image

Would love to hear what people think I’m doing wrong. Would also like to hear any other ways that people would go about creating the desired effect I’m looking for.

This is my code below 👇

<body>
    <header>
        <div class="container">
            <div class="justify">
                 <div class="inline">
                 <h1>App name</h1>
                 <h2>Download on the app store!</h2>
                 <a href="https://www.apple.com/uk/app-store/" target="_blank"><img class="downloadimg" src="appstore.png" alt="download link">
                </a>
                </div>
                <div class="inline">
                <img class="werewolf" src="werewolf.png" alt="app logo">
                </div>
            </div>
        </div>
    </header>
</body>
</html>

CSS code:

body{
    margin: 0px;
    padding: 0px;
    font-family: 'Bebas Neue', cursive;
}
header{
    background-color: aqua;
    font-size: 40px;
    padding-left: 10%;
    padding-top: 10%;
    padding-bottom:10%;
    border-style: dashed;
    border-color: rgb(255, 0, 0);

}
.justify{
    display: flex;
    align-items: center;
    justify-content: space-between;
   
}
.downloadimg{
    width: 50%;
}
.inline{
    border-style: dashed;
    border-color: rgb(255, 0, 0);
    
}
.werewolf{  
    width: 140%;
   
}

>Solution :

Try adding that to your image css rules:

    image.werewolf {
        display: block; /* or inline-block */
        max-width: 100%;
        height: auto; /* to maintain aspect ratio */
    }
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