CSS - How to align a anchor link to Right side of a page
In this tutorial, we are going to learn about how to align a anchor <a>
link to the right side of a page using CSS.
Consider, we have the following anchor link inside the div tag of our html:
<div class="container">
<a href="https://google.com" class="link">Google</h1>
</div>
To align a anchor link towards the right side of the page, add the display:flex
and justify-content: flex-end
to the anchor CSS class.
“justify-content: flex-end” positioned the anchor link at the end of the container.
Here is an example:
<div class="container">
<a href="https://google.com" class="link">Google</a>
</div>
CSS:
display: flex;
justify-content: flex-end;
}
or we can add the inline styles to anchor element using the style
attribute in HTML.
<div class="container">
<a href="https://google.com" style="display: flex;justify-content: flex-end;">
Google
</a>
</div>
Align the anchor link to right using absolute position
We can also use the absolute positioning in css to position the anchor <a>
link towards the right side of a page.
Here is an example:
<div class="container">
<a href="https://google.com" class="link">Google</a>
</div>
.link{
position:absolute;
right:0%;
}
-
Here we added
position:absolute
to the anchor element css class, so the element breaks out from the normal document flow and positioned to its relative parent (eg: body or parent element). -
The
right:0%
places the element towards the right side of the container.