html - 为什么我的 CSS flexbox 不会影响我的 div,即使它适用于其他部分
问题描述
我正在尝试使用 flexbox 将文本div
和图片div
彼此对齐,即使我之前做过同样的事情并且效果很好,但这次由于某种原因它不起作用。
这是我的 HTML 和 CSS 代码:
.hero-introduction {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
flex: 1 1 40rem;
}
.hero-images {
flex: 1 1 40rem;
}
<section class="hero">
<div class="hero-introduction">
<h2>Elena Joy <br> Photography</h2>
<p>paragraphe here</p>
<a href="#gallery">Gallery</a>
</div>
<div class="hero-images">
<img class="hero-elena" src="images/elena-joy.png" alt="picture of elena joy">
</div>
</section>
解决方案
只需设置display:flex
为 .hero 类和flex-direction:row
.hero{
display: flex;
flex-direction: row;
}
.hero-introduction {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
flex: 1 1 40rem;
}
.hero-images {
flex: 1 1 40rem;
}
<section class="hero">
<div class="hero-introduction">
<h2>Elena Joy <br> Photography</h2>
<p>paragraphe here</p>
<a href="#gallery">Gallery</a>
</div>
<div class="hero-images">
<img class="hero-elena"
src="images/elena-joy.png"
alt="picture of elena joy">
</div>
</section>
推荐阅读
- r - 计算朴素贝叶斯分类器的准确度、精确度和召回率(手动计算)
- javascript - 我们如何键入一个类工厂来生成一个给定对象字面量的类?
- xaml - 如何在 uwp 中默认 navigationviwe 显示模式?
- java - 为数字对象实现 Parcelable 时出现 ClassCastException
- angular - Angular 5:我们如何使用 routeroutlet 将数据从嵌套组件传递到父组件?
- bash - 终端 - 关闭所有终端窗口/进程
- kubernetes - ingress-nginx 没有 IP 地址
- python - 我想将所有特征集合转换为 Leaflet 中的几何集合
- wordpress - ReactJS 应用程序上的动态 URL 与使用 Rest API 的 wordpress 相同 - Wordpress
- python - 控制台关闭后如何保持浏览器打开