I have following HTML code:
<section class="indent-1">
<!-- Section 1 -->
<section>
<div>Some content</div>
<div>Some more</div>
</section>
<!-- Section 2 -->
<section>
<div>Some content</div>
<div>Some more</div>
</section>
</section>
And I'd like to display Section 1 on the left and Section 2 on the right instead of vertically like they normally appear. The parent section surrounding them is indented 120px
, and I'd like to preserve that.
How do I accomplish this? I tried float: left
on Section 1 and display: inline
on the parent section, but those seemed to cause Section 2 to "break out" of its parent section.
The most common way to place two divs side by side is by using inline-block css property. The inline-block property on the parent placed the two divs side by side and as this is inline-block the text-align feature worked here just like an inline element does.
Align image and text side by side On line 12 I have added style to the container class. I have added width property and given 300px width and added the flex property and align items to center. By using these properties, the image and text will be aligned side by side.
You have to add overflow:hidden;
to the parent.
Preview:
CSS:
<style>
section { border:1px solid red; padding:10px; overflow:hidden; }
section > section { float:left; }
.indent-1 { padding-left:120px; }
</style>
HTML:
<section class="indent-1">
<!-- Section 1 -->
<section>
<div>Some content</div>
<div>Some more</div>
</section>
<!-- Section 2 -->
<section>
<div>Some content</div>
<div>Some more</div>
</section>
</section>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With