981377660LMT / ts

ts学习
6 stars 1 forks source link

设置 position: absolute; 为什么宽度高度不生效 #459

Open 981377660LMT opened 6 months ago

981377660LMT commented 6 months ago

当元素设置为 position: absolute; 时,元素会脱离文档流,其宽度和高度默认会根据内容来自动调整,而不是继承其父元素的宽度和高度。如果你想要设置宽度和高度,你需要明确地在 .hidden-div 中指定 widthheight 属性。

例如:

.hidden-div {
  position: absolute;
  width: 100px;  // 设置宽度
  height: 100px;  // 设置高度
  .xtable-line-clamp(3);
}

这样 .hidden-div 的宽度和高度就会被设置为 100px。