Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to place two section elements next to each other using CSS? [duplicate]

Tags:

html

css

I'm trying to implement the following HTML structure using HTML5 and CSS. The section elements have to be next to each other. The right section element must have a margin-left of 30 px and a fixed width of 220 px.

enter image description here

What I have so far is as follows:

HTML

<section id="section-left">My left section</section>
<section id="section-right">My right section</section>

CSS

#section-left {
   float: left;
}

#section-right {
   float: right;
   width: 220px;
   margin-left: 30px
}

My problem is that the left section does not fill the remaining space up to the right section element. My result looks as follows:

enter image description here

What is the problem here?

like image 440
Javiator Avatar asked Jul 25 '14 20:07

Javiator


Video Answer


1 Answers

Reverse the order of your sections and use this CSS:

#section-left {
    overflow:hidden;
}
#section-right {
    width:220px;
    margin-left:30px;
    float:right;
}

jsFiddle example

like image 76
j08691 Avatar answered Oct 26 '22 23:10

j08691