html 圆角

本文介绍了如何通过CSS的border-radius属性为HTML元素设置圆角,包括基本语法和实现圆形、椭圆形等特殊形状的方法。通过设置不同数值或百分比,可以调整元素的圆角大小。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

圆角

通过border-radius为盒子设置圆角孤度

语法:

设置一个值:
	border-radius:10px;
设置四个值:
	border-radius: 左上 右上 右下 左下;
设置两个值:
	border-radius:左上右上   右下左下;

原理:
圆角的孤度 是圆的半径决定
在这里插入图片描述
属性值:数字(100px)或 百分比(50%)

特殊形状

圆形:盒子为正方形情况下,盒子的border-radius 值为 50%;
椭圆: 盒子为长方型情况下,将盒子的 border-radius 值 设为 50%;
例:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .box {
            width: 800px;
            height: 800px;
            background-color: #f2f2f2;
        }
        
        .box-1 {
            width: 219px;
            height: 100px;
            background-color: green;
            border-radius: 130px 130px 0px 0px;
            position: relative;
            top: 20px;
            left: 250px;
        }
        
        .box-2 {
            width: 15px;
            height: 15px;
            background-color: #ffffff;
            border-radius: 130px 130px;
            position: relative;
            top: -25px;
            left: 305px;
        }
        
        .box-3 {
            width: 15px;
            height: 15px;
            background-color: #ffffff;
            border-radius: 130px 130px;
            position: relative;
            top: -41px;
            left: 395px;
        }
        
        .box-4 {
            width: 220px;
            height: 180px;
            background-color: green;
            position: relative;
            left: 250px;
            border-radius: 0px 0px 20px 20px;
        }
        
        .box-5 {
            width: 40px;
            height: 150px;
            background-color: green;
            position: relative;
            left: 200px;
            top: -175px;
            border-radius: 10px 10px 10px 10px;
        }
        
        .box-6 {
            width: 40px;
            height: 150px;
            background-color: green;
            position: relative;
            left: 480px;
            top: -325px;
            border-radius: 10px 10px 10px 10px;
        }
        
        .box-7 {
            width: 40px;
            height: 80px;
            background-color: green;
            position: relative;
            left: 285px;
            top: -290px;
            border-radius: 10px 10px 10px 10px;
        }
        
        .box-8 {
            width: 40px;
            height: 80px;
            background-color: green;
            position: relative;
            left: 390px;
            top: -370px;
            border-radius: 10px 10px 10px 10px;
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="box-1"></div>
        <div class="box-2"></div>
        <div class="box-3"></div>
        <div class="box-4"></div>
        <div class="box-5"></div>
        <div class="box-6"></div>
        <div class="box-7"></div>
        <div class="box-8"></div>
    </div>
</body>

</html>

效果图:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值