将div顶部对齐兄弟div的底部

时间:2016-09-22 13:32:21

标签: html css flexbox

我想将dropdownContainer放在inputContainer下方,但dropdownContainer内没有autocompleteContainer

滚动时,dropdownContainer应与inputContainer一起移动。删除或添加令牌div时相同。

如果我从dropdownContainer移除位置:绝对,它正确对齐,但显示在autocompleteContainer

我更愿意在没有JS / jQuery的情况下这样做,但如果没有其他选择,我会使用它。

这是一个代码链接:http://codepen.io/rishadjb/pen/LRxzpN

谢谢。

.mainContainer{
  width:700px;
    position: relative;
}
.autocompleteContainer{
  background: none repeat scroll 0 0 #ececec;
    float: left;
    width: 100%;
/*   height:60px; */
    max-height: 100px;
    z-index: 1;
    padding: 4px 0;
    display: flex;
    flex-wrap: wrap;
    cursor: text;
    text-align: left;
    background-color: #e4e4e4;
    overflow-y: auto;
    overflow-x: hidden;
}

.token{
      background-color: #f7982f;
    border-radius: 10px;
    color: #fff;
    display: flex;
    font-family: sans-serif;
    font-size: 13px;
    font-weight: 400;
    margin: 2px;
    padding: 2px 5px;
}

.inputContainer{
      flex-grow: 1;
  position:relative;
}

.autoCompleteInput{
      border: medium none;
    outline: none;
    width: 100%;
    padding: 2px 12px;
    background: transparent;
    color: #008cc1;  
}

.dropdownContainer{
  height:60px;
  width:100%;
  position:absolute;
  background:red;
  z-index:999;
  border:1px solid blue;
}
<div class="mainContainer">
  <div class="autocompleteContainer">
    <div class="token">TokenToken</div>
    <div class="token">TokenTokenTokenToken</div>
    <div class="token">TokenToken</div>
    <div class="token">TokenTokenTokenToken</div>
    <div class="token">TokenToken</div>
    <div class="token">TokenTokenTokenToken</div>
    <div class="token">TokenToken</div>
    <div class="token">TokenTokenTokenToken</div>
    <div class="token">TokenToken</div>
    <div class="token">TokenTokenTokenToken</div>
    <div class="token">TokenToken</div>
    <div class="token">TokenTokenTokenToken</div>
    <div class="token">TokenToken</div>
    <div class="token">TokenTokenTokenToken</div>
    <div class="token">TokenToken</div>
    <div class="token">TokenTokenTokenToken</div>
    <div class="token">TokenToken</div>
    <div class="token">TokenTokenTokenToken</div>
    <div class="token">TokenToken</div>
    <div class="token">TokenTokenTokenToken</div>
    
    <div class="inputContainer">
      <input class="autoCompleteInput" value='inputText'/>
    </div>
    
    <div class="dropdownContainer">Dropdown Container</div>
  
  
  </div>
</div>

1 个答案:

答案 0 :(得分:0)

.autocompleteContainer是否必须浮动?如果删除该声明,那么您需要做的就是添加到dropdownContainer

.dropdownContainer{
    left: 0;
    top: 100%;
}