ame*_*uri 1 css graphics html5 css3 css-shapes
有没有办法创建一个圆形按钮,如图所示使用CSS(不使用Canvas或SVG)?
编辑:我不是在谈论border-radius,请看图片
这可以使用:after
和:before
:伪元素.
div {
position: relative;
margin: 30px;
width: 150px;
height: 100px;
background: #FF5656;
border-radius: 1000px / 200px;
}
div:after, div:before {
position: absolute;
content: '';
width: 10px;
height: 72%;
border-top-left-radius: 200px 1000px;
border-bottom-left-radius: 200px 1000px;
left: -6px;
top: 14%;
background: #FF5656;
}
div:after {
border-radius: 0;
border-top-right-radius: 200px 1000px;
border-bottom-right-radius: 200px 1000px;
left: calc(100% - 4px);
}
Run Code Online (Sandbox Code Playgroud)
<div></div>
Run Code Online (Sandbox Code Playgroud)
input
元素:因为,您不能将:伪元素应用于input
元素,您必须将:after
and :before
:pseudo元素应用于其容器.
input {
width: 150px;
height: 100px;
background: #FF5656;
border-radius: 1000px / 200px;
border: 0;
cursor: pointer;
color: black;
font-size: 16px;
}
input::-moz-focus-inner {
border: 0;
}
input:focus {
outline: none;
}
.btn-container {
position: relative;
width: 150px;
height: 100px;
margin: 30px;
}
.btn-container:after,
.btn-container:before {
position: absolute;
content: '';
width: 10px;
height: 72%;
border-top-left-radius: 200px 1000px;
border-bottom-left-radius: 200px 1000px;
left: -6px;
top: 14%;
background: #FF5656;
}
.btn-container:after {
border-radius: 0;
border-top-right-radius: 200px 1000px;
border-bottom-right-radius: 200px 1000px;
left: calc(100% - 4px);
}
Run Code Online (Sandbox Code Playgroud)
<div class="btn-container">
<input type="button" value="Button" />
</div>
Run Code Online (Sandbox Code Playgroud)
正如@ misterManSam在评论中提到的那样,你也可以使用一个button
元素来避免使用容器.
button {
position: relative;
width: 150px;
height: 100px;
background: #FF5656;
border-radius: 1000px / 200px;
border: 0;
cursor: pointer;
color: black;
font-size: 16px;
}
button::-moz-focus-inner {
border: 0;
}
button:focus {
outline: none;
}
button:after,
button:before {
position: absolute;
content: '';
width: 10px;
height: 72%;
border-top-left-radius: 200px 1000px;
border-bottom-left-radius: 200px 1000px;
left: -6px;
top: 14%;
background: #FF5656;
}
button:after {
border-radius: 0;
border-top-right-radius: 200px 1000px;
border-bottom-right-radius: 200px 1000px;
left: calc(100% - 4px);
}
Run Code Online (Sandbox Code Playgroud)
<button>Button</button>
Run Code Online (Sandbox Code Playgroud)