Exploring what’s possible with CSS. I’d like to achieve an effect where:
- I have a full-width color background stripe
- The actual content is centered with a fixed width
- The content consists of a paragraph with an image to the right
- The image’s top-right sits at its expected place inside the stripe, but its bottom extends below the background stripe
The below achieves this result, but it depends on explicitly setting the inner flex height to 110px and I’m hoping I can instead just have it hug the <p> while not hugging the image div.
<div style="display: flex; justify-content: center; background-color: hsl(215, 100%, 86%); ">
<div style="display: flex; justify-content: space-between; width: 500px; height: 110px;">
<p style="width: 30ch;">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</p>
<div>
<img src="https://unsplash.it/150">
</div>
</div>
</div>
2
Answers
You can make the image’s container be absolutely positioned with
top
,right
set to0
with respect to its parent.The two changes are, make the immediate parent
position: relative
so it becomes the reference for the absolute positioning and style the image container itself:position: absolute; top: 0; right: 0;
I attaching your code. Hope your success.