Div in center and middle align in any box with css

How to do div vertically align middle and center, How to do any container middle and center?

Here are many available many ways that you can align content box vertically middle and center.



<style>
      .flexContainer {
        displayflex;
        align-itemscenter;
        justify-contentcenter;
        height500px;
        background#0bf;
      }
      
      .flexInnerBox {
        background#fff;
      }
      </style>

      <h1>Complete center elements</h1>
           
      <div class="flexContainer">
        <div class="flexInnerBox"> I am in the center</div>

      </div>

__________________________________________________________________________

<style>
    html,
    body {
        height: 100%;
        overflow: hidden;
    }
    body {
        position: relative;
    }
   .textMiddleCenter {
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%)
    }
</style>
<div class="textMiddleCenter">Test content Hello world!</div>



<style>
        .className {
            width: 270px;
            height: 150px;
            position: absolute;
            left: 50%;
            top: 50%;
            margin: -75px 0 0 -135px;
        }
    </style>
    <div class="className">
        <p>Centered Horizontally And Vertically With CSS</p>
    </div>

<style>
        .centered {
            position: fixed;
            top: 50%;
            left: 50%;
            -webkit-transform: translate(-50%, -50%);
            -moz-transform: translate(-50%, -50%);
            -o-transform: translate(-50%, -50%);
            -ms-transform: translate(-50%, -50%);
            transform: translate(-50%-50%);
        }
    </style>

    <div class="centered">This div is centered</div>

This is the good and support for all browser. container align middle and vertically
<style>
        body,
        html,
        #wrapper {
            width: 100%;
            height: 100%
        }
        #wrapper {
            display: table
        }
        #main {
            display: table-cell;
            vertical-align: middle;
            text-align: center
        }
    </style>
    <div id="wrapper">
        <div id="main">Content goes here</div>
    </div>


No comments:

Note: Only a member of this blog may post a comment.

Copyright Reserved to Anything Learn. Powered by Blogger.