【问题标题】:How to use top margin perfectly? [duplicate]如何完美使用上边距? [复制]
【发布时间】:2021-05-22 15:05:23
【问题描述】:

#container {
  width: 350px;
  height: 300px;
  background-color: tomato;
  margin: 20px auto;
}

h1 {
  margin: 10px;
  background-color: blue;
  overflow: auto;
}
<div id="container">
  <h1>Hello</h1>
</div>

这两个元素应该有边距,但没有任何边距。如何在它们之间放置边距

【问题讨论】:

  • 你的问题不清楚

标签: html css margin heading


【解决方案1】:

在容器上将display 设置为table

#container {
  width: 350px;
  height: 300px;
  background-color: tomato;
  margin: 20px auto;
  display:table;
}

h1 {
  margin: 10px;
  background-color: blue;
  overflow: auto;
}
<div id="container">
  <h1>Hello</h1>
</div>

【讨论】:

    猜你喜欢
    • 2017-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-14
    • 1970-01-01
    相关资源
    最近更新 更多