CSS Layout How to - Fix top header








Question

We would like to know how to fix top header.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
body {<!--   w ww  . j a  va  2  s  .  com-->
  height: 1000px;
}

#fixed {
  background-color: yellow;
  width: 100%;
  left: 0;
  top: 0;
  height: 50px;
  position: fixed;
}
</style>
</head>
<body>
  <div id="fixed">fixed</div>
</body>
</html>

The code above is rendered as follows: