簡體   English   中英

使用負邊距將div1粘附到div2的左側

[英]Using negative margin to adhere div1 to the left of div2

我想在側邊欄中點擊聯系人左側的解雇按鈕,如下圖所示: https//i.imgur.com/oj2Qi2t.png

但使用margin-left: -50px; left: -50px; dismiss div消失了! 它的位置是正確的檢查元素,但我不知道如何正常顯示它,這應該是一個紫色的方塊。

完整的演示是: https//codepen.io/anon/pen/YbpZaV

HTML

<nav class="sidebar">
  <div class="dismiss">dismiss</div>
  <div class="contacts">
</nav>

CSS

.sidebar {
  width: 250px;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  overflow-y: auto;
  transition: all 0.3s;
  z-index: 40;
}

.dismiss {
  width: 50px;
  height: 50px;
  background-color: #7386d5;
  position: absolute;
  top: 50%;
  margin-left: -50px;
  cursor: pointer;
  transition: all 0.3s;
  z-index: 40;
}

你應該刪除overflow-y: auto : -

    .sidebar {
    width: 250px;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;      
    transition: all 0.3s;
    z-index: 40;
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM