边界半径间隙

时间:2019-07-05 08:47:51

标签: html css

我在div中添加了边框和边框半径。在该div内有::before,它继承了border-radius的{​​{1}},但边框显示不正确。有明显的缝隙。

.wrapper
.wrapper {
  width: 500px;
  height: 200px;
  border: 10px solid black;
  border-radius: 40px;
  background-color: #ccc;
  overflow: hidden;
  position: relative;
}

.wrapper::before {
  border: 2px solid red;
  box-shadow: 0 0 2px rgba(1, 117, 255, 0.9);
  opacity: 1;
  border-radius: inherit;
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
}

这可以通过CSS来解决吗?

1 个答案:

答案 0 :(得分:-1)

对于您当前的布局,border-radius: 30px;的{​​{1}}适用:

::before
.wrapper {
  width: 500px;
  height: 200px;
  border: 10px solid black;
  border-radius: 40px;
  background-color: #ccc;
  overflow: hidden;
  position: relative;
}

.wrapper::before {
  border: 2px solid red;
  box-shadow: 0 0 2px rgba(1, 117, 255, 0.9);
  border-radius: 30px;
  opacity: 1;
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
}