简体   繁体   English

如何在 css 中设置锐利的半圆背景

[英]How can i set sharp half circle background in css

在此处输入图像描述 I am trying to put half circle background but radius in bottom not completely coming in circle....我正在尝试放置半圆形背景,但底部的半径没有完全进入圆形......

Here is my code i have tried这是我尝试过的代码

 .main { overflow: hidden; }.bg { width: 100%; height: 800px; border-bottom-left-radius: 100px; border-bottom-right-radius: 100px; background-color: lightgray; margin-top: -130px; }
 <div class="main"> <div class="bg"></div> </div>

Try this it's working in all devices试试这个它适用于所有设备

 .main{ overflow: hidden; }.bg { width:80vw; height:40vw; border-bottom-left-radius: 80vw; border-bottom-right-radius: 80vw; background-color: lightgray; }
 <div class="main"> <div class="bg"></div> </div>

You can use an svg to make things easier.您可以使用svg让事情变得更简单。 There is the circle element which you can include that always draws perfect circles.有一个你可以包含的circle元素,它总是画出完美的圆圈。 Place it so that only the bottom half shows and you've got a half circle.放置它,以便只显示下半部分并且你有一个半圆。

Example:例子:

 svg { width: 98vw; height: 98vw; }
 <svg viewbox="0 0 100 100"> <circle cx="50" cy="0" r="50" fill="grey" /> </svg>

 .halfCircle{ height:45px; width:90px; border-radius: 90px 90px 0 0; background:green; } <div class="halfCircle"></div> the bellow link has all the shape https://paulund.co.uk/how-to-create-different-shapes-in-css

As per as you have told your requirements in your comment, I have this.根据您在评论中告诉您的要求,我有这个。

 .main { /*overflow: hidden;*/ }.bg { width: 400px; height: 500px; /*Have reduced the width and height just for the sake of simplicity. It's completely up to you */ border-bottom-left-radius: 50%; border-bottom-right-radius: 50%; background-color: lightgray; margin-top: -130px; }
 <div class="main"> <div class="bg"></div> </div>

Hope this solves your query.希望这能解决您的疑问。

It is working and looking perfectly.But the width should be twice the height and the border-redious first two parameters equal to height and last parameters should be 0它正在工作并且看起来很完美。但是宽度应该是高度的两倍,并且边框红色的前两个参数等于高度,最后一个参数应该是 0

 .halfCircle{ height:400px; width:800px; border-radius: 400px 400px 0 0; background:green; }

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

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