圆角border-radius (实现圆(椭圆 胶囊 半椭圆) 和 三角形) 以及源码分析

本文详细介绍了如何使用CSS3创建各种图形,包括不同类型的圆、三角形、椭圆以及特殊形状如半椭圆、1/4椭圆和扇形。通过实例分析和源码解释,展示了如何利用`border-radius`属性实现这些图形,并提供了多种实现同一图形的不同方法。文章还探讨了如何创建上下部分形状不同的组合图形。
摘要由CSDN通过智能技术生成

目录

 

目录

一:实现各种圆

二 实现三角形

三:椭圆 半椭圆 1/4 椭圆 扇形

横轴分开的椭圆

竖轴分开的椭圆

扇形(1/4圆)

四:特殊图形(实例分析)

五    源码分析



一:实现各种圆

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <style type="text/css">
            .box1{
                width:100px;
                height:100px;
                background-color: blue;
                border-radius: 7px;
                border-top-left-radius:20px;/* 单独设置值 */            
                }
            .box2{
                width:100px;
                height:100px;
                background-color: blue;
                border-radius: 50%;
            }    
            .box3{
                width:200px;
                height:100px;
                background-color: red;
                /* border-radius: 50% 50%; */
                border-radius: 50%;
            }
            .box4{
                width:200px;
                height:100px;
                background-color: blue;
                border-radius: 100px;
            }
            .box {
                width: 500px;
                height: 100px;
                background: #FFD900;
                border-radius: 50% /100% 100% 0 0;;
            }        
        </style>
    </head>
    <body>
        <!-- 一般圆角 -->
        <div class="box1"></div>
        
        <!-- 圆  半径为宽度的一般 需要高度一致    border-radius 50%-->
        <div class="box2"></div>
        
        <!-- 椭圆 2个半径  不需要高度一致  border-radius 50%-->
        <div class="box3"></div>
        
        <!-- 胶囊 border-radius 高度的一半-->
        <div class="box4"></div>

        <!-- 半椭圆 -->
        <div class="box"></div>
    </body>
</html>

二 实现三角形

.trangle{

  width: 100px;

  height: 100px;

  border: 100px solid #000;

  border-top-color: red;

  border-bottom-color: yellow;

  border-left-color: blue;

  border-right-color: green;

}

<div class="trangle"></div>

三:椭圆 半椭圆 1/4 椭圆 扇形

             .a{
                width: 300px;
                height: 100px;
                background-color: yellow;
                border-radius: 50% / 100% 100% 0 0;
            }
            .b{
                width: 300px;
                height: 100px;
                background-color: black;
                border-radius: 50% / 0 0 100% 100%;
            }

横轴分开的椭圆

 

border-radius:border-top-left-radius, border-top-right-radius, border-bottom-right-radius, border-bottom-left-radius

竖轴分开的椭圆

.a{
                width: 300px;
                height: 100px;
                background-color: yellow;
                border-radius: 100% 0 0 100% / 50%;
            }
            .b{
                width: 300px;
                height: 100px;
                background-color: black;
                border-radius: 0 100% 100% 0 / 50%;;
            }

扇形(1/4圆)

   .a{
                width: 100px;
                height: 100px;
                background-color: yellow;
                border-radius: 50%;
            }
            .a {
              width: 0;
              height: 0;
              border-width: 100px;
              border-style: solid;
              border-color: blue transparent #f00 transparent;
              border-radius: 50%;
            }

            .b{
                width: 100px;
                height: 100px;
                background-color: blue;
                border-radius:  100% 0 0 0;
                
            }   

四:特殊图形(实例分析)

 

背后红色背景怎么设置 ?上半部分为矩形 下半部分为下半椭圆形

法一:

.a{
                width: 200px;
                height: 150px;
                background-color: red;
                /* border-radius: 0 0 50px 50px; */
                border-radius: 380%/ 0 0 100% 100%;
            }

法二:

.a{
                width: 300px;
                height: 100px;
                background-color: yellow;
                border-radius: 100% 100% 0 0/ 50%;
            }
            .b{
                width: 300px;
                height: 100px;
                background-color: black;
                border-radius: 0 0 100% 100%/ 50%;
            }

五 源码分析

wcss3:border-radius圆角边框详解 | 前端记录http://www.ferecord.com/css3border-radius-yuan-jiao-bian-kuang-xiang-jie.html

  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值