html如何绘制弧形,用CSS画弧形

本文介绍了如何使用CSS来创建弧形边框,通过设置border-radius和利用伪类`:after`来截取圆的一部分,实现漂亮的弧形效果。通过调整相关属性,可以自定义弧形的颜色和形状。
摘要由CSDN通过智能技术生成

有的时候在界面里,想要做个漂亮的弧形边用来美观单一不变的矩形框.简单的顶点控制并不能很好实现想要的效果,用图片又不够完美,且多了加载项.那怎么用CSS来实现弧形呢?

先说一下原理,其实我们需要实现的是截取圆的小部分弧边,那么就首先要画一个足够大的圆,然后再在其中选取我们需要的截段,把其他部分隐去即可.一共也就两步.这里我们需要用到::after伪类.

先画个框作为容器,CSS代码如下:

#div_headContainer {

-webkit-border-radius: 5px;

-moz-border-radius: 5px;

border-radius: 5px;

margin: 5px;

padding: 0 0 8px 0;

height: 150px;

border: darkgray 1px solid;

}

再在里面套个小框,是我们用来做圆的容器,CSS代码如下:

#div_headContainerBackground {

width: 100%;

height: 100%;

position: relative;

overflow: hidden;

padding: 10px 10px 0 10px;

}

接下去就是关键了,我们使用:after伪类来实现背景

#div_headContainerBackground::after {

content: '';

width: 160%;

height: 100%;

position: absolute;

left: -30%;

top: 0;

z-index: -1;

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,让我来给您讲解如何用 HTMLCSS绘制米奇的图案。 首先,我们需要先在 HTML 中创建一个 div 容器,然后在 CSS 中设置该 div 的宽度和高度,并设置背景色为黑色,代码如下: HTML 代码: ```html <div class="mickey"></div> ``` CSS 代码: ```css .mickey { width: 200px; height: 200px; background-color: black; } ``` 接下来,我们需要在该 div 容器中绘制米奇的头部和耳朵。米奇的头部是一个圆形,可以使用 CSS 中的 border-radius 属性来实现。耳朵是两个圆形,可以使用伪元素 ::before 和 ::after 来实现。 HTML 代码: ```html <div class="mickey"> <div class="head"></div> <div class="left-ear"></div> <div class="right-ear"></div> </div> ``` CSS 代码: ```css .mickey { width: 200px; height: 200px; background-color: black; position: relative; } .head { width: 140px; height: 140px; border-radius: 70px; background-color: white; position: absolute; top: 30px; left: 30px; } .left-ear, .right-ear { width: 60px; height: 60px; border-radius: 30px; background-color: white; position: absolute; top: 20px; } .left-ear { left: -20px; } .right-ear { right: -20px; } .left-ear::before, .left-ear::after, .right-ear::before, .right-ear::after { content: ""; width: 30px; height: 30px; border-radius: 15px; background-color: black; position: absolute; top: 15px; } .left-ear::before, .right-ear::before { left: 15px; } .left-ear::after, .right-ear::after { right: 15px; } ``` 最后,我们还需要在头部中绘制米奇的眼睛和嘴巴。眼睛可以使用圆形和伪元素 ::before 和 ::after 来实现,嘴巴可以使用弧形和伪元素 ::before 和 ::after 来实现。 HTML 代码: ```html <div class="mickey"> <div class="head"> <div class="left-eye"></div> <div class="right-eye"></div> <div class="mouth"></div> </div> <div class="left-ear"></div> <div class="right-ear"></div> </div> ``` CSS 代码: ```css .mickey { width: 200px; height: 200px; background-color: black; position: relative; } .head { width: 140px; height: 140px; border-radius: 70px; background-color: white; position: absolute; top: 30px; left: 30px; } .left-eye, .right-eye { width: 30px; height: 30px; border-radius: 15px; background-color: black; position: absolute; top: 40px; } .left-eye { left: 40px; } .right-eye { right: 40px; } .left-eye::before, .right-eye::before { content: ""; width: 15px; height: 15px; border-radius: 7.5px; background-color: white; position: absolute; top: 5px; left: 5px; } .left-eye::after, .right-eye::after { content: ""; width: 10px; height: 10px; border-radius: 5px; background-color: black; position: absolute; top: 10px; left: 10px; } .mouth { width: 50px; height: 30px; border-radius: 0 0 25px 25px; border: 3px solid black; position: absolute; top: 70px; left: 45px; } .mouth::before, .mouth::after { content: ""; width: 10px; height: 10px; border-radius: 5px; background-color: black; position: absolute; } .mouth::before { top: 10px; left: 10px; } .mouth::after { top: 10px; right: 10px; } .left-ear, .right-ear { width: 60px; height: 60px; border-radius: 30px; background-color: white; position: absolute; top: 20px; } .left-ear { left: -20px; } .right-ear { right: -20px; } .left-ear::before, .left-ear::after, .right-ear::before, .right-ear::after { content: ""; width: 30px; height: 30px; border-radius: 15px; background-color: black; position: absolute; top: 15px; } .left-ear::before, .right-ear::before { left: 15px; } .left-ear::after, .right-ear::after { right: 15px; } ``` 这样,我们就成功地用 HTMLCSS 绘制了一个简单的米奇图案。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值