Vertical Alignment in To align text vertically in the middle of a Using Line-Height To vertically center single-line text, apply line-height equal to the desired element height, as demonstrated in the following CSS: Using Display Properties For multi-line text, wrap the text in a and apply display: table; and display: table-cell; along with vertical-align: middle; as follows: Using Transform Property For more advanced alignment, consider using the transform property with translateY(): Important Notes: The above is the detailed content of How to Vertically Center Text within a Div Element?. For more information, please follow other related articles on the PHP Chinese website!#abc {
line-height: 50px;
}
#abc {
display: table;
width: 100%;
}
#abc span {
vertical-align: middle;
display: table-cell;
}
#abc {
position: absolute;
top: 50%;
transform: translateY(-50%);
}