0

Link https://codepen.io/jabidgithub/pen/PoKZgeG

    <section class="sec--5">
        <a href="#" class="btn-ring">Naitours </a>
    </section>

Here after applying z-index on before pseudo element the pseudo element goes under the section element.

Why it is not going only under the .btn-ring element ??


.sec--5 {
  width: 100%;
    height: 100vh;
    display: grid;
    place-items: center;
    background: #eee;
}



.btn-ring {
    display: inline-block;
    text-transform: uppercase;
    text-decoration: none;
    font-size: 30px;
    padding: 20px 40px;
    color: #fff;
    background-color: rgb(42, 248, 255);
    border-radius: 50px;
    position: relative;
}

.btn-ring::before {
    content: "";
    display: inline-block;
    text-transform: uppercase;
    text-decoration: none;
    font-size: 30px;
    color: #fff;
    background-color: rgb(60, 91, 92);
    border-radius: 50px;
    width: 100%;
    height: 100%;
    position: absolute;
    top: 10%;
    left: 0;
    z-index: -1;
}
JabidHasan
  • 11
  • 1

1 Answers1

0

The problem you are encountering here is that ::behind item is created inside the a element, not beside it.

In order for this to work, you should be styling your elements slightly differently.

    <section class="sec--5">
      <a href="#" class="btn-ring">
        <span>Naitours </span>
      </a>
    </section>
.sec--5 {
  width: 100%;
    height: 100vh;
    display: grid;
    place-items: center;
    background: #eee;
}

span {
    display: inline-block;
    text-transform: uppercase;
    font-size: 30px;
    padding: 20px 40px;
    color: #fff;
    background-color: rgb(42, 248, 255);
    border-radius: 50px;
    position: relative;
}

a {
    text-decoration: none;
    position: relative;
}

a::before {
    content: "";
    display: inline-block;
    text-transform: uppercase;
    font-size: 30px;
    color: #aaa;
    background-color: rgb(60, 91, 92);
    border-radius: 50px;
    width: 100%;
    height: 100%;
    position: absolute;
    top: 10%;
    left: 0;
}
Arnas Savickas
  • 354
  • 3
  • 10