• 微信
您当前的位置: 首页> HTML+CSS>

css border属性边框一半或者部分可见

作者:Alpha时间:2020-05-30 阅读数:16731 +人阅读

1.使用伪类,让Border边框显示一半

2.使用绝对定位,增加边框盒子

1.使用伪类,让Border边框显示一半

<!DOCTYPE html>
<html>
 
<head>
    <meta charset="utf-8">
    <title>使用伪类,在元素前或后插入内容</title>
    <style>
        div {
            position: relative;
            width: 300px;
            height: 50px;
            background-color: #bbb;
            padding: 4px
        }
 
        div:before {
            content: "";
            position: absolute;
            left: 0;
            top: -2px;
            width: 50%;
            height: 2px;
            background-color: red
        }
    </style>
    <div>请看这个div的“上边框”是只有一半的</div>
    </body>
</html>

20200330145621686.png

2.使用绝对定位,增加边框盒子

<!DOCTYPE html>
<html>
 
<head>
    <meta charset="utf-8">
    <title>使用position定位,边框显示一半</title>
    <style>
        #holder {
            height: 50px;
            width: 300px;
            position: relative;
            margin: 10px;
            background-color: #eee;
        }
 
        #mask {
            position: absolute;
            top: -1px;
            left: 1px;
            width: 50%;
            height: 1px;
            background-color: orchid;
        }
    </style>
    <div id="holder">
        请看这个div的“上边框”是只有一半的
        <div id="mask"></div>
    </div>
    </body>
 
</html>

20200330145621686.png

本站所有文章、数据、图片均来自互联网,一切版权均归源网站或源作者所有。

如果侵犯了你的权益请来信告知我们删除。邮箱:595397166@qq.com

标签:

阿尔法

软件开发工程师#全栈工程师

{include file=foot.html}