w3resource
HTML exercises

CSS Properties: How to place an element at a certain distance from top of the document

Go to Exercise page

Solution:

HTML Code :

 <!DOCTYPE html>
  <html>
  <head>
  <title>How to place an element at a certain distance from top of the document</title>
  <style type="text/css">
  div.w3r {
  position: relative;
  width: 300px;
  height: 150px;
  border: 3px solid #3333FF
  }
  div.w3r1 {
  position: absolute;
  top: 50px;
  width: 150px;
  height: 80px;
  border: 3px solid #FF9900
  } 
  </style>
  </head>
  <body>
  <h1><strong>w3resource Tutorial</strong></h1>
<div class="w3r">This division element position: relative.
<div class="w3r1">This division element position: absolute. It is placed 50 pixels below the top edge.</div> </div> </body> </html>

Live Demo:

See the Pen top-answer by w3resource (@w3resource) on CodePen.


See the solution in the browser

Supported browser

Firefox logo Chrome logo Opera logo Safari logo Internet Explorer logo
YesYesYesYesYes

Go to Exercise page

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming