I am facing an issue with an image inside a div. Whenever I add a margin-top, the background of the div extends downwards, which is not the desired behavior. How can I fix this problem?
Below is my code snippet:
<div id="content">
<div class="page">
<div class="half">
<p>Text goes here.</p>
</div>
<div class="half">
<img src="imghere.png" alt="img" />
</div>
</div>
</div>
CSS
.page {
width:500px;
margin:0 auto;
padding: 5px;
}
.half {
display:inline-block;
width:44%;
margin:0 2%;
}
This code ensures that the text column appears on the left side while the image column is on the right side and adjusts accordingly when the window size is changed.
How can I achieve the layout transformation from:
-----div-----------
Text Image
-----/div-----------
to
-----div------------
Text
--/div--Image----
Here is an image demonstrating the desired layout: