Css3 in the middle. Transform failed?

<div class="header">
    <span class="something"></span>
</div>
.header {
    margin-top: 40px;
    width: 100%;
    height: 62px;
    position: relative;
    overflow: hidden;

    & > .something {
        font-size: 20px;
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
    }

}

before absolute positioning is not used:


:

how can I achieve my goal? Thank you.

Mar.29,2021

because you set left: 50% , the default div width is only 50%.
and the content happens to be all in Chinese, and there can be line breaks in the middle of each character, so the line breaks are done by default.
set css not to allow line breaks.


display:block;
text-align:center

Menu