前端 CSS 盒子模型 邊框 border屬性


 

邊框

border:邊框的意思,描述盒子的邊框

邊框有三個要素: 粗細 線性樣式 顏色

border: solid

border特性 

如果顏色不寫,默認是黑色。如果粗細不寫,不顯示邊框。如果只寫線性樣式,默認的有上下左右 3px的寬度,實體樣式,並且黑色的邊框。

 

通常使用簡寫方式

border :solid     5px  red;
        線性樣式   粗細   顏色

 

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="x-ua-compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Title</title>
    <style type="text/css">

        .box{
            width: 200px;
            height: 200px;
            border:solid 5px red;
        }
    </style>
</head>
<body>
    <div class="box"></div>
</body>
</html>

 

 

如果顏色不寫,默認是黑色
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="x-ua-compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Title</title>
    <style type="text/css">

        .box{
            width: 200px;
            height: 200px;
            border:solid 5px;
        }
    </style>
</head>
<body>
    <div class="box"></div>
</body>
</html>

 

 如果只寫線性樣式,默認的有上下左右 3px的寬度,實體樣式,並且黑色的邊框。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="x-ua-compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Title</title>
    <style type="text/css">

        .box{
            width: 200px;
            height: 200px;
            border:solid ;
        }
    </style>
</head>
<body>
    <div class="box"></div>
</body>
</html>

 

 

 

 

 

 border寫法還可以分開寫

按照3要素來寫border 

3個要素  粗細 線性樣式 顏色

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="x-ua-compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Title</title>
    <style type="text/css">

        .box{
            width: 200px;
            height: 200px;
            /*border: 5px solid red;*/
            /* 按照3要素*/
            border-width: 5px;
            border-style: solid;
            border-color: red;
        }
    </style>
</head>
<body>
    <div class="box"></div>
</body>
</html>

等於 border: 5px solid red

border-width: 3px;
border-style: solid;
border-color: red;

后面可以繼續寫,方向和padding一樣 上右下左

 

border-width: 5px 10px;  /* 上下 左右*/
border-style: solid dotted double dashed; /* 上右下左 */
border-color: red green yellow; /* 上 左右 下 */

 

 

 

 

 

 

 

按照方向划分

四個方向 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="x-ua-compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Title</title>
    <style type="text/css">

        .box{
            width: 200px;
            height: 200px;
            /* 按照方向划分*/
            border-top-width: 10px;
            border-top-style: solid;
            border-top-color: red;

            border-right-width: 10px;
            border-right-style: solid;
            border-right-color: red;

            border-bottom-width: 10px;
            border-bottom-style: solid;
            border-bottom-color: red;

            border-left-width: 10px;
            border-left-style: solid;
            border-left-color: red;
        }
    </style>
</head>
<body>
    <div class="box"></div>
</body>
</html>

上面12條語句,相當於 bordr: 10px solid red;

另外還可以這樣寫法 效果一樣:

border-top: 10px solid red;
border-right: 10px solid red;
border-bottom: 10px solid red;
border-left: 10px solid red;

 

 清除border邊框的默認樣式,比如input輸入框

 border:none;
 border:0;

設置一個方向沒有

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="x-ua-compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Title</title>
    <style type="text/css">


        .box{
            width: 200px;
            height: 200px;
            border-top: 10px solid red;
            border-right: 10px solid red;
            border-bottom: 10px solid red;
            border-left: 10px solid red;
            /* 設置border沒有樣式*/
            border-left: none;
        }
    </style>
</head>
<body>
    <div class="box"></div>
</body>
</html>

border-left: 0; 也可以
border-left: 0;

 

 

邊框樣式

描述
none 無邊框。
dotted 點狀虛線邊框。
dashed 矩形虛線邊框。
solid 實線邊框。


免責聲明!

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



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