微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

css – 如何使边框半径曲线向外?

我试图使一个div有如下图所示的边框:

这是我试过的:

div {
    height: 100px;
    width: 100px;
    border-bottom-right-radius:100px 10px;
    border:1px solid #000;
}
<div></div>

实现这一目标的一种效果是什么?

解决方法

使用 :before and :after

顶部边框是用以下创建的:before:

>它的高度与边界半径相同
>由于左侧,它位于外侧,顶部与左边界线排列
>其宽度用calc计算,精确地排列在曲线的顶部
>曲线可以通过变换来改进:skewX(-60deg)

左边框是用以下内容创建的:after:

>给出一个100%的高度减去前面的高度和边界的厚度与calc

例子

数字1 – 有点尖

div {
  border-bottom-right-radius: 100px 20px;
  border: 1px solid #000;
  border-top: none;
  height: 500px;
  width: 200px;
  position: relative;
  border-left: none;
}
div:before,div:after {
  content: '';
  display: block;
  position: absolute;
  left: -1px;
}
div:before {
  height: 20px;
  width: 100%;
  width: calc(100% + 1px);
  border-bottom-right-radius: 100px 20px;
  border-bottom: 1px solid #000;
  border-right: solid 1px #000;
  top: -1px;
}
div:after {
  height: calc(100% - 18px);
  border-left: 1px solid #000;
  top: 19px;
}
<div></div>

数字2 – 偏斜的平滑点

div {
  border-bottom-right-radius: 100px 20px;
  border: 1px solid #000;
  border-top: none;
  height: 200px;
  width: 200px;
  position: relative;
  border-left: none;
}
div:before,div:after {
  content: '';
  display: block;
  position: absolute;
  left: -1px;
}
div:before {
  height: 20px;
  width: 100%;
  width: calc(100% - 36px);
  border-bottom-right-radius: 100px 20px;
  border-bottom: 1px solid #000;
  border-right: solid 2px #000;
  top: 0px;
  left: 17px;
  transform: skewX(-60deg);
}
div:after {
  height: calc(100% - 19px);
  border-left: 1px solid #000;
  top: 20px;
}
<div></div>

原文地址:https://www.jb51.cc/css/219582.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。