position: fixed; 默认情况下不等于父元素的宽度,而是根据内容的宽度来确定宽度。但可以通过设置'left'和'right'属性来使其宽度等于父元素的宽度。

例如:

.parent {
  position: relative;
  width: 500px;
  height: 200px;
}

.child {
  position: fixed;
  left: 0;
  right: 0;
  height: 100px;
  background-color: red;
}

在上面的例子中,父元素的宽度为500px,子元素的宽度通过设置'left'和'right'为0来与父元素的宽度相等。


原文地址: http://www.cveoy.top/t/topic/o6QS 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录