CSS Layout How to - Float right, right and center








Question

We would like to know how to float right, right and center.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
#header {<!--from  w  w w . j a  v a  2  s  .  c om-->
  text-align: center;
}

#ruler {
  border-bottom: 1px solid #000;
}

#left {
  float: left;
  width: 100px;
  background-color: #eee;
}

#right {
  float: right;
  width: 100px;
  background-color: #eee;
}

#center {
  margin: 0 auto;
  width: 250px;
  overflow: hidden;
  background-color: #ccc;
}
</style>
</head>
<body>
  <div id="header">Hello</div>
  <div id="ruler">ruler</div>
  <div id="left">Left</div>
  <div id="right">Right</div>
  <div id="center">Center</div>
</body>
</html>

The code above is rendered as follows: