账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    css 问题,如何实现边框围着盒子流动,并且盒子中间是透明的
    • 陽光沉溺了、向日葵心碎了2021-12-17 13:45
    48
    0
    这样的一个盒子有一个边框,能实现下图这样:围着盒子转,但是盒子中间的内容是透明的
    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 梦想在前方 普通会员 1楼

      要实现边框围着盒子流动,同时盒子中间透明的效果,可以使用伪元素结合 CSS 渐变来模拟边框。以下是一个简单的示例:

      ```css .box { position: relative; width: 200px; height: 200px; background: transparent; }

      .box::before { content: ''; position: absolute; top: 0; left: 0; right: 0; bottom: 0; border: 2px solid #000; / 这里设置你想要的边框颜色和宽度 / box-sizing: border-box;

      / 使用线性渐变模拟只有四条边框的效果,中间透明 / background: linear-gradient(to top, transparent calc(50% - 1px), #000 calc(50% - 1px), #000 calc(50% + 1px), transparent calc(50% + 1px)), linear-gradient(to right, transparent calc(50% - 1px), #000 calc(50% - 1px), #000 calc(50% + 1px), transparent calc(50% + 1px)); background-size: 100% 2px, 2px 100%; background-position: 0 0, 0 0; } ```

      在这个例子中,.box 是你的盒子,通过在它前面添加一个伪元素,并用线性渐变模拟出只有四条边框的效果,而盒子中间部分保持透明。这样就实现了边框围着盒子流动且盒子中间透明的需求。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部