【问题标题】:How to add multiple CSS attributes to a tag simultaneously?如何同时向标签添加多个 CSS 属性?
【发布时间】:2018-12-29 13:26:27
【问题描述】:

我正在尝试通过 Appearance>Customize 中的 Additional CSS 部分以我想要的方式修改我的 WordPress 主题。

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

所以我使用了这个代码:

.entry-content h1 {
  background-color: #cfbc00;

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

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

【问题讨论】:

  • html代码在哪里?
  • @thebrownkid html 代码是我作为 wp 帖子编写的文本。它的所有动态

标签: css wordpress wordpress-theming


【解决方案1】:

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

.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;
}
<div class="entry-content">
<h1>Test title</h1>
</div>

【讨论】:

  • 谢谢。该代码几乎可以正常工作。但它有一个问题,当我删除 z-index 属性时,该行覆盖了文本。使用 z-index 属性,我遇到了我之前在问题中提出的相同问题
  • 您能否提供其外观的屏幕截图,或者如果在服务器上则更好地提供指向该站点的链接?
猜你喜欢
  • 2011-03-08
  • 1970-01-01
  • 2022-06-24
  • 2014-04-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-08-09
相关资源
最近更新 更多