填充顶部比填充底部“更大”

时间:2017-12-24 07:13:47

标签: html css

我不明白为什么在这个设置中,填充顶部比填充底部大很多倍。尝试调整周围的东西找到罪魁祸首的财产,但到目前为止没有。我注意到,我不小心留下了“在跨度之后,问题已经消失,但不确定这是如何相关的。”

https://jsfiddle.net/3n0yuzs3/1/

body
{
  font-family: sans-serif;
}

#window
{
    background-color: black;
    color: white;
    display: flex;
    flex-direction: column;
    opacity: 1;
    left: 50%;
    bottom: 0px;
    position: fixed;
    width: auto;
    height: auto;
    min-width: 600px;
    min-height: auto;
    max-width: 80vw;
    max-height: 80vh;
    transform: translateX(-50%);
    outline: 0px;
    cursor: default;
    z-index: 5000002;
    zoom: 1;  
}

#container
{
    overflow-y: auto;
    overflow-x: hidden;
    border: none;
    outline: 0;
    margin: 0;
    flex-grow: 1;  
}

#content
{
    font-size: 22px;
    text-align: center;
    overflow-wrap: break-word;
    padding-top: 1.6em;
    padding-bottom: 1.6em;
    padding-left: 1.6em;
    padding-right: 1.6em;  
}

.snack_msg
{
    padding-right: 200px;
    float:left;
}

.snack_btn
{
    color:#5fce49;
    text-transform: uppercase;
    letter-spacing:3px;
    cursor:pointer;
    float:right;
}
<div id='window'>
  <div id='container'>
    <div id='content'>
      <span class='snack_msg'>New message arrived</span>
      <span class='snack_btn' onclick='open_snack_message()'>open</span>
    </div>
  </div>
</div>

1 个答案:

答案 0 :(得分:2)

问题在于浮动元素而不是填充。如下所示,您可以使用所有大小的相同填充:

enter image description here

如果你检查得好,你也会看到你的身高等于 0 ,因为你有浮动元素,而且由于父母没有浮动,它会崩溃(这意味着没有高度)。要解决此问题,您需要将oveflow:auto添加到#content

&#13;
&#13;
body {
  font-family: sans-serif;
}

#window {
  background-color: black;
  color: white;
  display: flex;
  flex-direction: column;
  opacity: 1;
  left: 50%;
  bottom: 0px;
  position: fixed;
  width: auto;
  height: auto;
  min-width: 600px;
  min-height: auto;
  max-width: 80vw;
  max-height: 80vh;
  transform: translateX(-50%);
  outline: 0px;
  cursor: default;
  z-index: 5000002;
  zoom: 1;
}

#container {
  overflow-y: auto;
  overflow-x: hidden;
  border: none;
  outline: 0;
  margin: 0;
  flex-grow: 1;
}

#content {
  font-size: 22px;
  text-align: center;
  overflow-wrap: break-word;
  padding-top: 1.6em;
  padding-bottom: 1.6em;
  padding-left: 1.6em;
  padding-right: 1.6em;
  overflow: auto;
}

.snack_msg {
  padding-right: 200px;
  float: left;
}

.snack_btn {
  color: #5fce49;
  text-transform: uppercase;
  letter-spacing: 3px;
  cursor: pointer;
  float: right;
}
&#13;
<div id='window'>
  <div id='container'>
    <div id='content'>
      <span class='snack_msg'>New message arrived</span>
      <span class='snack_btn' onclick='open_snack_message()'>open</span>
    </div>
  </div>
</div>
&#13;
&#13;
&#13;

以下是一些有用的问题,您可以从中收集更多信息以及更多方法来阻止此行为:

How do you keep parents of floated elements from collapsing?

Why does 'overflow: auto' clear floats? And why are clear floats needed?