center div vertically and horizontally responsive code example

Example 1: position absolute vertical center

<style>
.parent { position: relative; }
.centered-element {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}
  
</style>

<div class="parent">
 <div class="centered-element">I'm Centered!</div>
</div>

Example 2: how to center a div vertically and horizontally

.container{	
	margin: 0;
    position: absolute;
    top: 50%;
    left: 50%;
    -ms-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
  	width: /* Define the width here; */
    height: /* Define the height here; */
}

/*You have to define the width and height! */

Tags:

Html Example