Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to align my link to the right side of the page?

Tags:

html

css

I have a link on my index page:

<div class="content">
    <a class="buy" href="buy.html">Buy</a> 
</div>

I would like to align it to the right side of my page, I tried:

a.buy{
  color: #2da1c1;
  font-size: small;
  text-decoration: none;
  left: 252px;
  float: left;

}
a.buy:hover
{
color: #f90;
text-decoration: underline;
left: 252px;
float: left;                 
}

But it still located on the left side. (I have included my CSS file in my index.html, and the CSS file already take effect for other elements on the page)

like image 545
Leem Avatar asked May 31 '11 08:05

Leem


People also ask

How do I set align to the right in HTML?

Similarly, to right align a paragraph on the canvas with HTML's align attribute you could have: <P align="right">...

How do I align links side by side in HTML?

Give your links a display of "inline-block" and they will appear next to each other. You can then add some padding or margin to give them some space. You can achieve the same result by using the li tag and giving them the display:inline-block style.

How do you align a button to the right of the page?

If you want to move the button to the right, you can also place the button within a <div> element and add the text-align property with its "right" value to the "align-right" class of the <div>.


2 Answers

Try float: right:

a.buy {
    color: #2da1c1;
    font-size: small;
    text-decoration: none;
    float: right;
}
a.buy:hover
{
    color: #f90;
    text-decoration: underline;         
}

Another way would be:

.content {
    position: relative
}
a.buy {
    color: #2da1c1;
    font-size: small;
    text-decoration: none;
    position: absolute;
    right: 0;
}
a.buy:hover
{
    color: #f90;
    text-decoration: underline;         
}
like image 196
thirtydot Avatar answered Oct 06 '22 01:10

thirtydot


(1) you have float: left; on the example code (2) maybe if you add float: right; to the div it will help?

like image 33
RRStoyanov Avatar answered Oct 05 '22 23:10

RRStoyanov