CSS学习11:边框(border)

目录

border语法:

border-style的属性值如下:

border可以单独设置四周的边框

边框会影响实际盒子的大小


border语法:

 border : border-width || border-style || border-color;   

例如:

border: 1px solid red;

属性作用
border-width自定义边框的粗细,单位是px
border-style边框的样式
border-color边框颜色

<!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.0">
    <title>Document</title>
    <style>
        div {
            width: 200px;
            height: 200px;
            background-color: pink;
            /* 边框会撑大盒子 */
            border: 5px solid #000;
        }
    </style>
</head>
<body>
    <div></div>
</body>
</html>

 

 

border-style的属性值如下:

  • none:没有边框

  • solid:边框为单实线(常用)

  • dashed:边框为虚线

  • dotted:边框为点线

border可以单独设置四周的边框

border-top         设置上边框

border-bottom    设置下边框

border-left          设置左边框

border-right        设置右边框

 

<!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.0">
    <title>Document</title>
    <style>
        div {
            width: 200px;
            height: 200px;
            /* 边框是由上下左右四部分组成   这个比较常用 */
            border-top: 1px solid #000;
            border-right: 5px dotted #ccc;
            border-bottom: 10px dashed red;
            border-left: 5px solid green;
        }
    </style>
</head>
<body>
    <div></div>
</body>
</html>

 

 

边框会影响实际盒子的大小

盒子模型的宽高会把边框的大小算进去,从而影响布局。解决方法:

  • 测量盒子大小的时候不量边框的大小,直接量内容的宽高。
  • 如果测量的时候包含了边框,则需要把宽高里边框的那一份减去。
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值