如何对齐文本中心和右侧

May*_*yur 6 html css

在对齐两个文本时我遇到问题,一个在中心,另一个在右边.

我用Div来对齐它:

<div style="text-align:center">
  <h1> Sample Heading</h1>

    <div style="float:right; text-align:center">

         <a href="#">sample link</a> 

    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

当我使用它时,我的标题是左边的,它不是中心对齐,请告诉这是正确的方法还是有任何其他方法来处理这种情况.

谢谢

Dan*_*den 2

如果您希望该项目不扰乱布局,请尝试绝对:

<div id="header" style="position:relative;text-align:center;"><!-- define relative so child absolute's are based on this elements origin -->
    <div id="sampleLink" style="position:absolute; top:0px; right:0px; >Link</div>
    <h1 style="text-align:center;">Heading</h1>
</div>
Run Code Online (Sandbox Code Playgroud)