两个背景水平 div 一个圆形 div
Two backgrounds horizontal in div one rounded div
我在将两个水平背景合二为一 div 时遇到了一个小问题,边框半径。我想要主要 div 是一个圆圈。
我的代码
body{
text-align: center;
}
.split-outer {
position: relative;
display: inline-block;
width: 200px;
height: 200px;
z-index: 2;
background: #014495;
border-radius: 100%;
}
.split-outer::after{
content: "";
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: 50%;
z-index: -1;
background: #fff;
border-bottom-right-radius: 200px;
border-bottom-left-radius: 200px;
}
.split-inner{
width: 200px;
height: 200px;
margin: 0 auto;
color: #fff;
text-align: center;
}
span{
display: block;
}
span.split-title{
padding: 30px 0 10px 0;
font-size: 55px;
text-align: center;
line-height: 55px;
}
span.split-content{
padding: 20px 0;
font-size:18px;
color: #014495;
}
<div class="container-fliud">
<div class="jumbotron">
<div class="split-outer">
<div class="split-inner">
<span class="split-title">100</span>
<span class="split-content">Lorem ipsum</span>
<button type="button" class="btn btn-primary btn-sm">Button</button>
</div>
</div>
</div>
</div>
但是我有一个小错误,在后面的元素中我看到第一个 div 的一些蓝色背景线。它看起来像是从半径生成的边界线。但是我想要一个干净的白色圆形背景。
Codepen 上一个:http://codepen.io/michal_t/pen/KdoZYz/
将 border: 2px solid white
放入 :after
。
这是css代码:
body {
text-align: center;
}
.split-outer {
position: relative;
display: inline-block;
width: 200px;
height: 200px;
z-index: 2;
background: #014495;
border-radius: 100%;
}
.split-outer::after {
content: "";
position: absolute;
left: -2px;
bottom: -1px;
width: 100%;
height: 50%;
z-index: -1;
background: #fff;
border-bottom-right-radius: 200px;
border-bottom-left-radius: 200px;
border: 2px solid white;
}
.split-inner {
width: 200px;
height: 200px;
margin: 0 auto;
color: #fff;
text-align: center;
}
span {
display: block;
}
span.split-title {
padding: 30px 0 10px 0;
font-size: 55px;
text-align: center;
line-height: 55px;
}
span.split-content {
padding: 20px 0;
font-size: 18px;
color: #014495;
}
这里是fiddle。
您可以通过从 .split-outer
中删除背景颜色然后使用 :before 伪造来创建背景的上半部分,类似于使用 :after 伪造创建下半部分的方式。
.split-outer:before {
content: "";
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 50%;
z-index: -1;
background: #014495;
background-image: initial;
background-position-x: initial;
background-position-y: initial;
background-size: initial;
background-repeat-x: initial;
background-repeat-y: initial;
background-attachment: initial;
background-origin: initial;
background-clip: initial;
background-color: #014495;
border-top-right-radius: 200px;
border-top-left-radius: 200px;
}
我在将两个水平背景合二为一 div 时遇到了一个小问题,边框半径。我想要主要 div 是一个圆圈。
我的代码
body{
text-align: center;
}
.split-outer {
position: relative;
display: inline-block;
width: 200px;
height: 200px;
z-index: 2;
background: #014495;
border-radius: 100%;
}
.split-outer::after{
content: "";
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: 50%;
z-index: -1;
background: #fff;
border-bottom-right-radius: 200px;
border-bottom-left-radius: 200px;
}
.split-inner{
width: 200px;
height: 200px;
margin: 0 auto;
color: #fff;
text-align: center;
}
span{
display: block;
}
span.split-title{
padding: 30px 0 10px 0;
font-size: 55px;
text-align: center;
line-height: 55px;
}
span.split-content{
padding: 20px 0;
font-size:18px;
color: #014495;
}
<div class="container-fliud">
<div class="jumbotron">
<div class="split-outer">
<div class="split-inner">
<span class="split-title">100</span>
<span class="split-content">Lorem ipsum</span>
<button type="button" class="btn btn-primary btn-sm">Button</button>
</div>
</div>
</div>
</div>
但是我有一个小错误,在后面的元素中我看到第一个 div 的一些蓝色背景线。它看起来像是从半径生成的边界线。但是我想要一个干净的白色圆形背景。
Codepen 上一个:http://codepen.io/michal_t/pen/KdoZYz/
将 border: 2px solid white
放入 :after
。
这是css代码:
body {
text-align: center;
}
.split-outer {
position: relative;
display: inline-block;
width: 200px;
height: 200px;
z-index: 2;
background: #014495;
border-radius: 100%;
}
.split-outer::after {
content: "";
position: absolute;
left: -2px;
bottom: -1px;
width: 100%;
height: 50%;
z-index: -1;
background: #fff;
border-bottom-right-radius: 200px;
border-bottom-left-radius: 200px;
border: 2px solid white;
}
.split-inner {
width: 200px;
height: 200px;
margin: 0 auto;
color: #fff;
text-align: center;
}
span {
display: block;
}
span.split-title {
padding: 30px 0 10px 0;
font-size: 55px;
text-align: center;
line-height: 55px;
}
span.split-content {
padding: 20px 0;
font-size: 18px;
color: #014495;
}
这里是fiddle。
您可以通过从 .split-outer
中删除背景颜色然后使用 :before 伪造来创建背景的上半部分,类似于使用 :after 伪造创建下半部分的方式。
.split-outer:before {
content: "";
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 50%;
z-index: -1;
background: #014495;
background-image: initial;
background-position-x: initial;
background-position-y: initial;
background-size: initial;
background-repeat-x: initial;
background-repeat-y: initial;
background-attachment: initial;
background-origin: initial;
background-clip: initial;
background-color: #014495;
border-top-right-radius: 200px;
border-top-left-radius: 200px;
}