[CSS] Using `inset` to replace `top, right, bottom, left`

When working with positioned elements, you often write code like this:

.some-element {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

This can be simplified using an inset propety:

.some-element {
    position: absolute;
    inset: 0;
}

Or if you have different values for toprightbottom and left, you can set them respectively in the order like: inset: -10px 0px -10px 0px. This shorthand works the same way as margin.

 

Other examples:

https://developer.mozilla.org/en-US/docs/Web/CSS/inset

 

posted @   Zhentiw  阅读(8)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用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
点击右上角即可分享
微信分享提示