Search code examples
htmlcsscss-transforms

Remove background outline on the side of the border after skew transform


HTML:

<div class="labels">
   <p>Very Funny</p>
</div>

CSS:

div.labels p {
  background: red;
  border-left: 2rem solid white;
  border-right: 2rem solid white;
  color: white;
  font-family: 'Bebas Neue';
  text-transform: uppercase;
  line-height: 0.8;
  transition: 0.4s ease all;
  font-size: 4rem;
  -webkit-text-stroke: 2px white;
  letter-spacing: 2px;
  width: fit-content;
  padding: 1rem 2rem;
  transform: skew(-10deg);
}

Here is the demo: https://jsfiddle.net/90vLp4ub/

You will notice that there is a thin red line around the element due to the background. How can I get rid of that?

Thanks.


Solution

  • To remove the red outlines and keep the animation, you can do this:

    1. Remove the borders left and right from p:hover
    2. Add some margin-left

    div.labels p:hover {
      background: red !important;
      margin-left: 30px;
    }
    div.labels p {
      color: white;
      font-family: 'Bebas Neue';
      text-transform: uppercase;
      line-height: 0.8;
      transition: 0.4s ease all;
      font-size: 4rem;
      -webkit-text-stroke: 2px white;
      letter-spacing: 2px;
      width: fit-content;
      padding: 1rem 2rem;
      transform: skew(-10deg);
    }
    <div class="labels">
       <p>Very Funny</p>
    </div>