html - Css Rotate 45 导致渐变边框中断

标签 html css rotation

我注意到旋转时 CSS 边框图像中有轻微的可见中断。有没有办法阻止这种或另一种方法来实现相同的解决方案? enter image description here

.box {
  margin: 150px;
  width: 250px;
  height: 250px;
  background: lightGray;
  border: 20px solid blue;
  border-image: linear-gradient(to right, #3acfd5 0%, #3a4ed5 100%);
  border-image-slice: 1;
  transform: rotate(45deg);
  display: flex;
  align-items: center;
  justify-content: center;
}

.r45 {
  transform: rotate(-45deg);
  color: red;
}
<div class="box">
  <p class="r45">Hello</p>
</div>

最佳答案

实现相同解决方案的另一种方法是使用 pseudo:after,如下面的工作示例所示,希望它有所帮助:)

.box {
  margin: 150px;
  width: 250px;
  height: 250px;
  background: linear-gradient(to right, #3acfd5 0%, #3a4ed5 100%);
  transform: rotate(45deg);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.box:after {
  left: 20px;
  right: 20px;
  top: 20px;
  bottom: 20px;
  content: '';
  background: lightGray;
  position: absolute;
}

.r45 {
  transform: rotate(-45deg);
  color: red;
  position: relative;
  z-index: 1;
}
<div class="box">
  <p class="r45">Hello</p>
</div>

关于html - Css Rotate 45 导致渐变边框中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52246520/

相关文章:

html - 响应头断点

css - 如何使我的字体大小响应?

css - 如何使用css自动将div block 流到下一行?

internet-explorer - IE10 和旋转图像的抗锯齿功能

c - 将绕任意轴的旋转解析为绕 X、Y 和 Z 轴的旋转

javascript - 将多个具有相同结构的html标签设置为下一个div的高度

javascript - 如何生成一个 Div 来填充一行?

html - 将鼠标悬停在表格内的目标 DIV

html - 基于 DOM 状态的条件 CSS 选择器

JavaFX 3D 旋转