多列均匀布局



等宽高比
常用于图片,固定比例的盒子
<style>.constant-width-to-height-ratio {background: #333;width:50%;/* 容器宽度,此时以占父容器的百分比来定义 */}.constant-width-to-height-ratio::before {content: '';/* 决定容器的高度,以高度占容器的百分比确定高度,从而也固定宽高比 */padding-top: 50%;float: left;}.constant-width-to-height-ratio::after {content: '';display: block;clear: both;}</style><body><div class="constant-width-to-height-ratio"></div></body>
要创建具有固定比例的一个盒子,所有你需要做的就是给 div 设置一个 padding:
使用20%的padding-bottom使得框等于其宽度的20%的高度。与视口宽度无关,子元素的div将保持其宽高比(100%/ 20%= 5:1)。
.container {
height: 0;
padding-bottom: 20%;
position: relative;
}
.container div {
border: 2px dashed #ddd;
height: 100%;
left: 0;
position: absolute;
top: 0;
width: 100%;
}
多列等高布局

要在右边的列加个border-bottom
需要面对的问题是:左边的高度是由图片撑开的,随着设备屏幕的增大缩小图片会自适应变化。
右边的文字部分是由文字撑开高度的。虽然文字也是rem为单位随着屏幕变化而变化但是变化的程度终究没有图片来的陡峭。
如果通过解决直接原因的办法解决:
我想的是右边加个padding-top ,padding-bottom 的高度。然后撑开右边的高度。
然而还是会面临rem变化与图片变化程度不一的问题。
而解决问题的根本路径便是:让左右两列等高。
1.因为是用到flex布局。
所以:使用align-items:stretch属性即可撑开
