dmz社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 443|回复: 0

[Html/Css] CSS边框长度控制

[复制链接]
  • TA的每日心情

    2024-2-20 11:15
  • 签到天数: 11 天

    [LV.3]偶尔看看II

    878

    主题

    4343

    帖子

    3987

    积分

    终身会员[A]

    Rank: 7Rank: 7Rank: 7

    积分
    3987

    发表于 2020-4-12 15:00:01 | 显示全部楼层 |阅读模式

    本站资源全部免费,回复即可查看下载地址!

    您需要 登录 才可以下载或查看,没有帐号?立即注册

    x
    以前需要边框长度比容器小一些时,我用div嵌套。后来发现伪类在实现这个效果时很方便,只需要一个div就够了,另外调整padding和margin都不会很麻烦。

    [CSS] 纯文本查看 复制代码
    <div class="content-block">
    <div class="box-container">
    <div class="border-top">border top</div>
    </div>
    <div class="box-container">
    <div class="border-left">border left</div>
    </div>
    <div class="box-container">
    <div class="border-right">border right</div>
    </div>
    <div class="box-container">
    <div class="border-bottom">border bottom</div>
    </div>
    </div>

    [CSS] 纯文本查看 复制代码
    .box-container {
        position: relative;
        width: 90%;
        color: #777;
    }
    
    .border-top {
        background: #b4bcbf;
        padding: 15px;
    }
    
        .border-top:before {
            content: '';
            position: absolute;
            left: 42%;
            top: 0;
            bottom: auto;
            right: auto;
            height: 7px;
            width: 50%;
            background-color: #8796a9;
        }
    
    .border-left {
        background: #dfdad6;
        padding: 15px;
    }
    
        .border-left:before {
            content: '';
            position: absolute;
            left: 0;
            top: 6%;
            bottom: auto;
            right: auto;
            height: 52%;
            width: 5px;
            background-color: #a89d9e;
        }
    
    .border-right {
        background: #eee9c4;
        padding: 15px;
    }
    
        .border-right:after {
            content: '';
            position: absolute;
            left: auto;
            top: auto;
            bottom: 5px;
            right: 0;
            height: 52%;
            width: 5px;
            background-color: #f39c81;
        }
    
    .border-bottom {
        background: #bcdc9d;
        padding: 15px;
    }
    
        .border-bottom:after {
            content: '';
            position: absolute;
            left: 18px;
            top: auto;
            bottom: 0;
            right: auto;
            height: 6px;
            width: 105px;
            background-color: #32b66b;
        }


    效果如下图:
    1.png


    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|Archiver|小黑屋|本站代理|dmz社区

    GMT+8, 2024-4-28 19:09 , Processed in 0.091750 second(s), 36 queries .

    Powered by Discuz! X3.4 Licensed

    Copyright © 2001-2021, Tencent Cloud.

    快速回复 返回顶部 返回列表