简体   繁体   English

有什么方法可以强制使用本征比调整大小的元素垂直和水平填充容器?

[英]Is There Any Way To Force An Element Sized Using An Intrinsic Ratio To Fill Its Container Vertically As Well As Horizontally?

Sassmeister here 萨斯迈斯特在这里

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&amp;portrait=0&amp;badge=0&amp;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&amp;portrait=0&amp;badge=0&amp;color=090909" class="js-only" frameborder="0" webkitallowfullscreen="" mozallowfullscreen="" allowfullscreen=""></iframe>
    </div>
 </div>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何强制 SVG 水平填充其容器? - How do I force an SVG to fill its container horizontally? 如何使用CSS使HTML元素填充动态尺寸的容器 - How to make a HTML element fill a dynamically sized container using CSS 如何创建一个容器,其中divs水平和垂直填充(并在4边有边距)? - How to create a container where divs fill it horizontally and vertically (and with margin on 4 sides)? 中心容器水平和垂直 - Center container horizontally and vertically 请保持其长宽比不超过一定高度。 其中的文字应垂直和水平居中 - Div to keep its aspect ratio and not exceed certain height. The text inside it should be vertically and horizontally centered 用Div水平和垂直填充空间 - Fill in Space Horizontally and Vertically With Divs 有没有一种 CSS 方法可以按照黄金比例垂直定位 HTML 元素? - Is there a CSS way to position an HTML element vertically following the golden ratio? 如何水平对齐伪元素与元素及其容器 - How to horizontally align pseudo element with element and its container 具有固有比例的响应式DIV,可水平和垂直缩放 - Responsive DIV with Intrinsic ratios which scales horizontally and vertically 在视口中垂直和水平居中HTML元素的最佳方法是什么? - What is the best way to vertically and horizontally center an HTML element within the viewport?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM