Flexbox - Equal height image columns

偶尔善良 提交于 2020-01-13 06:09:23

问题


I have a simple flexbox layout like this

   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>  

I am trying to use object-fit to get the images to crop so that the height is matched.

Where am i going wrong?


回答1:


Try removing align-items: flex-start from .panel-grid. It's overriding the stretch default.

 .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>


来源:https://stackoverflow.com/questions/50932663/flexbox-equal-height-image-columns

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!