html - 如何使用CSS水平对齐图标?

标签 html css

我有这个 html 标记,我想将我在 sprite 中的图标水平居中,它有 15% 的图标和 85% 的信息数据类。我想将图标居中对齐。

<div class="col-xs-12 mf-item">
<div class="ico icon-theme"></div>
<div class="info-data">Theme</div>
</div>

.mf-item {
    background-color: #ffffff;
    display: inline-block;
    height: auto;
    margin-left: 0;
    min-height: 30px;
}

.ico {
    display: inline-block;
    line-height: 30px;
    margin: 0 auto;
    padding-right: 5px;
    text-align: center;
    vertical-align: middle;
    width: 15%;
}

.info-data {
    border-bottom: 1px solid #0f8ccd;
    display: inline-block;
    line-height: 30px;
    margin: 0;
    width: 85%;
}

.icon-theme {
    background-position: 0 -90px;
    height: 30px;
    width: 23px;
}

任何帮助将不胜感激!!!! 谢谢!

最佳答案

您缺少 float:left 样式。我会这样做

* {
  box-sizing: border-box;
}

.mf-item {
    background-color: #ffffff;
    display: inline-block;
    height: auto;
    margin-left: 0;
    min-height: 30px;
    width:100%;
}

.ico {
    display: inline-block;
    height: 30px;
    margin: 0 auto;
    padding-right: 5px;
    text-align: center;
    vertical-align: middle;
    width: 15%;
    float:left;    
}

.info-data {
    border-bottom: 1px solid #0f8ccd;
    display: inline-block;
    line-height: 30px;
    margin: 0;
    width: 85%; 
    float:left;
}

.icon-theme {
    background-position: 0 -90px;
    height: 30px;
    width: 23px;
    display:block;
margin:0 auto;

    background-color:red; //your background image imaging
}
<div class="col-xs-12 mf-item">
  <div class="ico"><span class="icon-theme"></span></div>
  <div class="info-data">Theme</div>
</div>

关于html - 如何使用CSS水平对齐图标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35580374/

相关文章:

javascript - 如何使用 CSS 在静止背景图像上创建滚动窗口?

jquery - 模型形态,我该怎么做

html - 为什么我的整个下拉列表没有显示?

html - 导航菜单中间的中心标志

CSS - 尝试在浏览器调整大小时将链接保留在顶部导航栏内

html - Flexbox:文本没有按比例缩小

html - Flexbox 对齐内容 : Right not applying

Javascript 包含的函数在所有条件下都返回 false。只有其他部分被执行

jquery - 带有 jQ​​uery Parallax 的 Buggy 滚动

c# - 在 emptydata 模板 gridview 中使用客户端脚本代码