CSS Layout How to - Float Spans width Div left, center and right








Question

We would like to know how to float Spans width Div left, center and right.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
#header {<!--from  w  w w .j ava2s . com-->
  padding: 6px;
  background-color: #BBB;
  overflow: auto;
}

#left {
  float: left;
}

#center {
  text-align: center;
}

#right {
  float: right;
}
</style>
</head>
<body>
  <div id="header">
    <span id="left">Page Title</span> 
    <span id="right"><a href="logout.php">Logout</a></span>
    <div id="center">Logged in as</div>
  </div>
</body>
</html>

The code above is rendered as follows: