How to vertical center a div with position fixed and width in px?

I want to center a div with position fixed. And its width is specified as 300px and not in percentage.

<div class="mainCont">
  <div class="childCont">
</div>

childCont is div with fixed pos and width 300px. I want to make it as center.

Answers 1

  • Use the following CSS to your 'childCont' class:

    .childCont {
        position: fixed;
        width: 300px;
        top: 50%;
        left: 50%;
        transform: translate3d(-50%,-50%, 0);
    }
    

Related Articles