[英]Is There Any Way To Force An Element Sized Using An Intrinsic Ratio To Fill Its Container Vertically As Well As Horizontally?
If an element's dimensions are defined using an intrinsic ratio : 如果元素的尺寸是使用固有比率定义的:
Sass: 萨斯:
body,
html,
.Wrapper
{
width:100%;
height: 100%;
}
.VideoContainer
{
position: relative;
max-width: 100%;
height: 0;
overflow: hidden;
&.Sixteen-Nine {
padding-bottom: 56.25%;
}
&.Four-Three {
padding-bottom: 75%;
}
}
.VideoContainer iframe,
.VideoContainer object,
.VideoContainer embed
{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
HTML: HTML:
<div class="Wrapper">
<div class="VideoContainer Vimeo Sixteen-Nine">
<iframe src="http://player.vimeo.com/video/109777141?byline=0&portrait=0&badge=0&color=090909" class="js-only" frameborder="0" webkitallowfullscreen="" mozallowfullscreen="" allowfullscreen=""></iframe>
</div>
</div>
Is there any way to contain it so that it resizes to the hight of its container? 有什么方法可以容纳它,以便将其调整为容器的高度?
It will currently resize to the width of its container while maintaining its aspect ratio, however, even with a wrapper that defines an explicit height, it will overspill the container if the width of the wrapper compared to its height is greater than its aspect ratio. 当前,它将在保持其宽高比的同时将其大小调整为容器的宽度,但是,即使使用定义了明确高度的包装纸,如果包装纸的宽度与其高度相比仍大于其长宽比,也会溢出容器。
I need to support IE9+ and I don't want to use JavaScript 我需要支持IE9 +,并且我不想使用JavaScript
can you tell me if this is what you had in mind? 你能告诉我这是否是你的初衷吗?
.Wrapper
{
display: block;
width: 100%;
}
.VideoContainer
{
position: absolute;
height: 100%;
display: block;
width: 100%;
&.Sixteen-Nine {
padding-bottom: 56.25%;
}
&.Four-Three {
padding-bottom: 75%;
}
}
.VideoContainer div
{
height: 100%;
}
.VideoContainer div iframe{
height: 100%;
width: 100%;
}
<div class="Wrapper">
<div class="VideoContainer Vimeo Sixteen-Nine">
<div>
<iframe src="http://player.vimeo.com/video/109777141?byline=0&portrait=0&badge=0&color=090909" class="js-only" frameborder="0" webkitallowfullscreen="" mozallowfullscreen="" allowfullscreen=""></iframe>
</div>
</div>
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.