CSS Layout How to - Adjust div position with screensize








Question

We would like to know how to adjust div position with screensize.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
#left {
  background: #f00;
  height: 200px;
}<!--   w ww.j  a v  a  2 s .c o m-->

#right {
  overflow: hidden;
  background: #0f0;
  height: 200px;
}

@media all and (min-width:600px) {
  #left {
    float: left;
    width: 180px;
  }
  #right {
    margin-left: 180px;
  }
}
</style>
</head>
<body>
  <div>
    <div id="left">Nav</div>
    <div id="right">This is the space I need to fill but not go
      underneath the nav div</div>
  </div>
</body>
</html>

The code above is rendered as follows: