Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two column DIV layout becomes one column center aligned

In the center of my webpage I have a div with id center-container which contains 2 divs: one for a video player(on the left) and the second one (on the right) for an optional thing like playlist. Above and below the center-container div I have another content as well.

Now the question. How can I make my video player container to come to the middle of the page when the playlist div is absent (not set) without braking the remaining layout.

enter image description here

like image 844
Karine Avatar asked Nov 20 '11 15:11

Karine


People also ask

How do you divide two columns into flex?

Approach: To create a two-column layout, first we create a <div> element with property display: flex, it makes that a div flexbox and then add flex-direction: row, to make the layout column-wise. Then add the required div inside the above div with require width and they all will come as columns.

How do I align 3 divs in one row in HTML?

Three or more different div can be put side-by-side using CSS. Use CSS property to set the height and width of div and use display property to place div in side-by-side format. float:left; This property is used for those elements(div) that will float on left side.

How do you divide columns in HTML?

An HTML column is defined in the <div> tag using the class = "column" keyword. More columns can be added by adding more divs with the same class. The following syntax is used to add columns in HTML. <div class="row"> tag is used to initialize the row where all the columns will be added.


1 Answers

You can do this with less & simple code like this:

.playlist{
    width:100px;
    height:100px;
    float:right;
    background:blue;
    margin-right:20px;
}
.playlist + .video{
    width:200px;
    height:100px;
    margin-left:20px;
    background:green;
    float:left;
}
.video{
    width:200px;
    height:100px;
    margin:0 auto;
    background:green;
}

http://jsfiddle.net/qcTSt/

like image 87
sandeep Avatar answered Sep 21 '22 11:09

sandeep