Vik*_*ors 3 css css3 css-shapes
我正在尝试为下面的图片中显示的数字制作一个css块.我的想法/目标是制作一个响应块,如果有一个数字,它将是圆形的,如果两个则是第二个.我已经尝试过制作border-radius:50%所以我成功做第二块的第二块不像带有border-radius的图像:50%
所以我的问题是可以用一个类块或每个按钮(左|右)来产生这样的结果我需要为每个块写特殊类吗?

对于椭圆使用100%:
border-radius: 100%;
Run Code Online (Sandbox Code Playgroud)
对于体育场使用px中的大值:
border-radius: 9999px;
Run Code Online (Sandbox Code Playgroud)
border-radius: 100%;
Run Code Online (Sandbox Code Playgroud)
border-radius: 9999px;
Run Code Online (Sandbox Code Playgroud)
为此,您将需要一个"固定"高度(否则,您需要使用jquery计算).
你需要做的是这样的事情;
html,body{background:#222;}
div {
margin:10px;
display: inline-block;
height: 30px;
border-radius: 25px;
background: lightblue;
font-size: 30px;
min-width: 30px;
text-align: center;
line-height: 30px;
padding: 10px;
position:relative;
color:blue;
}
div:before{
content:"";
position:absolute;
left:0;
top:-10px;
width:100%;
border-top:3px solid tomato;
}Run Code Online (Sandbox Code Playgroud)
<div>1</div>
<div>123</div>Run Code Online (Sandbox Code Playgroud)
注意:border-radius应设置为整体高度的一半.
我还包括一个最小宽度,以确保它始终至少是一个圆圈.
$(document).ready(function() {
$('div').each(function(index) {
var height = $(this).height();
$(this).css("border-radius", height + "px");
});
});Run Code Online (Sandbox Code Playgroud)
html,
body {
background: #222;
}
div {
margin: 10px;
display: inline-block;
border-radius: 25px;
background: lightblue;
font-size: 30px;
min-width: 30px;
text-align: center;
line-height: 30px;
padding: 10px;
position: relative;
vertical-align:top;
color: blue;
}
div:before {
content: "";
position: absolute;
left: 0;
top: -10px;
width: 100%;
border-top: 3px solid tomato;
}Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>1</div>
<div>123</div>
<div>Not a set height,
<br/>either :)</div>Run Code Online (Sandbox Code Playgroud)