Learn free online HTML5, javascript, and jquery Tutorials by Examples

Tuesday 23 May 2017

vertically and horizontally center div css

<style>
.center {
    height: 200px;
    position: relative;
    border: 3px solid green;
}

.center p {
    margin: 0;
    position: absolute;
    top: 50%;
    left: 50%;
    -ms-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
}
</style>

<div class="center">
  <p>vertically and horizontally centered.</p>
</div>

No comments:

Post a Comment