css 边框镶角

一、background-image#

效果图:

background: linear-gradient(to left, yellow, yellow) left top no-repeat,
  linear-gradient(to bottom, yellow, yellow) left top no-repeat,
  linear-gradient(to left, yellow, yellow) right top no-repeat,
  linear-gradient(to bottom, yellow, yellow) right top no-repeat,
  linear-gradient(to left, yellow, yellow) left bottom no-repeat,
  linear-gradient(to bottom, yellow,yellow) left bottom no-repeat,
  linear-gradient(to left, yellow, yellow) right bottom no-repeat,
  linear-gradient(to left, yellow, yellow) right bottom no-repeat;
  background-size: 2px 10px, 10px 2px, 2px 10px, 10px 2px;
  background-color: blue;
  border: 2px solid red;

要点:

  1. linear-gradient塑造了background-image(具体渐变方向不影响结果和细节不重要,换做真实的矢量图片也可)
  2. 为每一个image都指定对应的位置
  3. background-size定义image的大小

也可写作:

background:linear-gradient(to left, yellow, yellow) left top / 2px 10px no-repeat,
  linear-gradient(to bottom, yellow, yellow) left top / 10px 2px no-repeat,
  linear-gradient(to left, yellow, yellow) right top  / 2px 10px no-repeat,
  linear-gradient(to bottom, yellow, yellow) right top/ 10px 2px no-repeat,
  linear-gradient(to left, yellow, yellow) left bottom  / 2px 10px no-repeat,
  linear-gradient(to bottom, yellow,yellow) left bottom / 10px 2px no-repeat,
  linear-gradient(to left, yellow, yellow) right bottom / 2px 10px no-repeat,
  linear-gradient(to left, yellow, yellow) right bottom/ 10px 2px no-repeat;
  background-color: blue;
  border: 2px solid red;

二、border-image#

效果图:

border-image: url('./bg.png');
border-image-slice: 80 80 fill;
border-image-width: 40px 40px;
width: 500px;
height: 200px;

注:此处用的二倍图
要点:

  1. border-image给定:边可延伸的背景图片
  2. border-image-slice设置边框裁切:角不变,边延伸
  3. border-image-width设置边框四角的宽高

作者:yiping5

出处:https://www.cnblogs.com/yiping5/p/18582141

版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。

posted @   Ping5-1  阅读(4)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
more_horiz
keyboard_arrow_up light_mode palette
选择主题
menu
点击右上角即可分享
微信分享提示