javascript - CSS - 匹配高度
问题描述
我有一个像这样的简单 flexbox 布局......
html, body {
margin:0;
padding:0;
}
.container {
display:flex;
flex-direction:row;
}
.section1 {
width:50%;
}
.section2 {
width:50%;
}
.img_16x9_holder {
display: block;
height: 0;
padding-bottom: 56.25%;
overflow: hidden;
}
img {
max-width:100%;
}
<div class="container">
<div class="section1">
<div class="img_16x9_holder">
<img src="http://lorempixel.com/g/800/800/" alt="800x800image">
</div>
<div class="section2">
<div class="img_matchheight_holder">
<img src="http://lorempixel.com/g/300/650/" alt="300x650image">
</div>
</div>
</div>
我正在尝试将左侧图像设置为 16x9 的比例,然后右侧的图像应该裁剪并填充以匹配左侧的高度。
这就是我想要达到的目标..
我可以单独使用 CSS 来做到这一点,还是最好看看 javascript 高度匹配解决方案?
解决方案
你可以在这里获得更多信息
这是一个例子:
html, body {
margin:0;
padding:0;
}
.container {
display:flex;
}
.section img{
height:100%;
}
#sec-1 img{
/*resize image with % or fixed width depending on the image size*/
width:50%;
}
#sec-2 img{
/*resize image with % or fixed width depending on the image size*/
width:50%;
}
<div class="container">
<div id="sec-1" class="section">
<img src="http://lorempixel.com/g/800/800/" alt="800x800image">
</div>
<div id="sec-2" class="section">
<img src="http://lorempixel.com/g/300/650/" alt="300x650image">
</div>
</div>
推荐阅读
- node.js - 我无法使用 sequelize 运行具有多个搜索参数的简单搜索
- javascript - html表单,如何通过传统post和jquery ajax同时向各个服务器发送数据
- azure - 无法在 Azure 门户中保存 JSON 配置文件更新
- javascript - How to autofocus on a specific input field in React (after clicking on another element)?
- flutter - 如何根据 Flutter 中另一个文本字段的值自动设置文本字段的值?
- flutter - 我如何全局处理用户交互?
- r - 插入行以填写 R 中缺少的日期
- angular - 无法在 Windows 10 代理网络系统中安装 angular-cli
- reactjs - React TypeScript - 传递回调函数
- javascript - 将响应正文 blob 转换为 json 或 javascript 中的纯文本