图片底部圆弧(border-radius的各种形状)

 

1.图片底部圆弧

直接看代码;里面有注释:

<!DOCTYPE HTML>
<html lang="en-US">

<head>
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">
        html,
        body {
            width: 100%;
        }
        .box {
            width: 480px;
             margin:100px auto;
        }
        img{
            width:480px;
            height:300px;
            border-radius: 100% 100% 100% 100% / 0% 0% 30% 30%;
                         
        }
        /* border-radius的常规用法我就不说了,这里就讲解一下上面那几个参数指的是什么;前面的是水平半径;后面的是垂直半径*/
    </style>
</head>

<body>
    <div class="box">
        <img src="./1.jpg" alt="">
    </div>
</body>

</html>

下面就来讲解下border-radius这个属性:

在我们开发中常用的就是的就是border-radius:50%;但其实border-radius可以为我们提供很多形状;

border-radiu常用的三种声明方式:

border-radius: 16px;
border-radius: 4em;
border-radius: 50%;

 

border-radius分别指定各个角弯曲程度

当声明border-radius: 10px;时,相当于声明border-radius: 10px 10px 10px 10px;
四个角的值分别为左上-右上-右下-左下顺时针旋转,类似于指定盒模型的margin,border,padding方式。
现将四个角指定为不同弯曲程度,结果如下:

border-radius: 10% 25% 40% 50%;

其中border-radius: 10% 25% 40% 50%;可以写成以下形式:

border-top-left-radius: 10%;
border-top-right-radius: 25%;
border-bottom-right-radius: 40%;
border-bottom-left-radius: 50%;

 

为border-radius分别指定水平和竖直弯曲程度

直接看实列:

半圆形

border-radius: 50% / 100% 100% 0 0;

沿纵轴劈开的半椭圆

border-radius: 100% 0 0 100% / 50%;

四分之一椭圆

border-radius: 100% 0 0 0;

还有很多形状,可以自己去尝试 

可以使用CSS的绝对定位来实现这个效果。HTML结构如下: ```html <div class="container"> <div class="left"></div> <div class="right"></div> <div class="bottom"> <span class="dot active"></span> <span class="dot"></span> <span class="dot"></span> </div> </div> ``` CSS样式如下: ```css .container { position: relative; width: 520px; height: 280px; margin: 0 auto; /* 水平居中 */ background-color: #ccc; } .left, .right { position: absolute; top: 50%; width: 20px; height: 30px; background-color: #fff; transform: translateY(-50%); } .left { left: 0; border-top-left-radius: 7px; border-bottom-left-radius: 7px; } .right { right: 0; border-top-right-radius: 7px; border-bottom-right-radius: 7px; } .bottom { position: absolute; bottom: 0; left: 50%; width: 70px; height: 13px; background-color: #fff; border-radius: 7px; transform: translateX(-50%); } .dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin: 0 6px; background-color: #ccc; } .active { background-color: orange; } ``` 解释一下: - `.container` 是整个图形的容器,使用相对定位。 - `.left` 和 `.right` 是左右两个小方块,使用绝对定位来垂直居中,左边的使用 `left: 0`,右边的使用 `right: 0`。 - `.bottom` 是下方的整体,使用绝对定位来底部对齐,使用 `left: 50%` 和 `transform: translateX(-50%)` 来水平居中。 - `.dot` 是小圆点,使用 `display: inline-block` 让它们在一行内排列,使用 `margin: 0 6px` 来让它们之间有一定的间隔。 - `.active` 是当前激活状态的小圆点,使用 `background-color` 来设置背景色。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值