html - 从右中间开始带图标的数字

标签 html css

我有一个数字,我想在它旁边放一个星形图标,但在中间。

数字的字体大小可以改变,但星号应该留在中间。

例如:

enter image description here

这是我的CSS:

.my-container {
    display: inline-block;
}

.my-text {
    font-family: "Courier-new";
    font-size:20px
}

.my-icon {
    vertical-align: middle;
    font-size: 10px;
}

.my-container {
  display: inline-block;
}

.my-text {
  font-family: "Courier-new";
  font-size: 20px
}

.my-icon {
  vertical-align: middle;
  font-size: 10px;
}
<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.no-icons.min.css" rel="stylesheet"/>
<link href="http://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.min.css" rel="stylesheet"/>
<div class="my-container">
  <span class="my-text">5</span>
  <span class='icon icon-star my-icon'></span>
</div>

这是我的 jsfiddle:http://jsfiddle.net/k48ttuLn/

最佳答案

我会为此使用 flexbox。无论内容大小如何,它都会垂直居中。

.my-container {
  display: flex;
  align-items: center;
}

.my-text {
  font-family: "Courier-new";
  font-size: 20px
}

.my-icon {
  vertical-align: middle;
  font-size: 10px;
}
<div class="my-container">
  <span class="my-text">5</span>
  <span class='icon icon-star my-icon'></span>
</div>

参见 A guide to flexbox更多示例和教程

关于html - 从右中间开始带图标的数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40929802/

相关文章:

javascript - 我不能使用 Angularjs 在我的 index.html 中包含另一个 html 页面

css - 使用 CSS 使按钮出现在 Chrome/Webkit 浏览器中的“选择下拉”菜单上

forms - HTML5 的 novalidate 和 formnovalidate 属性有什么区别?

html - Angularjs-Slider onchange 事件未启动不起作用

CSS:解决 Chrome 中背面可见性错误的方法

html - 如何调整 3D CSS 立方体的大小

html - 基于 ul 的导航在 iOS Safari/Chrome 中不起作用

html - 添加多个类 html

html - css如何使列自动填充背景颜色到高度100%

html - 无论缩放如何,如何使聚光灯/阴影位置保持完全相同的相对水平中心位置?