首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何将多个CSS属性同时添加到标签中?

如何将多个CSS属性同时添加到标签中?
EN

Stack Overflow用户
提问于 2018-07-21 20:18:25
回答 1查看 164关注 0票数 2

我正在尝试通过Appearance>Customize中的附加WordPress部件来修改我的CSS主题。

我希望entry-content类中的所有h1标记都是这样的:

所以我使用了下面的代码:

代码语言:javascript
复制
.entry-content h1 {
  background-color: #cfbc00;

    display: inline;
    background-color:#000000;
}

我希望整个块是彩色的#cfbc00和文本本身的背景是黑色的。但是浏览器不会同时对我的标签应用这些属性,它只应用其中一个属性。我该怎么办?

EN

回答 1

Stack Overflow用户

发布于 2018-07-21 20:31:13

如果您不能访问HTML代码,那么这里有一个CSS解决方法:

代码语言:javascript
复制
.entry-content
{
  position: relative;
}

.entry-content h1::before
{
  content: "";
  display: block;
  position: absolute;
  width: 100%;
  background-color: #cfbc00;
  height: 40px;
  z-index: -1;
}
.entry-content h1 {
    display: inline;
    background-color: #000000ad; /* Sets transparency according to sample image */
    top: 0;
    /* Line height to maintain the height of the :before element */
    line-height: 40px;
    color: #fff;
    font-size: 35px;
    padding: 5px;
}
代码语言:javascript
复制
<div class="entry-content">
<h1>Test title</h1>
</div>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51455996

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档