程序员

CSS border边框一半或者部分可见的实现代码

作者:admin 2021-04-13 我要评论

1.使用伪类,让Border边框显示一半 !DOCTYPE htmlhtml head meta charset=utf-8 title使用伪类,在元素前或后插入内容/title style div { position: relative; w...

在说正事之前,我要推荐一个福利:你还在原价购买阿里云、腾讯云、华为云服务器吗?那太亏啦!来这里,新购、升级、续费都打折,能够为您省60%的钱呢!2核4G企业级云服务器低至69元/年,点击进去看看吧>>>)

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>

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>

到此这篇关于CSS border边框一半或者部分可见的实现代码的文章就介绍到这了,更多相关CSS border边框内容请搜索脚本之家以前的文章或继续浏览下面的相关文章,希望大家以后多多支持脚本之家!


原文链接:https://m.jb51.net/css/755382.html

版权声明:本文转载自网络,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。本站转载出于传播更多优秀技术知识之目的,如有侵权请联系QQ/微信:153890879删除

相关文章
  • 四两拨千斤——你不知道的VScode编码Ty

    四两拨千斤——你不知道的VScode编码Ty

  • 我是如何在 Vue 项目中做代码分割的

    我是如何在 Vue 项目中做代码分割的

  • position:sticky 粘性定位的几种巧妙应

    position:sticky 粘性定位的几种巧妙应

  • 从零到一搭建React组件库

    从零到一搭建React组件库

腾讯云代理商
精彩导读
海外云服务器
热门资讯
腾讯云代理商