HTML Element Style How to - Position div tags on the top and bottom outside a big div








Question

We would like to know how to position div tags on the top and bottom outside a big div.

Answer


<!--from w w  w . j  av  a 2  s  .  c  om-->


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
#big {
  position: relative;
  width: 400px;
  height: 400px;
  overflow: visible;
  border: 1px solid red;
}

#button1, #button2 {
  width: 100px;
  height: 50px;
  position: absolute;
  right: -120px;
  border: 1px solid blue;
}

#button1 {
  top: 0px;
}

#button2 {
  bottom: 0px;
}
</style>
</head>
<body>
  <div id="big">
    hello
    <div id="button1">foo</div>
    <div id="button2">bar</div>
  </div>
</body>
</html>

The code above is rendered as follows: