vertical align in div code example
Example 1: css align center
//HTML
<div class="parent">
<span>Hello World</span>
</div>
//CSS
.parent {
display: flex;
justify-content: center;
align-items: center;
}
Example 2: css align items vertical center
.parent {
display: flex;
justify-content: center;
align-items: center;
}
Example 3: css center text in div
parent-element {text-align:center;}
parent-element {position: relative;}
element-to-be-centered {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
Example 4: css vertical align
.top-align {
vertical-align: top;
}
.center-align {
vertical-align: middle;
}
Example 5: css vertical align items in div
.flex-center-vertically {
display: flex;
justify-content: center;
flex-direction: column;
height: 400px;
}
Example 6: 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;
}