让子级span / div占用父div的100%宽度和自动高度

时间:2018-02-25 23:50:11

标签: javascript html css css3

我在div中有几个跨距,我想知道的是我如何让跨度占据父div的100%宽度,但这些跨度的高度应该是自动的。 CSS:

.parent {
    position: fixed;
    width: 100%;
    height: 80px;
    top: 0;
    left: 0;
    display: flex;
    justify-content: space-between;
    padding: 0px 20px;
    box-sizing: border-box;
    z-index: 90;
    background: #4070da;
    color: white;
    font-size: 1.5em;
}
.parent span{
    width: 100%;
    display: block;
    align-items: center;
}

HTML:

<div class="parent">
  <span>Depart</span>
  <span>07</span>
  <span>Mar 2018</span>
</div>

我希望实现这样的目标: Date Image

1 个答案:

答案 0 :(得分:4)

只需使用常规方法执行此操作并放弃弹性框方法:

.parent {
    position: fixed;
    width: 100%;
    height: 80px;
    top: 0;
    left: 0;
    padding: 0px 20px;
    box-sizing: border-box;
    z-index: 90;
    background: #4070da;
    color: white;
    font-size: 1.2em;
}
.parent span {
    width: 100%;
    display: block;
    text-align: center;
}
<div class="parent">
  <span>Depart</span>
  <span>07</span>
  <span>Mar 2018</span>
</div>