javascript - 我怎样才能把链接放在右边?

标签 javascript jquery html css

这是我的代码:

a{
    display: block;
    border: 3px solid #ffcb08;
    border-radius: 100px;
    text-align: center;
    color: #222;
    text-decoration: none;
    font-weight: 300;
    font-size: 20px;
    padding: 10px;
    box-sizing: border-box;
    margin-top: 15px;
    transition: all .3s;
    -webkit-transition: all .3s;
    -moz-transition: all .3s;
    width: 160px;
    float: right;
}

p{
    border: 1px solid;
}
<p>
some text here some text here some text here some text here some text here some text here some text here some text here some text here some text here some text here some text here some text here some text here some text here some text here some text here some text here some text here some text here some text here some text here.
<a href="#">Download</a>
</p>

我想做的就是将该按钮放在右侧,而不对其设置 position: absolute;。我该怎么做?

最佳答案

您可以通过多种方式做到这一点,这里是Flexbox方式:

text {
  display: flex;
  flex-direction: column; /* vertical stacking */
  /* align-items: flex-end; affects all flex-items */
}

a {
  align-self: flex-end; /* affects only this flex-item */
  display: block;
  border: 3px solid #ffcb08;
  border-radius: 100px;
  text-align: center;
  color: #222;
  text-decoration: none;
  font-weight: 300;
  font-size: 20px;
  padding: 10px;
  box-sizing: border-box;
  margin-top: 15px;
  transition: all .3s;
  -webkit-transition: all .3s;
  -moz-transition: all .3s;
  width: 160px;
}
<text>
  some text here some text here some text here some text here some text here some text here some text here some text here some text here some text here some text here some text here some text here some text here some text here some text here some text here some text here some text here some text here some text here some text here.
  <a href="#">Download</a>
</text>

关于javascript - 我怎样才能把链接放在右边?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47323543/

相关文章:

javascript - 如何更改CKEditor的编辑器大小?

javascript - 如何更改 reddit 的嵌入评论 iframe 的最大宽度?

javascript - Angular 1.6 : Factory issue initializing values

javascript - 在两个 flex 元素之间绘制箭头

javascript - 我想在点击选择大学后显示我的模态框,怎么办?

javascript - 在javascript中将ulong转换为8字节数组

javascript - 检测复选框在 Angular.js ng-change 事件中是否被选中或未被选中

javascript - 如何将 "attach"广告元素置于居中网站?

javascript - 我如何编写一个时钟来显示一天还剩多少时间?

html - 如何在生成的 HTML 表(带有 mysql 数据)中应用 CSS?