我尝试使div具有如下图所示的边框:
这就是我的尝试:
div {
height: 100px;
width: 100px;
border-bottom-right-radius:100px 10px;
border:1px solid #000;
}
<div></div>
实现这一目标的有效方法是什么?
答案 0 :(得分:27)
:before
and :after
:before
:其高度与边界半径相同
由于top
left
的外面,与左边界对齐
其宽度以calc
计算,以精确排列曲线的顶部
可以使用transform: skewX(-60deg)
:after
:calc
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;
}
&#13;
<div></div>
&#13;
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;
}
&#13;
<div></div>
&#13;
答案 1 :(得分:7)
我可以使用DIV来做到这一点,但我很确定存在一种更优雅的方式:
#container {
border:none;
height:100px;
border-right: solid 1px #000;
}
#square_top {
border-bottom-right-radius:100px 10px;
border:none;
border-bottom: solid 1px #000;
height:10px;
}
#square_bottom {
border-bottom-right-radius:100px 10px;
border:none;
border-bottom: solid 1px #000;
border-right:solid 1px #000;
border-left:solid 1px #000;
height:10px;
}
#square {
height: 90px;
border-left:solid 1px #000;
}
<div id="container">
<div id="square_top"></div>
<div id="square">TEXT HERE</div>
</div>
<div id="square_bottom"></div>
答案 2 :(得分:4)
虽然CSS可以做到这一点,但还有另一种方法可以提供更大的灵活性: SVG
这种方法允许:
body {background: url('http://lorempixel.com/output/people-q-g-640-480-9.jpg');background-size: cover;}
div {
position: relative;
width: 30%;
padding: 5%;
color: #fff;
text-align: center;
}
svg {
position: absolute;
top: 0; left: 0;
width: 100%; height: 100%;
z-index: -1;
}
<div>
<p>Some text</p>
<p>Some text</p>
<p>Some text</p>
<p>Some text</p>
<p>Some text</p>
<p>Some text</p>
<p>Some text</p>
<p>Some text</p>
<p>Some text</p>
<svg viewbox="0 0 50 100" preserveAspectRatio="none">
<path d="M1 9 C49 10 49 1 49 1 V90 C49 91 49 99 1 99z" stroke-width="0.5" stroke="#000" fill-opacity="0.5" />
</svg>
</div>