CSS Layout How to - Place to fixed position relative to page flow








Question

We would like to know how to place to fixed position relative to page flow.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
body {<!--from w  w w .j  ava2s  . c o m-->
  background: #eee;
}

.container {
  width: 400px;
  padding: 20px;
  height: 1000px;
  margin: 0 auto;
  background: #fff;
}

.item, .fixed-anchor {
  float: left;
  margin-right: 10px;
  position: relative;
}

.fixed {
  position: fixed;
  margin-left: 100px;
}
</style>
</head>
<body>
  <div class="container">
    <div class="navigation">
      <div class="item">Navigation</div>
      <div class="item">Navigation</div>
      <div class="item">Navigation</div>
      <div class="fixed-anchor">
        <div class="fixed">Tadaa!</div>
      </div>
    </div>
  </div>
</body>
</html>

The code above is rendered as follows: