html - 将 div 元素彼此居中定位
问题描述
这是我的代码。请注意,图像的高度大于我想要的 div。我不想要的是另一个包含文本的 div 位于图像的底部。有没有什么办法解决这一问题?另外,我尝试了 margin-bottom 到 feature_details。
.feature_details {
display: inline-block;
width: 40%;
text-align: left;
margin-bottom: 4rem;
}
.feature_display {
display: inline-block;
width: 50%;
}
.feature_display__img {
width: 100%;
height: auto;
}
<div class="feature_section__feature_left">
<div class="feature_details">
<h3 class="feature_name">Reviews that really matter</h3>
<div class="feature_info">
<p>
Insolvers makes it easy to create rich, high-quality content using
the inbuilt editor.
</p>
<p>
Add images, gifs, and media - draft, experiment, and share with your
peers before scheduling.
</p>
</div>
</div>
<div class="feature_display">
<div class="feature_display__img">
<img src="https://i.pinimg.com/564x/e9/29/1c/e9291cc39e820cd4afc6e58618dfc9e0.jpg" alt="Feature display" />
</div>
</div>
</div>
解决方案
添加vertical-align: middle;
到您的图像容器。
.feature_details {
display: inline-block;
width: 40%;
text-align: left;
margin-bottom: 4rem;
}
.feature_display {
display: inline-block;
width: 50%;
vertical-align: middle;
}
.feature_display__img {
width: 100%;
height: auto;
}
<div class="feature_section__feature_left">
<div class="feature_details">
<h3 class="feature_name">Reviews that really matter</h3>
<div class="feature_info">
<p>
Insolvers makes it easy to create rich, high-quality content using the inbuilt editor.
</p>
<p>
Add images, gifs, and media - draft, experiment, and share with your peers before scheduling.
</p>
</div>
</div>
<div class="feature_display">
<div class="feature_display__img">
<img src="https://i.pinimg.com/564x/e9/29/1c/e9291cc39e820cd4afc6e58618dfc9e0.jpg" alt="Feature display" />
</div>
</div>
</div>
推荐阅读
- javascript - 如何使用标头、有效负载和正文制作 httpclient 获取请求?角度 API
- python - Pygame(我正在尝试为我的课程制作一个与 agar.io 非常相似的游戏)我怎样才能让它让背景移动
- c - 将平台设置为 WIN32,以便在 Visual Studio 2019 中从命令行编译 C 代码
- node.js - 运行 yo @superset-ui/superset 时遇到权限问题
- rest-assured - 放心获取数组对象名
- networking - 如何根据Netlogo中的正态分布为网络中的每只海龟分配不同的值
- javascript - 匹配两个字符串之外的所有内容
- amazon-web-services - 如何指定要使用多少个 ec2 实例来分配负载
- r - rpart 摘要:图中缺少变量
- sql-server - 复选框从 VB.NET 插入到数据库