四个方向的边框

四个方向的边框

四个方向的边框属性

属性意义
border-top上边框
border-right右边框
border-bottom下边框
border-left左边框

四个方向边框的三要素小属性

四个方向边框也可以写成三要素小属性,以右边框为例示例如下:

属性意义
border-right-width右边框宽度
border-right-style右边框线型
border-right-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>边框</title>
    <style>
        div {
            width: 150px;
            height: 150px;
            border: 10px solid #000;
            margin-bottom: 20px;
        }
        .box1 {
            border-top-style: solid;
            border-top-color: red;
        }
        .box2 {
            border-right-style: dotted;
            border-right-color: blue;
        }
        .box3 {
            border-bottom-style: dashed;
            border-bottom-color: green;
        }
        .box4 {
            border-left-style: solid;
            border-left-color: yellow;
        }
    </style>
</head>
<body>
    <div class="box1"></div>
    <div class="box2"></div>
    <div class="box3"></div>
    <div class="box4"></div>
</body>
</html>

网页效果如下:

在这里插入图片描述

在上面代码中使用四个方向边框的三要素小属性分别设置了四个盒子的上下左右四个边框的值。

去掉边框

border-right: none;属性即可去掉左边框,以此类推,示例如下:

<style>
    div {
        width: 200px;
        height: 200px;
        border: 10px solid red;
        border-right: none;
    }
</style>

网页效果如下:
在这里插入图片描述

利用边框制作三角形

可以巧妙的利用边框的特性制作三角形,设置宽高为0px即可,示例代码如下:

<style>
    div {
        width: 0px;
        height: 0px;
        /* 设置颜色为透明色,transparent是透明色 */
        border: 50px solid transparent;
        border-bottom-color: red;
    }
</style>

在这里插入图片描述

其他方向三角形以此类推。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值