css - 在 Firefox 中使用 absolute 和 flex 有位置问题
问题描述
我的 html 标签是这样的,当我使用绝对和 flex 时,我在 Firefox 中遇到问题。我需要<h2>
在someBox
底部,但它someBox
在 Firefox 中浮动。
<div class="leftPointBox">
<a class="someBox">
<div class="wrap">
<picture>
<source media="(max-width: 414px)" srcset="img/420x315.jpg">
<source media="(min-width: 413px)" srcset="img/800x600.jpg">
<img src="img/800x600.jpg" srcset="img/420x315.jpg 414w, img/800x600.jpg 1024w">
</picture>
</div>
<h2>TITLE</h2>
</a>
</div>
css(scss):</p>
.someBox {
position: relative;
overflow: auto;
}
.leftPointBox{
width: 380px;
float: left;
h2 {
text-align: left;
font-weight: 600;
color: #ffffff;
font-size: 20px;
background-color: #004E98;
position: absolute;
bottom: 0;
width: 360px;
padding: 10px;
margin-bottom: 0;
}
}
.someBox .wrap {
height: 285px;
}
.wrap {
position: relative;
overflow: hidden;
display:flex;
align-items:center;
justify-content:center;
margin-bottom: 10px;
img {
max-width: 100%;
max-height: 100%;
@media screen and (max-width: 1024px){ flex: inherit; max-width: 100%;}
}
}
解决方案
在某些情况下,浮点数和弹性盒不太喜欢对方。我删除了所有浮动以保持文档流完整,并将 flexbox.wrap
从.someBox
. 现在,使用align-self您可以将标题放在底部。
我将高度设置.someBox
为 600px 只是为了演示标题将位于底部。
.someBox {
display: flex;
flex-wrap: wrap;
height: 600px; /* Demo purpose only */
}
.leftPointBox {
width: 380px;
}
.leftPointBox h2 {
text-align: left;
font-weight: 600;
color: #ffffff;
font-size: 20px;
background-color: #004E98;
padding: 10px;
margin-bottom: 0;
align-self: flex-end;
width: 100%;
}
.someBox .wrap {
height: 285px;
}
.wrap {
}
.wrap img {
max-width: 100%;
max-height: 100%;
}
<div class="leftPointBox">
<a class="someBox">
<div class="wrap">
<picture>
<source media="(max-width: 414px)" srcset="https://via.placeholder.com/420x315">
<source media="(min-width: 413px)" srcset="https://via.placeholder.com/800x600">
<img src="https://via.placeholder.com/800x600" srcset="https://via.placeholder.com/420x315 414w, https://via.placeholder.com/800x600 1024w">
</picture>
</div>
<h2>TITLE</h2>
</a>
</div>
推荐阅读
- javascript - 将表格行和以下单元格设为必填字段
- c++ - 如何访问整个地图的值
- c# - c#中的I/O级联
- ios - 在捆绑资源 ios 离子目标 c 中打印时,Json 文件为空
- php - 在 PHP 中存储兄弟元素的属性和内部 html
- ios - 如何在 Swift 中将 ImageView 拖入 CollectionView 并将 CollectionView 项拖入 ImageView,如 tinder App 配置文件编辑
- list - 计算列表中的出现次数
- mysql - 日期之间的平均差距mysql
- android - 如何在一个视频中添加多个 gif watermakr 在android中使用 ffmpeg
- python - Python:将复杂的类似列表的字符串转换为列表(没有用于混合字节和非字节文字的 SyntaxError)