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
One way to center text or put it in the middle of the page is to enclose it within <center></center> tags. Inserting this text within HTML code would yield the following result: Center this text!
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>
You do not need to use div's to do this, you can style the elements themselves. The < a > tag by default does not understand text-align, as it is an inline element, so I have placed the link in a paragraph, which accepts text-align. I have placed the two lines in a < div > tag with a small width so it is easy to see what is going on.
<div style="width:400px;">
<h1 style="text-align:center"> Sample Heading</h1>
<p style="text-align:right"><a href="#">sample link</a> </p>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With