CSS Layout How to - Create layout with absolute position








Question

We would like to know how to create layout with absolute position.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.floorplan, .room {<!--from  w ww  .j  a v a2 s. co  m-->
  border: 1px solid #ee7538;
}
.floorplan {
  background: #ebecec;
  height: 300px;
  position: relative;
  width: 200px;
}
.room {
  background: #fff;
  color: #000;
  display: block;
  font-family: Impact, sans-serif;
  font-weight: bold;
  position: absolute;
  text-align: center;
  text-decoration: none;
}
.room:hover {
  background: #ee7538;
  color: #fff;
}
#room1018 {
  height: 50px;
  left: 20px;
  line-height: 50px;
  top: 20px;
  width: 100px;
}

#room1025 {
  height: 100px;
  left: 20px;
  line-height: 100px;
  top: 100px;
  width: 50px;
}
</style>
</head>
<body>
  <div class="floorplan">
    <a class="room" href="#" id="room1018"> 1018 </a> 
    <a class="room" href="#" id="room1025"> 1025 </a>
  </div>
</body>
</html>

The code above is rendered as follows: