center items vertically and horizontally code example
Example 1: center div horizontally and vertically
.parent {
position: relative;
}
.child {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
Example 2: css align center
//HTML
<div class="parent">
<span>Hello World</span>
</div>
//CSS
.parent {
display: flex;
justify-content: center;
align-items: center;
}
Example 3: css center position
body {
text-align: center;
}
tag_name {
display: inline;
}
tag_name {
display: block;
width: 170px;
}
tag_name {
display: block;
width: 100px;
margin: 0 auto 0 auto;
}
Example 4: how to center horizontally and vertically block div
#html code
<div class="parent">
<h1 class="child">CSS is cool</h1>
</div>
#css code
.parent{
display:grid;
place-items:center;
width:560px;
height: 560px;
}