html - 对齐标题、段落和图像
问题描述
我是一个初学者,所以在学习将东西放在我想要的地方时遇到了一些麻烦。
我想移动标题下的段落,使其顶部与图像和标题对齐。
我还想必须向下滚动才能看到下一部分(水电的东西),而不是它在第一部分(风的东西)旁边
我希望这是有道理的,TIA。
.re-format {
display: inline-flex;
}
.re-format img {
padding: 50px 0 0 50px;
width: 200px;
height: 300px;
}
.re-format h3 {
color: #474747;
text-shadow: none;
padding: 40px;
}
.re-format p {
font-family: candara;
color: #474747;
font-size: 20px;
}
<div class="re-format">
<img src="images/wturbine.jpeg">
<h3>Wind Energy</h3>
<p>para about wind <br>para about company<br> para about some other stuff</p>
<img src="images/dam2.jpg">
<h3>Hydro Energy</h3>
<p>para about hydro <br>para about company<br> para about some other stuff</p>
</div>
解决方案
这是想要的效果吗?
解释:
首先,要使内容垂直滚动而不是水平滚动,设置
flex-direction
为column
.其次,我稍微改变了每个“标题+内容”元素的布局。现在这两个元素中的每一个都有自己的封闭 div (
.subsection
)。小节内的图像和文本使用水平弹性框排列(也有其他方法)。
.re-format {
display: inline-flex;
flex-direction: column;
}
.re-format img {
padding-right: 50px;
width: 200px;
height: 300px;
}
.re-format h3 {
color: #474747;
text-shadow: none;
padding: 40px;
}
.re-format p {
font-family: candara;
color: #474747;
font-size: 20px;
}
.subsection-content {
display: flex;
flex-direction: row;
}
<div class="re-format">
<div class="subsection">
<h3>Wind Energy</h3>
<div class="subsection-content">
<img src="images/wturbine.jpeg">
<p>para about wind <br>para about company<br> para about some other stuff</p>
</div>
</div>
<div class="subsection">
<h3>Hydro Energy</h3>
<div class="subsection-content">
<img src="images/dam2.jpg">
<p>para about hydro <br>para about company<br> para about some other stuff</p>
</div>
</div>
</div>
推荐阅读
- angular - 循环上传文件不起作用
- android - OpenGL Z-Fighting 问题
- javascript - 如何使用 javascript 永久更改 html 元素
- javascript - 如何在行导出类 ReusableRay 中修复意外的令牌“导出”
- go - 如何在 for 循环中使用所有处理器内核?
- ruby-on-rails - 导出到 .CSV 时使用带有 self.id 或类似的 Model.where
- mysql - 选择最小值和最大值
- php - 在循环中多次使用 $I++
- javascript - 如何使用 FilePond 将文件作为普通文件元素发送到 Laravel 控制器?
- c++ - 是否可以让函数在 C++ 中返回类型名?