【问题标题】:CSS :before and :after not working with my image [duplicate]CSS :before 和 :after 不使用我的图像 [重复]
【发布时间】:2022-10-24 21:58:14
【问题描述】:

我正在尝试将 :before 和 :after 与图像一起使用,但它不起作用。 我能得到你的帮助吗?

<div class="services" id="services">
        <div class="title">services</div>
        <p class="slogan">Don't be busy, be productive</p>
    <img class="image" src="/images/services.jpg" alt="services">
   

    .services .image {
    width: 250px;
    float: right;
    margin-right: 110px;
    position: relative;
}
.services .image::before {
    content: "";
    width: 200px;
    height: 200px;
    background-color: black;
    position: absolute;
    top: 0;
    right: -50px;
    z-index: -1;
}

【问题讨论】:

    标签: css css-selectors pseudo-element


    【解决方案1】:

    音频、画布、嵌入、iframe、img、输入、对象和视频等元素不支持 :after 和 :before 元素。这是因为在渲染时,它们的全部内容将被替换(包括伪元素)

    您可以尝试改用 js 或 jQuery。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-27
      • 2011-08-17
      • 1970-01-01
      • 2011-02-19
      • 2021-11-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多