I have div block
with property flex
CSS.
This block has 80% width and 50% height of display.
How to display this block in center by horizontal and vertical?
Flex alignment properties apply to the children of a flex container.
So if you have a div with display: flex
, and you want to center this div, you make the parent a flex container. Then you can apply flex alignment properties to the div.
div {
display: flex;
width: 80%;
height: 50vh;
border: 1px solid black;
}
body {
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
}
<div></div>
Here's a more complete explanation: https://stackoverflow.com/a/33049198/3597276