html - CSS并排与flexbox相同的高度
问题描述
我试图让 2divs
并排使用flexbox
,但其中包含文本的 div 比图像侧高,我不知道为什么。
.serviceEntry {
display: flex;
margin-bottom: 2rem;
}
.serviceImg,
.serviceContent {
flex: 1;
}
.serviceContent {
color: white;
background-color: #93AEC2;
padding: 0px 10px;
line-height: 2;
}
<div class="serviceEntry">
<div class="serviceImg">
<img src="https://hope.rudtek.dev/wp-content/uploads/2020/08/hopewellness-cbt-falls-church-37-1024x668.jpg" class="attachment-large size-large" alt="" srcset="https://hope.rudtek.dev/wp-content/uploads/2020/08/hopewellness-cbt-falls-church-37-1024x668.jpg 1024w, https://hope.rudtek.dev/wp-content/uploads/2020/08/hopewellness-cbt-falls-church-37-300x196.jpg 300w, https://hope.rudtek.dev/wp-content/uploads/2020/08/hopewellness-cbt-falls-church-37-768x501.jpg 768w, https://hope.rudtek.dev/wp-content/uploads/2020/08/hopewellness-cbt-falls-church-37-1536x1001.jpg 1536w, https://hope.rudtek.dev/wp-content/uploads/2020/08/hopewellness-cbt-falls-church-37.jpg 2000w"
sizes="(max-width: 1024px) 100vw, 1024px" width="1024" height="668">
</div>
<div class="serviceContent">
<h3><a href="https://hope.rudtek.dev/services/women/">Women</a></h3>
We provide specialized individual treatment and cognitive behavioral therapy to empower women in all aspects of life, including personal growth, overcoming mood and anxiety disorders, and navigating major life transitions.
</div>
</div>
这是我的小提琴:https ://jsfiddle.net/bu1q359z/
解决方案
display:flex
也可用于.serviceImg
匹配text
和图像height
(并排)
现场演示:(运行片段并单击整页以查看它的工作)
.serviceEntry {
display: flex;
margin-bottom: 2rem;
}
.serviceContent {
flex: 1;
}
.serviceImg {
display: flex;
flex: 1;
}
.serviceContent {
color: white;
background-color: #93AEC2;
padding: 0px 10px;
line-height: 2;
}
<div class="serviceEntry">
<div class="serviceImg">
<img src="https://hope.rudtek.dev/wp-content/uploads/2020/08/hopewellness-cbt-falls-church-37-1024x668.jpg" class="attachment-large size-large" alt="" srcset="https://hope.rudtek.dev/wp-content/uploads/2020/08/hopewellness-cbt-falls-church-37-1024x668.jpg 1024w, https://hope.rudtek.dev/wp-content/uploads/2020/08/hopewellness-cbt-falls-church-37-300x196.jpg 300w, https://hope.rudtek.dev/wp-content/uploads/2020/08/hopewellness-cbt-falls-church-37-768x501.jpg 768w, https://hope.rudtek.dev/wp-content/uploads/2020/08/hopewellness-cbt-falls-church-37-1536x1001.jpg 1536w, https://hope.rudtek.dev/wp-content/uploads/2020/08/hopewellness-cbt-falls-church-37.jpg 2000w" sizes="(max-width: 1024px) 100vw, 1024px" width="1024" height="668">
</div>
<div class="serviceContent">
<h3><a href="https://hope.rudtek.dev/services/women/">Women</a></h3>
We provide specialized individual treatment and cognitive behavioral therapy to empower women in all aspects of life, including personal growth, overcoming mood and anxiety disorders, and navigating major life transitions.
</div>
</div>
推荐阅读
- javascript - NativeScript Javascript 对象属性未定义
- python - 如何将一个模型的一个或多个属性(FIELD)值动态添加到同一应用程序中的另一个模型
- docker - 如何更改 docker 容器的子网和 IP 地址?
- java - 未从 Active Directory 导入默认组
- javascript - 如何使用传感器值检测设备方向?
- visual-c++ - Eigen3 矩阵-矩阵乘法比自己的 openmp 并行代码快 30 倍
- xcode - Xcode 在段错误后切换回代码编辑器
- ruby-on-rails - 如何在我的上传器中创建一个条件,以便只处理特定文件
- sql-server - 无法打开 SSRS 2012 门户的默认模板
- c# - 以模态渲染视图