When I insert an img into the article element it makes it so my body no longer is 100% of the browser height.
Without the image the body scales fine, goes all the way down to the bottom of the screen. But upon adding the image, it does not push the body background down. What am I doing wrong? I did not include the code for the whole page, just the parts that I think are important to my problem. If more info is needed let me know.
<body>
<main>
<article>
<img src="https://www.lawrenceprospera.org/images/quintana/Page_Under_Construction.jpg" width="600px" align="right">
<h2>Hello</h2>
This website is a work in progress. Sorry for the mess!
</article>
</main>
</body>
html {
background: #7f4160;
height: 100%;
-webkit-font-smoothing: antialiased;
}
body {
background: #424160;
color: #000;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 16px;
line-height: 1.5;
margin: 0 auto;
max-width: 800px;
min-height: 100%;
height:100%;
padding: 2em 2em 4em;
border-left: 3px solid #573444;
border-right: 3px solid #573444;
}
img {
background: transparent;
border: 10px solid rgba(0, 0, 0, 0.12);
border-radius: 4px;
padding:0;
display: inline-block;
max-width: 95%;
}
2
Answers
You can try to apply a "clearfix" solution to the element to ensure that it properly contains its floated child elements.
"clearfix" is a technique used in CSS to ensure that an element properly contains its floated child elements. When an element contains floated elements, it can sometimes collapse and not extend to the full height of its floated contents.
You can read more here.
Here’s an example of how you can modify your code:
And you can add the following CSS code to create the clearfix:
Side note:
Please consider using CSS classes instead of inline styles (align="right", width="600px") for better separation of concerns and maintainability.
Set the height of the image as "auto". It might solve the issue.