我遇到了一些
的问题
外部的
设置了最小高度,但是内部的
高度各不相同。由于内部的
采用绝对定位,它们不会影响外部的高度。有没有办法让这些内部的
影响外部的高度呢?
我使用绝对定位样式来设置这些
,以便它们都从容器
的顶部开始。
我遇到了一些
外部的
我使用绝对定位样式来设置这些
position: relative;
以及其他子元素设置position: absolute; top:0; left: 0;
来解决,这样可以确保容器的高度与第一个元素的高度相同。由于我的CSS过渡幻灯片使用了不透明度属性,在整个幻灯片的过程中容器尺寸不会改变。display: none;
,我猜测是因为这个原因)。display: inline-table, height: auto;
,这对我有用。这是一个早就应该有的跨浏览器解决方案,不再需要静态的width
,也不再需要em
hack。
<style>
/* clearfix */
.container:after {
content: '';
display: table;
clear: left;
}
.page {
float: left; /* display side-by-side */
width: 100%; /* be as wide as parent */
margin-right: -100%; /* take up no width */
}
</style>
<div class="container">
<div class="page"></div>
<div class="page"></div>
</div>
在寻找解决这个问题的方法时,我很惊讶地发现它是如此简单。尽管.page
元素没有绝对定位,但是通过这种方法仍然可以实现所有相同的目标,几乎不需要付出任何代价。
这里有一个演示:https://jsfiddle.net/eqe2muhv/
当然,这也适用于内联块。虽然您可能需要将容器的font-size
或letter-spacing
设置为0
。我还建议在.page
上使用vertical-align: top
,以模拟常规块元素。
这里有一个演示:https://jsfiddle.net/dzouxurs/8/
如果您希望它们处于同一水平面上,可以简单地将div浮动。
我已经完成了这个任务,没有使用任何JS
。只用了CSS:
.frame {
max-height: calc(100vh - 283px); // 283px gives me some space at the botoom of the frame
}
也许你可以尝试使用 max-height: calc(100% - 50%);
如果居中显示的内容非常短小,这将起作用。
position:absolute;
top:0;
bottom:0;
margin:auto;
width:auto;
height:auto
max-height: calc(100% - 50%);
...etc...
在需要自动高度的元素上测试display: inline-block
。