javascript - 窗口调整大小时修复div

标签 javascript jquery html css

我有一个 div,它有固定的位置和 bottom 0 显示在窗口的底部。

我的问题是当窗口调整大小时,这个 div 向上移动并进入其他元素。例如,当我在 chrome 中打开控制台时,这个 div 会跳转到 facebook 中固定位置的其他元素,例如 friend 列表,当我打开控制台框时,元素会向上跳转,但会隐藏向上元素。

请帮助我如何在调整窗口大小时修复 div。

最佳答案

CSS 位置固定:

Do not leave space for the element. Instead, position it at a specified position relative to the screen's viewport and doesn't move when scrolled. When printing, position it at that fixed position on every page. Fixed positioning is similar to absolute positioning, with the exception that the element's containing block is the viewport. This is often used to create a floating element that stays in the same position even after scrolling the page. - by Mozilla MDN

换句话说,当您使用 position: fixed; 时,会将元素从文档的常规流中移除。

How I can fix div in Window Re-size?

解决方案: 没有办法用 CSS 做到如你所愿。您必须删除 position: fixed; 因为当您将 bottom: 0pxposition: fixed; 设置到您的元素时,这并不重要您的浏览器或窗口的大小(垂直)是多少,因为 position: fixed; 元素将始终出现在视口(viewport)屏幕底部的 0px 处。

关于javascript - 窗口调整大小时修复div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25709274/

相关文章:

javascript - 如何用 Jest 模拟 uuid

javascript - Plottable.Plots.Rectangle 创建宽度为 0 的矩形

javascript - 在 jQuery 中切换 div 的高度

javascript - 渲染backbone.js Collection View 时遇到问题。在我的初始化函数中获取“未定义”的 "Uncaught TypeError: Cannot call method '

javascript - 将 JavaScript 变量拆分为 2 个,其中 X 分隔 2 个数字

javascript - 在 HTML 输入字段中选择文件时显示确认

Javascript表单验证onclick按钮没有错误但也不起作用

javascript - 动画在开始前跳到0

javascript - HTML 中的链接下拉列表和文本框

jquery - 将类随机添加到两个 div 之一