HTML Element Style How to - Stack DIVs and horizontally and align them








Question

We would like to know how to stack DIVs and horizontally and align them.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
#outer {<!--  w  w w  .j a v a 2  s  .  co  m-->
  border: 1px solid red;
  display: inline-block;
}

#outer div {
  border: 1px solid green;
}
</style>
</head>
<body>
  <div id="outer">
    <div>Here is some stuff and things.</div>
    <div>Here is some stuff and things. Here is some stuff and things.</div>
  </div>
</body>
</html>

The code above is rendered as follows: