align elements vertically css code example
Example 1: css align center
//HTML
Hello World
//CSS
.parent {
display: flex;
justify-content: center;
align-items: center;
}
Example 2: center elements vertically in div
.container {
display: flex;
align-items: center;
}
Example 3: css vertical align
.top-align {
vertical-align: top;
}
.center-align {
vertical-align: middle;
}
Example 4: css center div vertically
/* center vertically */
/* No Flexbox */
.parent {
position: relative;
}
.child {
position: absolute;
top: 50%;
transform: translateY(-50%);
}
/* With Flexbox */
.parent {
display: flex;
flex-direction: column;
justify-content: center;
}
Example 5: vertical align css
.container{
display: table;
}
.div-inside-container{
display: table-cell;
vertical-align: middle;
}
Example 6: how to center align the html element in css examples
#inner {
width: 50%;
margin: 0 auto;
}
# center text
.center {
text-align: center;
border: 3px solid green;
}