【发布时间】:2021-09-10 10:02:43
【问题描述】:
HTML:(有 5 个这样的li's)
<ul id='today-forecast'>
<li class='today-item'>
<div class='time'>Time</div>
<img class='icon'></img>
<div class='temp'>Temp</div>
</li>
</ul>
CSS:
#today-forecast {
display: flex;
list-style: none;
align-items: center;
justify-content: center;
}
#today-forecast .today-item {
flex-grow: 1;
display: flex;
flex-direction: column;
justify-content: flex-start;
align-items: center;
background-color: blue;
}
#today-forecast .today-item img{
display: block; background-color: blue; }
JS
export function iconSetter(img, name) {
//img <-img tag selected from document, name <- name of icon
name = '01n' //from: https://openweathermap.org/weather-
//conditions
img.src = `http://openweathermap.org/img/wn/${name}@2x.png`;
}
使用 flexbox 网格线预览:
背景颜色表明问题可能不在于图像,而在于容器。
.today-item 的孩子没有 flex-grow: 1。我还尝试了 justify-content: flex-start,但它没有用。设置高度并不能解决这里的问题,但它可以解决我页面的另一部分。
【问题讨论】:
-
添加代码sn-p。图片使用一些在线图片地址。
-
@SuryanshSingh 完成
-
您问题中的代码没有重现问题。