[CSS] Interchange background of an element
z-index
property arranges how an element is stacked onto other positioned elements. At times you may set a z-index
property on a child element to be lower and it ends up hiding behind the background of its parent. To prevent this, you can cause a new stacking context on the parent element to prevent child elements from going behind it. One way way to create a stacking context is to use isolation: isolate
css style declaration.
We can use this stacking context technique to create hover effect that interchanges a button's background. For example:
button.join-now {
cursor: pointer;
border: none;
outline: none;
padding: 10px 15px;
position: relative;
background-color: #5dbea3;
isolation: isolate; /* If ommitted, child pseudo element will be stacked behind */
}
button.join-now::before {
content: "";
position: absolute;
background-color: #33b249;
top: 0;
left: 100%;
right: 0;
bottom: 0;
transition: left 500ms ease-out;
z-index: -1;
}
button.join-now:hover::before {
left: 0;
}
Read more: https://dev.to/smitterhane/13-css-tricks-that-will-give-you-an-adrenaline-rush-5908
分类:
CSS3
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
2021-07-20 [SAA + SAP] 06. Containers on AWS: ECS, Fargate, ECR & EKS
2020-07-20 [XState] Assignement actions
2020-07-20 [XState] Using global actions prop for testing
2018-07-20 [Vue @Component] Simplify Vue Components with vue-class-component
2017-07-20 [HTML] Change an HTML5 input's placeholder color with CSS
2017-07-20 [Node] Run Any Version of a Node Tool with npx
2016-07-20 [CSS] Make element not selectable