html - 一个标签内有两个背景

标签 html css

我怎样才能在<h3> tag里面给两边背景

<h3>heading goes here</h3>

如下:

+---+--------------------------+------+
|>>>+ heading goes here        |<<<   +
+---+--------------------------+------+

像这样?

h3{
background: url('path') no-repeat left center;
background: url('path') no-repeat right center;
}

更新


好的,我是这样用的:

#custom-module .moduletable:nth-child(2) h3 {
    background: url(../images/icon-news.jpg)no-repeat center left;
    position: relative;
}
#custom-module .moduletable:nth-child(2) h3:after{
    background: url("../images/icon-news.jpg") no-repeat right center;
    content: " ";
    position: absolute;
    right: 0;
}

但在 :after 中使用了相同的背景图像伪没有显示。

最佳答案

有两种方法可以使用 CSS 实现多背景。

您可以使用 :before 和 :after 伪元素 ( tutorial with code )。

h3 {
  position: relative;
}
h3:before {
   content: "";
   position: absolute;
   top: 0; left: 10px;
   background: #4aa929;
}
h3:after {
   content: "";
   position: absolute;
   top: 0; right: 10px;
   background: #fff;
}

或者您可以使用 CSS3 的多背景功能 ( tutorial with code )。

h3 {
    background: url('path') no-repeat left center, 
                url('path') no-repeat right center;
}

关于html - 一个标签内有两个背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18680985/

相关文章:

html - Bootstrap 不会在一行中获得 4 个 DIV

javascript - CSS 帮助 : Autoplay 6 images in a loop

asp.net - 查找设计问题(html、css)

javascript - 如何从外部 HTML 覆盖已标记为 !important 的内联 CSS

html - Nginx 找到 css 但没有将其加载到 index.html

php - 需要一个正则表达式来将 css 类添加到第一个和最后一个列表项

css - 图像的自动标题不起作用 : img[title]:after{content:attr(title);}

html - 将 href 添加到表链接会产生额外的间距?

html - 当中心div的内容增加时,左右div的高度不增加

javascript - <ul> 上的 jQuery .appendTo() 适用于所有 <ul> 而不是指定的 <ul>