Mayur Mayur - 5 months ago 20
CSS Question

how to align text center and right

I am facing problem while aligning two text, one in center and other text in right.

I used a Div to align it:

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

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

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

</div>
</div>


When I used this my heading comes left, its not a centrally align properly please tell is this the correct way or is there any other way to handle this scenario.

Thanks

Answer

If you want the item to not mess with the layout, try absolute:

<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>
Comments