-2

I've checked similar posts and they are not helping.

I want my innermost div to appear in the center of the parent div.

For example:

<container>
  <div class="parent">
    <div class="child">
    </div>
  </div>
</container>

The parent div is a flex item inside an inline-flex container. margin: 0 auto is only allowing it to horizontally align, but I need it vertically aligned as well. Height and width are 80% of parent div.

How do I go about this?

Also, I will need to add a display: none at times. When I don't want display: none active, what can I leave display as?

Edit:

.Card {
    width: 150px;
    height: 220px;
    border: 2px solid rgb(218, 186, 186);
    margin: 10px;
    display: inline-flex;
}

.FaceUp {
    display: none;
}

.FaceDown {
    height: 80%;
    width: 80%;
    margin: 0 auto;
}

I've tried margin, justify-content, justify-items, align-content, align-items, vertical-align. None seem to be working.

FaceDown and FaceUp will never display at the same time. They are the child/sibling divs inside the parent div.

jkdev
  • 11,360
  • 15
  • 54
  • 77
Alice
  • 612
  • 1
  • 5
  • 13

2 Answers2

1

Did u try writing:

 parentDiv {
  display: flex;
  justify-content: center;
  align-content: center;
 }

 childDiv {
  align-self: center;
 } 

Because every parent should have display: flex; in order to affect a child

pitygacio
  • 41
  • 6
-1

try this

position: absolute;
top: 50%;
transform: translateY(-50%)
Gene Rally
  • 19
  • 3