:: before元素的内容不可点击

时间:2019-02-15 13:50:21

标签: html css

*我正在使用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元素下方的所有内容均不可单击。在保持设计的同时,还有其他方法可以编码吗?

我尝试过的解决方案:

  • 在设置宽度380px之前给出::,但这只能解决较大屏幕的问题。
  • 在部分类中添加背景图像。但是右上角的边框却与背景图像重叠了,而不是我想要的结果。

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:0)

谢谢你arieljuod。现在已经回答了这个问题。

我已经在:: before元素内添加了pointer-events: none