【问题标题】:Contents of ::before element unclickable::before元素的内容不可点击
【发布时间】:2019-02-15 13:50:21
【问题描述】:

*我正在使用 Bootstrap CSS 网格并在此练习中重置。我正在使用 Gutenberg 在 WordPress 中添加内容。请耐心等待,我的解释可能难以理解 - 英语不是我的第一语言。

--

所以我创建了一个顶部有两个边框的容器来创建一个倒置的金字塔。这显示了前一个容器的背景颜色和图像。我还在父容器中添加了一个对角渐变的图像,如下所示:

/*------------------------------------*\
    MAIN
\*------------------------------------*/

.header {
  position: relative;
  background: #2f2655;
  height: 500px;
}

.header:before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.1);
}

.header .logo {
  text-align: center;
  position: absolute;
  left: 0;
  bottom: 30px;
  width: 100%;
  padding: 20px 0;
  z-index: 5;
}

.header .logo a {
  display: inline-block;
  margin: 0 auto;
  text-decoration: none;
}

.header .logo a h1 {
  color: #fff;
}

.section {
  position: relative;
  overflow: hidden;
  margin-top: -20px;
  padding-top: 20px;
}

.section .surround {
  position: relative;
  padding-bottom: 40px;
}

.section .surround:before {
  content: "";
  position: absolute;
  left: -8px;
  width: 10%;
  height: 20px;
  top: -20px;
  background-color: #fff;
  -webkit-transform: skew(40deg);
  -moz-transform: skew(40deg);
  -o-transform: skew(40deg);
  -ms-transform: skew(40deg);
  transform: skew(40deg);
  z-index: 5;
}

.section .surround:after {
  content: "";
  position: absolute;
  right: -8px;
  width: 90%;
  height: 20px;
  top: -20px;
  background-color: #fff;
  -webkit-transform: skew(-40deg);
  -moz-transform: skew(-40deg);
  -o-transform: skew(-40deg);
  -ms-transform: skew(-40deg);
  transform: skew(-40deg);
  z-index: 5;
}

.section.blue-wrapper:before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  width: 100%;
  height: 100%;
  background-image: url(https://i.imgur.com/nnHq6IP.png);
  background-repeat: no-repeat;
  background-position: top right;
  z-index: 5;
}

.section.blue-wrapper .surround *:not(.btn-white) {
  color: #fff;
}

.section.blue-wrapper .surround,
.section.blue-wrapper .surround:before,
.section.blue-wrapper .surround:after {
  background-color: #00aeef;
  z-index: 4;
}

.section.grey-wrapper .surround,
.section.grey-wrapper .surround:before,
.section.grey-wrapper .surround:after {
  background-color: #e1e1e1;
}

.section .content {
  text-align: center;
  position: relative;
  padding: 20px 0;
}

.section.grey-wrapper .section-title {
  color: #777;
}


/*------------------------------------*\
    MISC
\*------------------------------------*/

*.btn-white {
  color: #fff;
  margin: 1rem 0;
  padding: 0.6rem 2.3rem;
  background: none;
  display: inline-block;
  border: 1px solid #fff;
  border-radius: 20px;
  text-decoration: none;
  transition: all 0.1s linear;
}

*.btn-white:hover {
  text-decoration: none;
  background: #fff;
  color: #0e0048;
}
<!doctype html>
<html lang="en-GB" class="no-js">

<head>
  <meta charset="UTF-8">
  <title>
    <?php wp_title(''); ?>
    <?php if(wp_title('', false)) { echo ' :'; } ?>
    <?php bloginfo('name'); ?>
  </title>


  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="description" content="">


</head>

<body class="home">

  <div id="mm-page">

    <!-- header -->
    <header class="header" role="banner" style="height: 200px;">

      <div class="header-items">

        <!-- logo -->
        <div class="logo">
          <a href="#">

            <h1>Logo</h1>

          </a>
        </div>
        <!-- /logo -->

      </div>

    </header>
    <!-- /header -->

    <div class="section blue-wrapper">

      <div class="surround">

        <div class="container">

          <div class="row">

            <div class="col-12">

              <article class="content">

                <h2 class="section-title">Coloured Wrapper</h2>

                <p>This is a sample text.</p>

                <a class="btn-white" href="#">Button</a>

              </article>

            </div>

          </div>

        </div>

      </div>

    </div>

    <div class="section grey-wrapper">

      <div class="surround">

        <div class="container">

          <div class="row">

            <div class="col-12">

              <section class="content">

                <h2 class="section-title" style="margin-bottom: 0;">Grey</h2>

              </section>

            </div>

          </div>

        </div>

      </div>

    </div>

我的问题是:::before 元素下方的任何内容都无法点击。在保持设计的同时我还有其他方法可以编码吗?

我尝试过的解决方案:

  • 在设置宽度为 380 像素之前设置 ::before,但这只能解决我在更大屏幕上的问题。
  • 改为在节类中添加背景图像。但右上角的边框与背景图像重叠 - 这不是我想要的结果。

【问题讨论】:

  • 尝试添加属性pointer-events: none
  • 哇!谢谢!我不知道那个属性。
  • 好,我会把它添加为 asnwer 然后@Hewlett

标签: html css


【解决方案1】:

::before 元素上使用属性pointer-events: none

【讨论】:

    【解决方案2】:

    谢谢你。这个问题现在有了答案。

    我在 ::before 元素中添加了pointer-events: none

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-07-06
      • 2018-09-03
      • 2019-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多