css - 如何保持内联 2 个具有最小宽度的固定元素?

标签 css css-position

有 2 个固定的(不能更改)内联 block 和它们的最小宽度。当我试图调整窗口大小时(宽度小于最小值),它们相互重叠。有什么建议吗?如何设置整个页面的最小宽度?

<div style="position:fixed;left:0;top:0;bottom:0;width:40%;min-width:500px;border:2px solid red;margin:5px;">&nbsp;</div>
<div style="position:fixed;right:0;top:0;bottom:0;width:40%;min-width:500px;border:2px solid blue;margin:5px;">&nbsp;</div>

最佳答案

简短的回答是,而不是不改变那个position: fixed

看看 position: fixed 的实际含义:

fixed
Do not leave space for the element. Instead, position it at a specified position relative to the screen's viewport and don't move it when scrolled. When printing, position it at that fixed position on every page.

https://developer.mozilla.org/en-US/docs/Web/CSS/position

而且由于您无法控制视口(viewport)的宽度...

绝对位置应该可以,然后你可以将你的 body 设置成这样:

body {
    min-width: 1020px;
    position: relative;
    min-height: 100%;
}
html{
  height: 100%;
}

http://jsfiddle.net/1forkath/

关于css - 如何保持内联 2 个具有最小宽度的固定元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29710489/

相关文章:

html - Ruby on Rails - 导入 Bootstrap 错误 "File not found or unreadable"

html - 添加新内容时如何使我的网站流畅地扩展?

html - z-index 在表内不起作用

javascript - 保持风格固定输入直到改变

html - 如何让一个div占据所有剩余的高度

javascript - 尝试使输入框通过单击按钮出现 - Javascript

html - 绝对位置内的绝对定位

CSS:position:absolute div inside position:relative div——我做错了什么?

javascript - 绝对定位div的布局问题

css - 我如何 float 这些字段集?