html - 固定 div 的右侧溢出其父级

标签 html css position fixed

我试图将一个 position:fixed div 放入另一个 div 中。我想要一个具有 width:100%; 的固定 div,因此它同时适用于移动设备和桌面设备。

这是我的 JSfiddle

SF 想要一些代码:

<div id="container">
  <div id="item">This div is good div</div>
  <div id="fixed">Right side of this div overflow its parent!!! </div>
</div>

最佳答案

具有 position:fixed; 的元素会忽略父级大小,因为它仅相对于视口(viewport):

MDN:

Fixed positioning is similar to absolute positioning, with the exception that the element's containing block is the viewport.

你可以:

  1. 尝试为其指定 position:absolute; 并将容器设置为 position:relative;

  2. 使用position:fixed;并显式设置大小。

关于html - 固定 div 的右侧溢出其父级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38775152/

相关文章:

html - 在 html 页面中选择国家下拉列表

html - 如何在CSS中制作一个椭圆形?

css - 嵌套媒体查询

css - 包含@font-faces 的特定语言 LESS 类不起作用

css - IE 无法识别悬停时的顶部定位

r - 更改 R Scatterplot3D 中的 ylab 位置

javascript - 如何正确地将 html/css/js 主题实现到 Vue 中?

css - float <button> 对象

javascript - 如何使输入值首字母大写?

html - 具有固定位置和相对位置的重叠 div