html tutorial - How to center align absolute positioned div using CSS - html5 - html code - html form



Answer: Use the CSS margin, left, right Property

    CSS margin:It align the positioned <div> element and property that combination with the left and right position.

    Example

      <!DOCTYPE html>
      <html lang="en">
      <head>
      <meta charset="utf-8">
      <title>Center Alignment of Absolutely Positioned Elements</title>
      <style type="text/css">
          .box {
              width: 50%;
              position: absolute;
              z-index: 99;
              margin: 0 scroll;
              left: 0;
              right: 0;
              padding: 20px;
              background: #f0e68c;
          }
      </style>
      </head>
      <body>
          <div class="box">
              <h1>This is a heading</h1>
              <p>This is a paragraph.</p>
          </div>
      </body>
      </html>

      Related Searches to How to center align absolute positioned div using CSS