css教程网 css教程网365css.cn
公告为您打开互联网世界的窗户关于本站
首页/属性速查/布局与定位

inset

top / right / bottom / left 的简写,定位元素的四条边偏移。

语法
inset: <length-percentage>{1,4} | auto
常用值
长度 / 百分比 / auto;inset: 0 表示四边贴齐
初始值
auto
继承
否

运行效果

示例改成别的值试试,差异一眼能看出来
查看代码
HTML
<div class="ib"><span></span></div>
CSS
.ib { position: relative; width: 180px; height: 100px; background: #eef2ff; border-radius: 10px; }
.ib span { position: absolute; inset: 12px 20px; border-radius: 8px; background: linear-gradient(120deg, #2b57ff, #7a4bff); }

使用要点

  • inset: 0 配合 margin: auto 与固定宽高,是经典的居中写法。
  • 逻辑属性对应 inset-inline-start / inset-block-start,多语言项目更适用。