How will I use :: after to make an arrow on my button?

I can create an arrow button on the right side like this:

.next-button {
    font-family: 'Source Sans Pro', Arial, Helvetica, sans-serif;
    text-decoration: none;
    color: #fff;
    text-align: center;
    border: none;
    background-color: #2399e5;
    display: inline-block;
    height: 36px;
    line-height: 36px;
    padding: 0 1rem;
}

.next-point{
    vertical-align: top;
    width: 0;
    height: 0;
    display: inline-block;
    border-top: 18px solid transparent;
    border-bottom: 18px solid transparent;
    
    border-left: 18px solid #2399e5;
    border-right: 18px solid transparent;
}
<div>
<button class="next-button" type="button">Next</button><div class="next-point"></div>
</div>
Run code

... but if I try to do this using :: after it just doesn't work. Here is how I tried this:

.next-button {
    font-family: 'Source Sans Pro', Arial, Helvetica, sans-serif;
    text-decoration: none;
    color: #fff;
    text-align: center;
    border: none;
    background-color: #2399e5;
    display: inline-block;
    height: 36px;
    line-height: 36px;
    padding: 0 1rem;
}

.next-button::after{
    content: " ";
    vertical-align: top;
    width: 0;
    height: 0;
    display: inline-block;
    border-top: 18px solid transparent;
    border-bottom: 18px solid transparent;
    
    border-left: 18px solid #2399e5;
    border-right: 18px solid transparent;
}
<div>
<button class="next-button" type="button">Next</button>
</div>
Run code

I have been doing this for a long time, and I clearly don’t understand how to use it ::after. How would I search for a button in my first snippet using ::afterinstead of creating a separate div?

+4
source share
2 answers

- .next-button, . , , right (width = 36px → right = -36px).

.next-button {
  position: relative;
  font-family: 'Source Sans Pro', Arial, Helvetica, sans-serif;
  text-decoration: none;
  color: #fff;
  text-align: center;
  border: none;
  background-color: #2399e5;
  display: inline-block;
  height: 36px;
  line-height: 36px;
  padding: 0 1rem;
}

.next-button::after {
  position: absolute;
  content: "";
  top: 0;
  right: -36px;
  width: 0;
  height: 0;
  display: inline-block;
  border-top: 18px solid transparent;
  border-bottom: 18px solid transparent;
  border-left: 18px solid #2399e5;
  border-right: 18px solid transparent;
}
<div>
  <button class="next-button" type="button">Next</button>
</div>

translateX(100%) , .

.next-button {
  position: relative;
  font-family: 'Source Sans Pro', Arial, Helvetica, sans-serif;
  text-decoration: none;
  color: #fff;
  text-align: center;
  border: none;
  background-color: #2399e5;
  display: inline-block;
  height: 36px;
  line-height: 36px;
  padding: 0 1rem;
}

.next-button::after {
  position: absolute;
  content: "";
  top: 0;
  right: 0;
  transform: translateX(100%);
  width: 0;
  height: 0;
  display: inline-block;
  border-top: 18px solid transparent;
  border-bottom: 18px solid transparent;
  border-left: 18px solid #2399e5;
  border-right: 18px solid transparent;
}
<div>
  <button class="next-button" type="button">Next</button>
</div>
+6

- , :

.arrow-clip{
      clip-path: polygon(0% 0%, 80% 0, 100% 50%, 80% 100%, 0% 100%);
      background-color: #2399e5;
      color: #fff;
      padding: 0.2rem 2rem;
      border: 0px;
}
<button class="arrow-clip">Next</button>

, , , .

0

Source: https://habr.com/ru/post/1682974/


All Articles