Positioning Divs relative,absolute, center

In this example below you will see how to do a Positioning Divs relative,absolute, center with some HTML / CSS and Javascript

This awesome code was written by Ferencok, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright Ferencok ©
  • HTML
  • CSS
<!DOCTYPE html>
<html lang="en" >

  <meta charset="UTF-8">
  <title>Positioning Divs relative,absolute, center</title>
      <link rel="stylesheet" href="css/style.css">



<h2>Image Text</h2>
<p>Center text in image:</p>

<div class="container">
  <div class="center">Centered</div>



/*Downloaded from https://www.codeseek.co/Ferencok/positioning-divs-relativeabsolute-center-VbVeYq */

.container {
    position: relative;
    background: red;
    height: 200px;

.center {
    position: absolute;
    left: 25%;
    top: 50%;
    width: 50%;
    text-align: center;
    font-size: 18px;
     background: lime;

img { 
    width: 100%;
    height: auto;
    opacity: 0.3;