css - 如何防止 h2 内容在 :before content? 中被破坏

标签 css

http://i.imgur.com/wsfUCxd.png

是的,我的 :before 图标有点问题。

我想要的是 h2 内容在水平线上,而不是在 :before 内容下的换行符之后。

有什么建议吗?

最佳答案

为图标使用 position:absolute;left:0; 并向 h2 添加图标大小的 padding-left。注意:不要忘记将 h2 的位置设置为 relative。

示例:

h2{
    position: relative;
    padding-left: 60px; /* the size of your icon plus a spacer */
}
h2:before{
    content:'';
    position:absolute;
    left:0;
    height: 50px;   /* height of your icon */
    width:50px;     /* width of your icon */
    background-image:url(img/icon.png); /* your icon */
}

关于css - 如何防止 h2 内容在 :before content? 中被破坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32200801/

相关文章:

CSS 问题,针对 IE8 中的字体大小

javascript - 鼠标悬停时如何避免div 'move'?

css - checkbox-inline 将复选框放在文本上而不是旁边

css - 如何覆盖 Flex 4 中的 Spark 主题?

html - 带有可变宽度元素的 overflow-x 容器

javascript - 查询 : Datepicker not centered

html - 网页在 iOS 7 中崩溃

css - 有什么方法可以将通过 SASS Bourbon 编译的 SCSS 代码反编译为可读格式?

html - 如果屏幕宽度小于特定宽度,则隐藏导航栏的某些链接

javascript - 带有可扩展部分的 Accordion