Issue with inset Box-Shadow and Transform: Scale() on Chrome

316 Views Asked by At

I need to use inset Box-Shadow to simulate border, because I need to control how horizontal/vertical borders overlap if they have different colors.

Here I have a Top border only. However, Scale() and certain offsets causes a right/left borders to appear. This happens on Chrome, but not IE or Edge.

Screenshot

I understand this is related to sub-pixels. Is there a mitigation? Again, CSS border is not an option for me.

.element {
  position: absolute;
  left: 22px;
  top: 20px;
  width: 100px;
  height: 100px;
  background: yellow;
  box-shadow: inset 0 1px 0 0 red;
  padding: 5px;
  box-sizing: border-box;
}

.container {
  background: white;
  transform: scale(1.2);
  width: 200px;
  height: 200px;
}
<!DOCTYPE html>
<html>
  <body>
    <div class="container">
      <div class="element">ABCD</div>
    </div>
  </body>
</html>

Thanks!

1

There are 1 best solutions below

0
Jos van Weesel On

If you can't use a border on your .element, then why not create a pseudo-element to apply the border to? A transform: scale() would not change anything about how it looks.

*,
*::before {
  box-sizing: border-box;
}

.container {
  background: white;
  transform: scale(1.2);
  width: 200px;
  height: 200px;
}

.element {
  position: absolute;
  left: 22px;
  top: 20px;
  width: 100px;
  height: 100px;
  background: yellow;
  padding: 5px;
}

.element::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-top: 1px solid red;
}
<div class="container">
  <div class="element">ABCD</div>
</div>