html - div 中的图标定位 - 忽略文本空格

标签 html css glyphicons

我试图在带有文本的 div 中放置一个图标。

无论里面有多少行文本,图标都应该固定在右上角。我怎样才能做到这一点?

.box {
  padding: 5px;
  width: 160px;
  height: 50px;
  margin-bottom: 30px;
  background-color: blue;
  line-height: 20px;
  color: white;
}

span {
  color: red;
  display: inline;
  float: right;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">

<div class="box">
  This is a sample text inside a sample box. 
  <span class="glyphicon glyphicon-plus"></span>
</div>
<div class="box">
  This is a sample text. 
  <span class="glyphicon glyphicon-plus"></span>
</div>

Fiddle

最佳答案

将此添加到您的 CSS

.box{
    display: flex;
}
span{
    margin-left: auto
}

关于html - div 中的图标定位 - 忽略文本空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48225362/

相关文章:

css - 如何删除 <a> 标签底部的空格?

twitter-bootstrap - 字形和 bootstrap 4

javascript - 左侧的文本溢出省略号

html - 你如何制作 :visited bold in XHTML/CSS?

html - "#"像这样使用时的含义 href ="#"

html - 如何将 Visual Studio Code 上的本地网站推送到我部署在 Azure 上的 Web 应用程序

twitter-bootstrap - 如何下载 twitter bootstrap 字形?

jquery - Twitter Bootstrap 3.0 崩溃时图标发生变化

html - 是否可以在表单提交按钮中使用 Glychicons?

javascript - 使用javascript检查服务器上是否存在html文件