Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I display 2 sections side-by-side? [duplicate]

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.

like image 919
Matt Norris Avatar asked Sep 23 '10 12:09

Matt Norris


People also ask

How do I show two divs side by side?

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.

How do I put text and pictures side by side?

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.


1 Answers

You have to add overflow:hidden; to the parent.

Preview:

alt text

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>
like image 78
Jeaf Gilbert Avatar answered Sep 25 '22 03:09

Jeaf Gilbert