Irfan D. Irfan D. - 9 months ago 22
HTML Question

How to make same height two div and center

how to floated two divs height makes same and after second div slip down, the container width fit child width and divs are center automatically? i apologise for my english. :(

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="" xml:lang="en">
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<style type="text/css">

.left {
width: 510px;
float: left;


.right {
float: left;
width: calc(100% - 520px);
width: -webkit-calc(100% - 520px);
width: -moz-calc(100% - 520px);
width: -o-calc(100% - 520px);
background-color: #00f;
//min-height:50px; (edited)

<div class="container">
<div class="left"><p>paragraph 1</p><p>paragraph 2</p></div>
<div class="right"><p>paragraph 1</p></div>
<div class="clear"></div>

[i want to do this] (edited again!)


You should remove the floating and give width: auto; for .left & .right elements, at the certain point when the width is reduced. Further, to make the .container center aligned give max-width and align it using margin-left: auto; & margin-right: auto;

Below is the media query:

    @media (max-width: 600px){
            max-width: 400px;
            margin:0 auto;
         .left, .right{
             float: none;
             width: auto;
             padding: 10px;
         .left p{
             padding-bottom: 10px;

Padding bottom for <p> tag is added to get the spacing between the elements.

Find the working fiddle here: