border-radius: 20px; 會有圓角效果,但是效果是向外的;
效果截圖:(移動端展示也一樣)
想要實現 (邊框圓角內凹效果)
查閱資料,暫無屬性可設置,只能自己擼;(思路是實現四個圓角然後遮擋在四個邊角,實現。)
注意有坑
實現方案一
<html>
<head>
<meta name="viewport" content="width=750, user-scalable=no, viewport-fit=cover">
<meta charset="utf-8" />
<title></title>
<style type="text/css">
* {
box-sizing: border-box;
}
.box {
margin-top: 100px;
margin-left: 100px;
width: 200px;
height: 200px;
border: 1px solid red;
position: relative;
}
.border {
position: absolute;
width: 40px;
height: 40px;
border: 1px solid #fff;
z-index: 1;
background: #fff;
}
.ceshi {
position: relative;
border-radius: 0px 0px 40px 0px;
border-bottom: 1px solid red;
border-right: 1px solid red;
}
.left.top {
top: 0px;
left: 0px;
border-radius: 0px 0px 40px 0px;
border-bottom: 1px solid red;
border-right: 1px solid red;
}
.right.top {
top: -1px;
right: -1px;
border-radius: 0px 0px 0px 40px;
border-bottom: 1px solid red;
border-left: 1px solid red;
}
.left.bottom {
left: -1px;
bottom: -1px;
border-radius: 0px 40px 0px 0px;
border-top: 1px solid red;
border-right: 1px solid red;
}
.right.bottom {
right: -1px;
bottom: -1px;
border-radius: 40px 0px 0px 0px;
border-top: 1px solid red;
border-left: 1px solid red;
}
</style>
</head>
<body>
<div class="border ceshi"></div>
<div class="box">
<div class="border left top"></div>
<div class="border right top"></div>
<div class="border left bottom"></div>
<div class="border right bottom"></div>
</div>
</body>
</html>
效果如圖
pc 端效果沒啥問題
移動端 就有問題了,解決方案
(1、調整四個內部元素定位)
(2、.box 增加 border-radius: 53px; 值不等於 40px)
方案二:(增加一個共同父級,讓父級去約束)
<html>
<head>
<meta name="viewport" content="width=750, user-scalable=no, viewport-fit=cover">
<meta charset="utf-8" />
<title></title>
<style type="text/css">
* {
box-sizing: border-box;
}
.content {
position: relative;
margin-top: 100px;
margin-left: 100px;
width: 200px;
height: 200px;
/* overflow: hidden; */
}
.box {
width: 200px;
height: 200px;
border: 1px solid red;
}
.border {
position: absolute;
width: 80px;
height: 80px;
border: 1px solid red;
z-index: 1;
background: #fff;
border-radius: 50%;
}
.left.top {
top: -40px;
left: -40px;
}
</style>
</head>
<body>
<div class="content">
<div class="box">
</div>
<div class="border left top"></div>
</div>
</body>
</html>
截圖
開啓overflow:hidden;(不好的事情發生了)
多了兩條不想要的邊框
解決方案
只能 增加.content {border-radius: 50px;}
有其他好方案,歡迎各位大佬評論指點下。