css - 如何让动态大小的灯箱正确溢出/滚动?

标签 css dynamic overflow lightbox border-box

我确定我做错了一些明显的错误,但我一直无法弄清楚。我的灯箱动态调整大小(百分比宽度),并且我希望灯箱内的内容在较小的屏幕上根据需要垂直滚动,而不会移动内容周围的边框(实际上是框阴影)。

作为补充说明,我需要“容器”div 具有动态高度。当我将容器 div 设置为 height: 100% 时,灯箱会按我想要的方式运行(请参阅下面的代码),但是当我删除高度设置时,溢出不再正常工作。

我的灯箱演示应该有助于澄清我的问题:

http://viewer.zmags.com/publication/a82492b9?viewType=pubPreview

这是我的 CSS:

html{
height: 100%;}

body {
font-family: Verdana, sans-serif;
font-weight: 400;
font-size: 12pt;
color: #FFFFFF;
padding: 0px;
margin: 0px;
background: #FF0000;
height: 100%;
overflow: hidden;}

div.container {
background-color: #6d6d6d;
padding: 20px;
height: 100%; <!-- I want to remove this, but can't figure out a way to get the same functionality without it -->
overflow: hidden;}

div.content {
background-color: #6d6d6d;
overflow: auto;
max-height: 100%;
margin: 0px auto;}

div#tab1 {
box-shadow: 0 0 0 1px #FFFFFF inset, 0 0 0 4px #be854C inset;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;}

还有我的 HTML:

<body>
<div class="container" id="tab1">
<div class="content">
<p>Lightbox content here.</p>
</div>
</div>
</body>
</html>

最佳答案

如果您的浏览器支持要求允许,请考虑绝对定位您的 .container div,并适本地设置其顶部、左侧等:

div.container {
  background-color: #6d6d6d;
  padding: 20px;
  overflow: hidden;
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
}

如果您尝试在页面上放置其他元素,这会有一些缺点,但对于灯箱来说,这是一个合理的解决方案。

关于css - 如何让动态大小的灯箱正确溢出/滚动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26300606/

相关文章:

javascript - 自定义组件库中的相对路径

entity-framework - 如何在 EF.Core 中构建动态 where 过滤器来处理等于、LIKE、gt、lt 等

css - 返回 Safari 9 中的页面时,溢出 y 滚动不起作用

javascript - 动画 css/js 波浪不随窗口大小调整大小

javascript - Bootstrap 表在更改后向 'contenteditable' 类添加边框

html - CSS:垂直滚动两个绝对定位的div,而水平滚动条保持固定

html - 与 Bootstrap 3 重叠的部分

c++ - 未初始化的局部变量并帮助更正

c# - 如何最好地解析任何常量 Lua 表而不将其加载到 Lua VM 中?

HTML 溢出 CSS 不起作用