微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

html – CSS新手:如何对齐我的链接到页面的右侧?

我的索引页面上有一个链接
<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文件已经对页面上的其他元素生效了)

解决方法

尝试浮动:右:
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;         
}

原文地址:https://www.jb51.cc/html/224575.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐