html - Flexbox - 等高图像列

标签 html css flexbox

我有一个像这样的简单 flexbox 布局

   html,body {
       margin:0;
       padding:0;
   }
   
   body {
   height:100%;
   width:100%;
   }
   
   .panel-grid
   {
   -webkit-align-items: flex-start;
    align-items: flex-start;
	margin-bottom:30px;
	display:flex;
	justify-content:space-between;
	}
	
	#section-163 {
	width:calc(61.8034% - ( 0.38196600790794 * 30px ) );
	align-self:auto;
	}
	
	#section-260
	{
	width:calc(38.1966% - ( 0.61803399209206 * 30px ) );
	align-self:auto;
	}
	
	.myimage {
	object-fit:cover;
	width:100%;
	height:100%;
	}
	
<div class="panel-grid panel-no-style">
	<div id="section-163" class="panel-grid-cell">
		<div class="rty-panel widget widget_image-widget panel-first-child panel-last-child" style="height: 100%;">
			<div class="rty-widget-image-widget rty-widget-image-widget-base" style="height: 100%;">
				<img class="myimage" src="https://dummyimage.com/1600x900/000/fff">
			</div>
		</div>
	</div>
	
	<div id="section-260" class="panel-grid-cell">
		<div class="rty-panel widget widget_image-widget panel-first-child panel-last-child" style="height: 100%;">
			<div class="rty-widget-image-widget rty-widget-image-widget-base" style="height: 100%;">
				<img class="myimage" src="https://dummyimage.com/500x600/000/fff">
			</div>
		</div>
	</div>
</div>  

我正在尝试使用 object-fit 来裁剪图像以匹配高度。

我哪里错了?

最佳答案

尝试从 .panel-grid 中删除 align-items: flex-start。它覆盖了 stretch 默认值。

 .panel-grid {
   /* -webkit-align-items: flex-start; */
   /* align-items: flex-start; */
   margin-bottom: 30px;
   display: flex;
   justify-content: space-between;
 }

html,
body {
  margin: 0;
  padding: 0;
}

body {
  height: 100%;
  width: 100%;
}

.panel-grid {
  /* -webkit-align-items: flex-start; */
  /* align-items: flex-start; */
  margin-bottom: 30px;
  display: flex;
  justify-content: space-between;
}

#section-163 {
  width: calc(61.8034% - ( 0.38196600790794 * 30px));
  align-self: auto;
}

#section-260 {
  width: calc(38.1966% - ( 0.61803399209206 * 30px));
  align-self: auto;
}

.myimage {
  object-fit: cover;
  width: 100%;
  height: 100%;
}
<div class="panel-grid panel-no-style">
  <div id="section-163" class="panel-grid-cell">
    <div class="rty-panel widget widget_image-widget panel-first-child panel-last-child" style="height: 100%;">
      <div class="rty-widget-image-widget rty-widget-image-widget-base" style="height: 100%;">
        <img class="myimage" src="https://dummyimage.com/1600x900/000/fff">
      </div>
    </div>
  </div>

  <div id="section-260" class="panel-grid-cell">
    <div class="rty-panel widget widget_image-widget panel-first-child panel-last-child" style="height: 100%;">
      <div class="rty-widget-image-widget rty-widget-image-widget-base" style="height: 100%;">
        <img class="myimage" src="https://dummyimage.com/500x600/000/fff">
      </div>
    </div>
  </div>
</div>

关于html - Flexbox - 等高图像列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50932663/

相关文章:

html - 动态调整图像大小

css - 当溢出设置为自动时, flex 元素不会在交叉轴上拉伸(stretch)

css - 在 Safari 中使用 Flex 使内容居中

html - 如何开始一个新行并将换行符与 flexbox 中的另一个元素对齐?

javascript - 删除带有重叠 png button-images 的按钮残留物

html - 使用 Chrome 时图像不会显示在 div 中

html - Bootstrap 面板和列表未显示

javaScript 淡入 OnLoad

jquery - 如何在 jQuery 中获取变换矩阵和 matrix3d 值?

html - 试图让 div 在父 div 中保持对齐