简体   繁体   English

CSS半圆效应

[英]CSS semi-circle effect

I am trying to create a unique shape using solely CSS. 我正在尝试使用CSS创建一个独特的形状。

Here is what I have so far: http://jsfiddle.net/u6vu96u8/ 这是我到目前为止: http//jsfiddle.net/u6vu96u8/

However, there is too much flat at the base of the semi-circle. 但是,在半圆的底部有太多的flat Is it possible, I can just get the curves to meet exactly in the middle without the flat line? 是否有可能,我可以让曲线在没有扁线的情况下恰好在中间相遇?

Code: 码:

 button { font-size: 1em; background: #ffffff; border-radius: 10px; -moz-border-radius: 10px; -webkit-border-radius: 10px; border: 1px solid #1588cb; color: #1588cb; font-weight: 400; height: 60px; width: 300px; position: relative; margin: 25px 0 50px 0; -webkit-box-sizing: content-box; -moz-box-sizing: content-box; -o-box-sizing: content-box; box-sizing: content-box; } .full-circle { border: 1px solid #1588cb; height: 35px; width: 45px; -moz-border-radius: 30px; -webkit-border-radius: 30px; -webkit-box-sizing: content-box; -moz-box-sizing: content-box; -o-box-sizing: content-box; box-sizing: content-box; border-radius: 0 0 45px 45px; border-top: none; height: 15px; background: #ffffff; position: absolute; left: 50%; margin-left: -17px; bottom: -16px; line-height: 0; } 
 <button>News <span class="full-circle">+</span> </button> 

Your full-circle class has a width of 45px, whereas it has a border radius of 30px. 您的全圆类的宽度为45px,而边界半径为30px。 If you want it to be a semicircle, you need the same border radius as width. 如果希望它是半圆,则需要与宽度相同的边界半径。 Changing the width to 30px appears to do what you want (try it) 将宽度更改为30px似乎可以做到你想要的(尝试)

You can play with height and bottom css properties for the .full-circle class 您可以使用.full-circle类的高度和底部css属性

 button { font-size: 1em; background: #ffffff; border-radius: 10px; -moz-border-radius: 10px; -webkit-border-radius: 10px; border: 1px solid #1588cb; color: #1588cb; font-weight: 400; height: 60px; width: 300px; position: relative; margin: 25px 0 50px 0; -webkit-box-sizing: content-box; -moz-box-sizing: content-box; -o-box-sizing: content-box; box-sizing: content-box; } .full-circle { border: 1px solid #1588cb; height: 35px; width: 45px; -moz-border-radius: 30px; -webkit-border-radius: 30px; -webkit-box-sizing: content-box; -moz-box-sizing: content-box; -o-box-sizing: content-box; box-sizing: content-box; border-radius: 0 0 45px 45px; border-top: none; height: 19px; background: #ffffff; position: absolute; left: 50%; margin-left: -17px; bottom: -20px; line-height: 0; } 
 <button>News<span class="full-circle">+</span></button> 

Fiddle 小提琴

You could decrease the width to match the border-radius. 您可以减小宽度以匹配border-radius。

 button { font-size: 1em; background: #ffffff; border-radius: 10px; -moz-border-radius: 10px; -webkit-border-radius: 10px; border: 1px solid #1588cb; color: #1588cb; font-weight: 400; height: 60px; width: 300px; position: relative; margin: 25px 0 50px 0; -webkit-box-sizing: content-box; -moz-box-sizing: content-box; -o-box-sizing: content-box; box-sizing: content-box; } .full-circle { border: 1px solid #1588cb; height: 15px; width: 30px; -moz-border-radius: 30px; -webkit-border-radius: 30px; -webkit-box-sizing: content-box; -moz-box-sizing: content-box; -o-box-sizing: content-box; box-sizing: content-box; border-radius: 0 0 45px 45px; border-top: none; background: #ffffff; position: absolute; left: 50%; margin-left: -17px; bottom: -16px; line-height: 0; } 
 <button>News<span class="full-circle">+</span></button> 

You have 2 height attributes on the full-circle class, was a bit confusing until I removed the first one. 你在全圆类上有2个高度属性,在删除第一个属性之前有点令人困惑。

button {
    font-size: 1em;
    background: #fff;
    border-radius: 10px;
    -moz-border-radius: 10px;
    -webkit-border-radius: 10px;
    border: 1px solid #1588cb;
    color: #1588cb;
    font-weight: 400;
    height: 60px;
    width: 300px;
    position: relative;
    margin: 25px 0 50px 0;
    -webkit-box-sizing: content-box;
    -moz-box-sizing: content-box;
    -o-box-sizing: content-box;
    box-sizing: content-box;
}

.full-circle {
    display:block;
    border: 1px solid #1588cb;
    width: 45px;
    -moz-border-radius: 30px;
    -webkit-border-radius: 30px;
    -webkit-box-sizing: content-box;
    -moz-box-sizing: content-box;
    -o-box-sizing: content-box;
    box-sizing: content-box;
    border-radius: 0 0 60px 60px;
    border-top: none;
    height: 25px;
    background: #fff;
    position: absolute;
    left: 50%;
    margin-left: -17px;
    bottom: -26px;
    line-height: 0;
}

https://jsfiddle.net/hj3g3gjL/ https://jsfiddle.net/hj3g3gjL/


Update: 更新:

I sort of got it working... Either way, you owe me a beer! 我有点工作......无论哪种方式,你欠我一杯啤酒!

.full-circle {
        display:block;
        border-bottom: 1px solid #1588cb;
        width: 45px;
        -moz-border-radius: 45px / 36px;
        -webkit-border-radius: 45px / 36px;
        -webkit-box-sizing: content-box;
        -moz-box-sizing: content-box;
        -o-box-sizing: content-box;
        box-sizing: content-box;
        border-radius: 45px / 36px;
        height: 35px;
        background: #fff;
        position: absolute;
        left: 50%;
        margin-left: -17px;
        bottom: -17px;
        line-height: 40px;
    }

https://jsfiddle.net/awea2s2y/ https://jsfiddle.net/awea2s2y/

or maybe this one is slightly better? 或者这个稍微好一点? https://jsfiddle.net/p9hynbrb/ https://jsfiddle.net/p9hynbrb/

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

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