马三荷

CSS图形——实现圆角

 

css实现圆角

css2.1给元素添加圆角是一件很麻烦的事,老办法是用背景图片实现,制作比较麻烦。css3,border-radius的属性,使圆角属性得到完美的解决。

语法

border-radius:长度值;

说明:

长度值可以是px、百分比、em等

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>圆角实现</title>
    <style type="text/css">
        div{
            width: 100px;
            height: 50px;
            border-radius: 10px;
            background-color: yellow;
        }
    </style>
</head>
<body>

    <div></div>
    
</body>
</html>

设置border-radius:10px;设置的四个圆角半径都是10px

 border-radius属性值有四个写法(同margin、padding相似)

(1)border-radius:一个值;

        结果如上图

(2)border-radius:两个值;

       例如:border-radius:10px 20px;表示左上角、右下角为10px,右上角、左下角为20px;

     结果

   

(3)border-radius:设置三个值;

    例如:border-radius:10px 20px 30px;表示左上角、右上角和左下角、左下角的圆角半径依次是10px、20px、30px

   结果

 

 

 

(4)border-radius:设置四个值

  例如:border-radius:10px 20px 30px 40px;表示左上角、右上角、右下角和左下角的圆角半径依次是10px 20px 30px 40px

 结果

 

 实现下图效果:

代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>圆角实现</title>
    <style type="text/css">
        div{
            width: 50px;
            line-height: 50px;
            border-radius:80% 90% 100% 20%;
            background-color: black;
            color: white;
            text-align: center;
            font-size: 30px;
        }
    </style>
</head>
<body>

    <div>6</div>
    
</body>
</html>

 

posted on 2018-01-26 11:46  马三荷  阅读(6665)  评论(0编辑  收藏  举报

导航