⽗元素和⼦元素同时左浮动,然后⽗元素相对左移动50%,再然后⼦元素相对右移动50%,或者⼦元素相对左移动-50% 也就可以了。
<style>
.p {
position:relative;
left:50%;
float:left;
}
.c {
position:relative;
float:left;
right:50%;
}
</style>
<body>
<div clsaa='p'>
<h1 class='c'> hello world </h1>
</div>
</body>