CSS Layout How to - Create Simple Responsive Layout








Question

We would like to know how to create Simple Responsive Layout.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.wrapper {<!--   www  . ja v a 2 s . c  o m-->
  width: 600px;
  background: #ccc;
  margin: 0 auto;
}

.col-1 {
  width: 32%;
  float: left;
  background: aqua;
  margin-left: 2%;
}

.first {
  margin-left: 0;
}

.clearfix:after {
  content: ".";
  display: block;
  clear: both;
  visibility: hidden;
  height: 0;
  line-height: 0;
}

@media only screen and (max-width: 600px) {
  .wrapper {
    width: 90%;
  }
  .col-1 {
    width: 100%;
    float: none;
    margin-left: 0;
    margin-bottom: 20px;
  }
}
</style>
</head>
<body>
  <div class="wrapper clearfix">
    <section class="col-1 first">A</section>
    <section class="col-1">B</section>
    <section class="col-1">C</section>
  </div>
</body>
</html>

The code above is rendered as follows: