Dina Dina - 4 years ago 133
HTML Question

center h1 in the middle of screen

how i can center horizantaly and vertically a text, i dont want to use positon absolute becuase i try with it and my other div getting worse is there is other way to do that ?



div{
height: 400px;
width: 800px;
background: red;
}

<div>
<h1>This is title</h1>
</div>




Answer Source

you can use display flex it enables a flex context for all its direct children, and with flex direction establishes the main-axis, thus defining the direction flex items are placed in the flex container

div{
  height: 400px;
  width: 800px;
  background: red;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download