background不常用的属性

使用background属性的时候一般只使用自己熟悉的属性,或者其实大多数时候默认属性就能符合需求。遇到不熟悉的需求可能挨个属性试一下就可以了。但是最好的方案还是了解清楚。其实前端最花时间的就是样式处理了。

1. background-clip

background-clip是背景颜色或者背景图片的可见的填充范围。 注意,如果想要背景图片对该属性起作用,那么不能直接使用background: url(), 而需要使用background-image: url()

  • background-clip: border-box (默认值)
css 复制代码
/*在border的范围也会背景图片填充*/
background: url(https://pic4.9pic.cn/00/23/beijing-jihe1-bizhi-jihebeijing_236624_detail.jpg);
padding:40px;
border:20px dashed yellow;
background-clip: border-box;
  • background-clip: padding-box
  • background-clip: content-box;

2. background-origin

该属性表示背景从哪个范围开始渲染。 下面的例子在background-clip: content-box的前提下进行渲染。

  • background-origin: border-box
  • background-origin: padding-box
  • background-origin: content-box
相关推荐
hunterandroid19 小时前
Android 安全最佳实践:从数据存储到网络通信的防护思路
前端
H Journey19 小时前
web开发学习:html、css、js
前端·css·html·js
hunterandroid19 小时前
Compose 性能优化:从卡顿到丝滑的实战经验
前端
hunterandroid19 小时前
Kotlin Coroutines 在 Android 项目中的落地实战
前端
不一样的少年_19 小时前
不用框架,手搓 AI Agent:(一) 先让它跑起来
前端·后端·agent
味悲19 小时前
浏览器解析机制与XSS的15种编码绕过
前端·xss
小牛itbull19 小时前
【译】为什么我使用 React 重构了 WordPress?
前端·react.js·重构
用户0595401744619 小时前
AI Agent 记忆存储踩坑实录:这个问题让我排查了 3 天,最终用 pytest + Docker 实现秒级回归
前端·css
今日无bug19 小时前
Emmet 语法速成指南
前端·css·html
Hello.Reader19 小时前
Tailwind CSS v4.3 从入门到实战Vite 安装、响应式布局、暗黑模式与主题配置
前端·css