我可以使用 CSS 来扭曲边框,使它们看起来像草图吗?

not*_*vvy 6 css css-transforms

我有带边框的框 ( div),我想让它看起来像草图,即边框不是画成直线,而是稍微扭曲,就像手绘一样。

插图:

“草图”盒子

这可以使用 CSS 转换或类似方法来完成吗?

Sil*_*eri 9

这篇关于手绘边框的文章给出了一个很好的例子,它通过使用大椭圆圆角(通过CSS border-radius属性)仅使用 CSS 在按钮上实现这种效果。它可能不适用于大型div元素。

改编自文章的示例:

button {
      background:transparent;
      padding:0.5rem 0.5rem;
      margin:0 0.5rem;
      font-size:1rem;

      border-top-left-radius: 255px 15px;
      border-top-right-radius: 15px 225px;
      border-bottom-right-radius: 225px 15px;
      border-bottom-left-radius:15px 255px;
}

button:hover{
   box-shadow:2px 8px 4px -6px hsla(0,0%,0%,.3);
}
button.lined.thick{
   border:solid 3px #41403E;
}
button.dotted.thick{
   border:dotted 3px #41403E;
}
button.dashed.thick{
  border:dashed 3px #41403E;
}
button.lined.thin{
   border:solid 2px #41403E;
}
button.dotted.thin{
   border:dotted 2px #41403E;
}
button.dashed.thin{
  border:dashed 2px #41403E;
}
Run Code Online (Sandbox Code Playgroud)
<button class='lined thick'>Lined Thick</button>
<button class='dotted thick'>Dotted Thick</button>
<button class='dashed thick'>Dashed Thick</button>
<div>&nbsp;</div>
<button class='lined thin'>Lined Thin</button>
<button class='dotted thin'>Dotted Thin</button>
<button class='dashed thin'>Dashed Thin</button>
Run Code Online (Sandbox Code Playgroud)


Kit*_*day 6

您可以使用CSS 边框图像

这是w3schools 网站上的示例

这是一个代码示例:

#borderimg {
    /* You can also use border-top or border-bottom to target the side you want affected */
    border: 10px solid transparent;
    padding: 15px;
    -webkit-border-image: url(border.png) 50 round; /* Safari 3.1-5 */
    -o-border-image: url(border.png) 50 round; /* Opera 11-12.1 */
    border-image: url(border.png) 50 round;
}
Run Code Online (Sandbox Code Playgroud)

  • 我认为 w3schools 的解释不是很好。我可以推荐[这篇文章](http://thenewcode.com/438/CSS-Border-Image-Explained),它给出了非常详细的解释。[本网站](http://border-image.com/) 提供了一个非常有用的工具,可以找到 border-image-slice 和其他属性的最佳值。 (3认同)