css实现圆,半圆,四分之一圆和其他几何图形画法

画四分之一圆的时候,是画出一个圆并且结合overflow等实现,但是其实可以直接画出半圆或者四分之一圆,之前忽略了几个属性。

圆的画法:先画相应矩形,在用border-radius

1.画出圆
{
  width:100px;
  height:100px;
  border-radius:50px;
}
2.画出方向四个不同的本圆
.top
{
  width: 100px;
  height: 50px;
  border-radius: 50px 50px 0 0;
}
.right {
  height: 100px;
  width: 50px;
  border-radius: 0 50px 50px 0;
}
.bottom {
  width: 100px;
  height: 50px;
  border-radius: 0 0 50px 50px;
}
.left {
  width: 50px;
  height: 100px;
  border-radius: 50px 0 0 50px;
}
3.画出四分之一个圆方法:
{
  width:50px;
  height:50px;
  border-radius:50px 0 0 0;
}
4.椭圆
<div class="ellipse">
</div>
 .ellipse{
    width: 200px;
    height: 100px;
    border-radius: 50%;
    background: black;
}
5.沿横轴、纵轴劈开的半椭圆
<div class="x-ellipse">
</div>
<div class="y-ellipse">
</div>

.x-ellipse{
    width: 200px;
    height: 150px;
    border-radius: 50%/ 100% 100% 0 0;
    /*相当于50% 50% 50% 50%/ 100% 100% 0 0;*/
    background: black;
}
.y-ellipse{
    width: 200px;
    height: 150px;
    border-radius: 100% 0 0 100%/50%;
    background: black;
}        

这里写图片描述

6.四分之一椭圆
<div class="quarter-ellipse">
</div>
.quarter-ellipse{
    width: 200px;
    height: 150px;
    border-radius: 100% 0 0 0;
    background: black;
}

这里写图片描述

7.菱形

如果想让形状变形,但是里边的字体不变形

思路:
变形之后,再让里边内容旋转回来

<div class="paralle"><p>transform:skew()</p></div>

.paralle {
    position: relative;
    left: 100px;
    width:200px;
    height: 100px;
    background:#44a5fc;

    line-height: 100px;
    text-align: center;
    font-weight: bolder;

    transform: skew(-20deg);
}
.paralle p{
    transform: skew(20deg);
}

这里写图片描述

8.三角形
#triangle-up {
    width: 0;
    height: 0;
    border-left: 50px solid transparent;
    border-right: 50px solid transparent;
    border-bottom: 100px solid lightblue;
}
#triangle-down {
    width: 0;
    height: 0;
    border-left: 50px solid transparent;
    border-right: 50px solid transparent;
    border-top: 100px solid lightblue;
}

#triangle-left {
    width: 0;
    height: 0;
    border-top: 50px solid transparent;
    border-right: 100px solid lightblue;
    border-bottom: 50px solid transparent;
}
#triangle-right {
    width: 0;
    height: 0;
    border-top: 50px solid transparent;
    border-left: 100px solid lightblue;
    border-bottom: 50px solid transparent;
}
#triangle-topleft {
    width: 0;
    height: 0;
    border-top: 100px solid lightblue;
    border-right: 100px solid transparent;
}
#triangle-topright {
    width: 0;
    height: 0;
    border-top: 100px solid lightblue;
    border-left: 100px solid transparent; 
}
#triangle-bottomleft {
    width: 0;
    height: 0;
    border-bottom: 100px solid lightblue;
    border-right: 100px solid transparent;
}
#triangle-bottomright {
    width: 0;
    height: 0;
    border-bottom: 100px solid lightblue;
    border-left: 100px solid transparent;
}
9.一些属性的说明

border-radius:50px 0 0 0
等价于将border-raduis属性分成四个属性来设置,把一个圆分成上左,上右,下右,下左4份
border-top-left-radius:
border-top-right-radius:
border-bottom-right-radius:
border-bottom-left-radius:

首选需要了解border-radius
border-radius可以是元素也可是百分比。
border-radius:border-top-left-radius,border-top-right-radius,
border-bottom-right-radius,border-bottom-left-radius;
不仅仅可以为四个角分别设置值,甚至可以给每个角提供水平和垂直半径
方法是在斜杠前指定 1~4 个值,在斜杠后指定另外 1~4 个值
举例来说,
当 border-radius 的值为10px / 5px 20px 时,
其效果相当于 10px 10px 10px 10px / 5px 20px 5px 20px 。

1. 圆形: 使用 CSS3 的 border-radius 属性,将宽高设置为相等的值即可创建圆形。 示例代码: ```css .circle { width: 100px; height: 100px; border-radius: 50%; } ``` 2. 环: 在圆形的基础上,添加 border 属性控制边框宽度和颜色。 示例代码: ```css .ring { width: 100px; height: 100px; border-radius: 50%; border: 10px solid #000; } ``` 3. 半圆: 使用 CSS3 的 border-radius 属性,将宽度设置为高度的两倍,再设置 border-bottom-left-radius 和 border-bottom-right-radius 的值为 0,即可创建半圆。 示例代码: ```css .half-circle { width: 100px; height: 50px; border-radius: 100px 100px 0 0; } ``` 4. 四分之一: 在半圆的基础上,再设置 border-top-left-radius 的值为 0,即可创建四分之一。 示例代码: ```css .quarter-circle { width: 50px; height: 50px; border-radius: 0 50px 0 0; } ``` 5. 扇形: 在圆形的基础上,使用伪元素 ::before 和 ::after 创建两个三角形,再使用 transform 属性旋转其中一个三角形,即可创建扇形。 示例代码: ```css .sector { position: relative; width: 100px; height: 100px; border-radius: 50%; overflow: hidden; } .sector::before, .sector::after { content: ""; position: absolute; top: 0; left: 0; width: 50%; height: 100%; background-color: #000; transform-origin: 100% 50%; } .sector::before { transform: rotate(30deg); } ``` 以上是几种常见的 CSS3 圆形环、半圆四分之一、扇形的实现方法。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值