HTML Element Style How to - Place two divs in the same line








Question

We would like to know how to place two divs in the same line.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
div.relative {<!--from www  . j a  v a  2  s  .  com-->
  position: relative;
  width: 300px;
  height: 300px;
  overflow: scroll;
  background: blue;
  white-space: nowrap;
}

div#one, div#two {
  display: inline-block;
  width: 200px;
  height: 50px;
}

div#one {
  background: red;
}

div#two {
  background: green;
}
</style>
</head>
<body>
  <div class="relative">
    <div id="one"></div>
    <div id="two"></div>
  </div>
</body>
</html>

The code above is rendered as follows: