jeudi 28 avril 2016

Align 2 divs in same line without using float

I am a new learner in web designing and practicing websites. I want to align 2 divs in one line without using float. I have a parent div with width 1400px. I want 2 child divs of width 600px each to align next to each other and have equal margin from both sides. Below is my code. Please suggest.

Also, what changes does float make to DOM? I observed that if I use float I need to specify the height as well? Is it the case or I was making some mistake in understanding the role of float?

<html>
  <head>
    <title>
      My Page
    </title>
  </head>
  <body>
    <div class="main">
      <div class="child1">Child 1</div>
      <div class="child2">Child 2</div>
    </div>
  </body>
</html>

.main{
  width:1400px;
  background-color:#c3c3c3;
  position: relative;
  display: inline-block;
}
.child1{
  background-color:#666;
  width: 600px;
  margin:auto;
}
.child2{
  background-color:#888;
  width : 600px;
  margin:auto;
}




Aucun commentaire:

Enregistrer un commentaire