CSS newbie: Как выровнять мою ссылку в правой части страницы?
У меня есть ссылка на моей индексной странице:
<div class="content">
<a class="buy" href="buy.html">Buy</a>
</div>
Я хотел бы выровнять его с правой стороны моей страницы, я попробовал:
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;
}
Но он все еще расположен с левой стороны. (Я включил свой файл CSS в свой index.html, и файл CSS уже вступил в силу для других элементов на странице)
Ответы
Ответ 1
Попробуйте float: right
:
a.buy {
color: #2da1c1;
font-size: small;
text-decoration: none;
float: right;
}
a.buy:hover
{
color: #f90;
text-decoration: underline;
}
Другой способ:
.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;
}
Ответ 2
(1) у вас есть float: left;
на примере кода
(2) возможно, если вы добавите float: right;
в div, это поможет?
Ответ 3
Попробуйте следующее:
a.buy{
color: #2da1c1;
font-size: small;
text-decoration: none;
float: right;
}
a.buy:hover
{
color: #f90;
text-decoration: underline;
}
Ответ 4
Вы также можете попробовать:
.content
{
text-align: right;
}