简体   繁体   中英

Incomplete circle using CSS with divider in middle with text

I am trying to make a circle being divided by the center with some text. But can not find any solution using css.

My HTML:

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

My 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;
}

Fiddle: https://jsfiddle.net/2re8d0cv/

My desired output is:

这应该是出于

After looking into my code and desired output you will understand. I don't want to use image there. as it will resolve problem I can not use image. I want to make it with full CSS only, but I also don't know if it is possible or not.

You can accomplish this by adding another pseudo element so that the word "or" is not overlapped by other elements.

In the example below I've added a new .right:after almost identical to .right:before , except this element will be the one to display the text at a higher z-index.

See this updated version of your fiddle .

        .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
        }

Edit: however, as you pointed out, this creates a 1 pixel gap near the border of the circle 1像素间隙

We have to add a 4th and final pseudo element to cover up the borders from other elements that we don't want to see.

In other words, our previous pseudo element .right:after covers up the unwanted x-axis lines and the new .left:before covers up the y-axis lines.

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

Updated fiddle here .

图像显示元素

SVG

Here is a solution using <SVG>

Here is how it looks:

在此输入图像描述

  • Used path elements to draw the lines (with a curve in the center of the line)
  • Placed the text in the center of the image. Then it looks like its in the center on the lines where they curve.

 .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> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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