繁体   English   中英

不完整的圆圈使用CSS与分隔符在中间与文本

[英]Incomplete circle using CSS with divider in middle with text

我试图通过一些文本将圆圈划分为中心。 但是使用css找不到任何解决方案。

我的HTML:

<div class="wrap">
    <div class="left">
    </div>
    <div class="right">
    </div>
</div>

我的CSS:

.right, .left {
    height: 200px;
    width: 200px;
    border: 1px solid #9F9F9F;
    float: left;
    margin: 2px;
}
.wrap {
    margin: auto;
    width: 420px;
    position: relative;
}
.left:after {
    content: "";
    display: inline-block;
    height: 60px;
    width: 6px;
    position: absolute;
    left: 203px;
    top: 65px;
    z-index: 99;
    background-color: #fff;
}
.right:before {
    content: "OR";
    border: 1px solid #9F9F9F;
    width: 50px;
    display: inline-block;
    border-radius: 50%;
    position: absolute;
    left: 175px;
    top: 65px;
    text-align: center;
    padding: 20px 5px;
}

小提琴: https//jsfiddle.net/2re8d0cv/

我想要的输出是:

这应该是出于

在查看我的代码和所需的输出后,您将理解。 我不想在那里使用图像。 因为它将解决问题我不能使用图像。 我想用完整的CSS制作它,但我也不知道它是否可能。

您可以通过添加另一个伪元素来实现此目的,以便单词“或”不与其他元素重叠。

在下面的例子中,我添加了一个新的.right:after几乎与.right:before相同,除了这个元素将是一个以更高的z-index显示文本的元素。

看到这个小提琴的更新版本

        .right:before {
            content:"";
            border: 1px solid #9F9F9F;
            width: 50px;
            height: 18px;
            display: inline-block;
            border-radius: 50%;
            position: absolute;
            left: 175px;
            top: 65px;
            text-align: center;
            padding: 20px 5px;
        }

       .right:after {
            content: "OR";
            width: 50px;
            display: inline-block;
            border-radius: 50%;
            position: absolute;
            left: 175px;
            top: 65px;
            text-align: center;
            padding: 20px 5px;
            z-index: 101
        }

编辑:但是,正如您所指出的,这会在圆的边界附近创建一个1像素的间隙 1像素间隙

我们必须添加第4个和最后一个伪元素来掩盖我们不想看到的其他元素的边界。

换句话说,我们之前的伪元素.right:after覆盖不需要的x轴线和新的.left:before覆盖y轴线.left:before

            .left:before {
            content: "";    
            display: inline-block;
            height: 58px;
            width: 6px;
            position: absolute;
            left: 203px;
            top: 66px;
            z-index: 99;
            background-color: #FFF;
        }

这里更新了小提琴

图像显示元素

SVG

这是使用<SVG>的解决方案

以下是它的外观:

在此输入图像描述

  • 使用路径元素绘制线条(在线条中心有一条曲线)
  • 将文本放在图像的中心。 然后看起来它在它们弯曲的线条的中心。

 .wrapper { height: 400px; } .right { float: right; display: inline-block; width: 45%; height: 100%; } .circlebetween { position: absolute; transform: translate(-50%, -50%); top: 50%; left: 50%; width: 20%; height: 100%; fill: white; stroke: #999; stroke-width: 0.7; } .left { float: left; display: inline-block; width: 45%; height: 100%; } 
 <div class="wrapper"> <div class="right">RIGHT</div> <svg class="circlebetween" viewBox="0 0 20 100" perserveAspectRatio="none"> <path d="M 7,0 7,35 A 15.1 15.1 0 0 0 7 65 V100" /> <path d="M13,0 13,35 A 15.1 15.1 0 0 1 13 65 V 100" /> <text x="50%" y="50%" dy=".3em" font-familiy="serif" stroke="none" fill="black" text-anchor="middle" transform="">OR</text> </svg> <div class="left">LEFT</div> </div> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM