html - 如何对齐插入:before method?的图标

标签 html css

如何垂直对齐使用 :before 方法插入的图标?

这是我的:

<div class="button submit">
  <a class="submit check_car_search" href="#" >Some Text</a>
</div>

CSS:

.button a{
    background: none;
    background-color: #32BBE7;
    text-indent:1px;
    color:#FFF;
    text-decoration: none;
    display: table-cell;
    vertical-align:middle;
    text-align:center;
    height: auto;
    padding: 10px;
    border-radius: 3px;
    font-weight: 600;
    font-size: 50px;
    font-style: italic;
}

.button a:hover{
    background-color: #2597F0;
}


.button a:before {
    content:url(http://i.stack.imgur.com/tKsDb.png);
    position: relative
}

JSFiddle:https://jsfiddle.net/1z83tc1o/

如何相对于文本垂直对齐图标?

最佳答案

可以使用background,设置大小(宽,高),然后可以使用vertical-align

CSS

.button a:before {
    position: relative;
    display: inline-block;
    width: 18px;
    height: 16px;
    vertical-align: middle;
    content:"";
    background: transparent url(http://i.stack.imgur.com/tKsDb.png) no-repeat center center;
    margin-right: 20px; // Optional

}

DEMO HERE

关于html - 如何对齐插入:before method?的图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34609717/

相关文章:

html - 在视差滚动布局上使用模态框时隐藏叠加层

jquery - VideoJS 5 视频播放器更改音量和进度条的命中框

css - li 菜单链接在页面加载时位于内容下方 + css

html - Bootstrap 列不居中

PHP:Bootstrap 单选按钮值未显示

html - 优化我的 CSS

html - FireFox 和 Chrome 显示不同的 html 页面

CSS 列表问题

html - 使用 Swift 在 iOS 上将带有 HTML 标记的描述转换为 NSAttributedString 时如何使用旧金山字体

css - 为什么 grid-template-row 在这里什么都不做?