【问题标题】:Make elements touch each other with no vertical gaps使元素相互接触,没有垂直间隙
【发布时间】:2020-05-12 11:06:26
【问题描述】:

我在网格中有一些元素。

但是我希望字母和数字能够相互接触。他们之间没有差距。

类似这样的:

目前的代码看起来是这样的:

在 JSX 中,但工作方式与 HTML 相同。

  <ul className='week-forecast-list'>
        <li className='week-forecast-item'>
          <h3 className='week-forecast-day'>
            {formatDateToDay(list[0].dt_txt)}
          </h3>
          <h4 className='week-forecast-temp'>
            {formatTemp(list[0].main.temp)}
            <span className='degrees-icon'>º</span>
          </h4>
          <p>{list[0].weather[0].main}</p>
</li>
</ul>
.week-forecast-list {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}
.week-forecast-item {
  border: 1px solid var(--darkish);
  display: flex;
  flex-direction: column;
}
.week-forecast-day {
  font-size: 8rem;
}
.week-forecast-temp {
  font-size: 8rem;
}

【问题讨论】:

  • 你能发布你的实际 HTML 代码吗?
  • 在没有看到代码的情况下,我会自信地假设您想要将 gap: 10px 设为 0px。
  • 抱歉,我已经更新了。如果您不熟悉,它在 JSX 中的工作方式与 html 相同。
  • &lt;h3&gt;&lt;h4&gt; 上尝试margin:0;
  • 元素上没有边距。

标签: css flexbox css-grid


【解决方案1】:

使用line-height 属性

line-height: 0.75;

【讨论】: