【问题标题】:Two backgrounds horizontal in div one rounded div两个背景水平在 div 一个圆形 div
【发布时间】:2015-10-26 08:48:53
【问题描述】:

我在一个带有边框半径的 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> 

但我有一个小错误,在 after 元素中,我看到第一个 div 的一些蓝色背景线。它看起来像从半径生成的边界线。但我想要一个干净的白色圆形背景。

Codepen 上一页 :http://codepen.io/michal_t/pen/KdoZYz/

【问题讨论】:

标签: html css pseudo-element


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    您可以通过从.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;
    }
    

    http://codepen.io/anon/pen/dYmdva

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-09-24
      • 2012-05-02
      • 2014-05-22
      • 2019-01-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多