css--->圓角設置


1.為元素添加四個相同的圓角:

語法結構:border-radius:r;

     r為圓角的半徑大小

eg:如下樣式,給元素添加四個圓角為10px

   

代碼如下:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>radius</title>
        <style>
            div{
                width: 100px;
                height: 100px;
                background-color: aqua;
                border-radius: 10px;
            }
        </style>

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

2.為元素創建一個圓角 

  語法結構:

    左上角:border-top-left-radius: r ;

    右上角:border-top-right-radius: r ;

    左下角:border-bottom-left-radius: r ;

    右下角:border-bottom-right-radius: r ;

 

 

eg:如下樣式,給元素添加左上角圓角為30px

代碼如下:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>radius</title>
        <style>
            div{
                width: 100px;
                height: 100px;
                background-color: aqua;
                border-top-left-radius: 30px;
            }
        </style>

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

3.為元素創建一個橢圓角 

  語法結構:

    左上角:border-top-left-radius: x y ;

    右上角:border-top-right-radius:x y ;

    左下角:border-bottom-left-radius: x y ;

    右下角:border-bottom-right-radius: x y ;

   其中x表示圓角在水平方向上的半徑大小,y表示圓角在垂直方向上的半徑大小

 

  eg:如下樣式,給元素添加左上角圓角在水平方向上為10px,在垂直方向上為30px

  

  代碼如下:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>radius</title>
        <style>
            div{
                width: 100px;
                height: 100px;
                background-color: aqua;
                border-top-left-radius: 10px 30px;
            }
        </style>

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

4.圓形設置:

  方法1:
    條件1:定義width等於height
    條件2:radius=1/2width
  代碼如下:
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>radius</title>
        <style>
            div{
                width: 100px;
                height: 100px;
                background-color: aqua;
                border-radius: 50px;
            }
        </style>

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

    方法2:

      定義:radius:50%(永遠為容器的一半)

    代碼如下:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>radius</title>
        <style>
            div{
                width: 100px;
                height: 100px;
                background-color: aqua;
                border-radius: 50%;
            }
        </style>

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

 

5.半圓設置:

  語法結構:

    border-radius:r1 r2 0 0;

  其中r1和r2是左右上角的半徑大小,左下角和右小角設置為0

  設定條件:r1=r2=1/2width=height

  eg:設定一個直徑為100px的半圓

  

  代碼如下:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>radius</title>
        <style>
            div{
                width: 100px;
                height: 50px;
                background-color: aqua;
                border-radius: 50px 50px 0 0;
            }
        </style>

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

6.橢圓形設置:

  語法結構:

    border-radius:x/y;

  其中x表示圓角在水平方向上的半徑大小,y表示圓角在垂直方向上的半徑大小

  eg:設置一個與容器為W:200px,H:100px內相切的一個橢圓形

  

  代碼如下:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>radius</title>
        <style>
            div{
                width: 200px;
                height: 100px;
                background-color: aqua;
                border-radius: 100px/50px;
            }
        </style>

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

7.給radius賦多個值的含義:

  (1) border-radius:r1 r2;

  其中r1是左上角和右下角的半徑大小,r2是左下角和右上角的半徑大小

  eg:如下樣式,左上角和右下角的半徑為10px,左下角和右上角的半徑為30px

  

  代碼如下:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>radius</title>
        <style>
            div{
                width: 100px;
                height: 100px;
                background-color: aqua;
                border-radius: 10px 30px;
            }
        </style>

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

  (2) border-radius:r1 r2 r3 r4;

  其中r1是左上角半徑大小,r2是右上角半徑大小,r3是右下角半徑大小,r4是左下角半徑大小

   eg:如下樣式,左上角半徑大小10px,右上角半徑大小20px,右下角半徑大小30px,左下角半徑大小40px

  

  代碼如下;

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>radius</title>
        <style>
            div{
                width: 100px;
                height: 100px;
                background-color: aqua;
                border-radius: 10px 20px 30px 40px;
            }
        </style>

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM