html - 怎么能缩放到兄弟姐妹的高度?
问题描述
标题非常自我描述。请记住,容器元素应该有自己的宽度和高度,如示例所示。虽然这个示例是用 flexbox 编写的,但我不介意使用其他方法,只要它是纯 HTML/CSS 即可。
我觉得这应该是微不足道的,但我一直在寻找一段时间,包括 Stack Overflow 上的相关答案,我似乎无法找到任何令人满意的答案。
body {
margin: 0;
padding: 0;
width: 100%;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
img {
margin-left: 8px;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<div>
<h1>Lorem Ipsum</h1>
<h2>Dolor Sit Amet, here's some extra text</h2>
</div>
<img src="https://lorempixel.com/g/64/64/" />
</body>
</html>
解决方案
如果您添加更多的 div,这是可能的。
.wrapper {
display: flex;
align-items: stretch;
}
img {
height: 100%;
}
<body>
<div class="wrapper">
<div>
<h1>Lorem Ipsum</h1>
<h2>Dolor Sit Amet, here's some extra text</h2>
</div>
<div class="img-wrap">
<img src="https://lorempixel.com/g/64/64/">
</div>
</div>
</body>
推荐阅读
- javascript - Javascript对象数组未显示在反应js中使用地图的预期值
- spring - 通过弹簧数据和 f:viewAction 加载实体然后访问其属性之一时出现延迟加载异常
- javascript - 多个选择的复选框下拉列表,由 ;
- python-3.x - 如何从 Python 中的列表中非均匀采样
- java - 两个数组的插入排序
- jenkins - 通过jenkins执行时找不到ansible-playbook
- html - 如何修复 reactjs 中的页面刷新问题
- c - 没有使用 fopen() 创建文件;为什么,或者他们在哪里?
- c - 如何检查我的变量是否等于 NULL ?C
- typo3 - Typo3:安装/激活扩展后 ClassAliasLoader 出错