2017-10-18 74 views
2

我想要的方式,在上邊距是基於div的高度設置響應格式化HTML DIV:jsfiddle更改邊距響應

有包裝內的另一個div有一個display: none設置爲它,但它可能會更改時,用戶輸入一個錯誤的密碼。事情是,下面有一個div,當display: content設置爲第二個div時,它被推下。我希望頁面的內容能夠響應地向上而不是向下。

如何現在: enter image description here

應該如何: enter image description here

+0

你可以使你當前什麼gettings VS你想要的東西快速漆圖紙? – ProEvilz

+0

當然,看看編輯。事情是,我希望當頁面內容足夠大時可以對頁邊進行響應。 –

+0

您所描述的內容聽起來像是試圖將事物垂直放置在視圖中,而不是隨着顯示更多內容而使事物向下移動。是這樣嗎?如果是這樣,只需使用帶有居中內容的flexbox容器並忘記頂部邊距。 –

回答

1

鑑於你的榜樣,你的目標和你的喜好,以避免Flexbox的由於IE10,我覺得你最好的選擇是使用display:table爲這個容器。

使用此功能,您可以在「表格單元格」中使用vertical-align屬性。

檢查下面的例子。爲了演示目的,我添加了一個切換按鈕來顯示/隱藏您的驗證碼。 可能想要全屏查看以獲得效果。

$("#toggle").on('click', function() { 
 
    $(".captcha").toggle(); 
 
});
html,body { 
 
    height: 100%; 
 
} 
 
.outer-wrapper { 
 
    height: 100%; 
 
    width: 100%; 
 
    background: #eeeeee; 
 
    display: table; 
 
} 
 

 
.inner-wrapper { 
 
    height: 100%; 
 
    width: 100%; 
 
    display: table-cell; 
 
    vertical-align: middle; 
 
    height: inherit; 
 
} 
 

 
.login-wrapper { 
 
    background-color: #172238; 
 
    color: white; 
 
    width: 200px; 
 
    text-align: center; 
 
    height: auto; 
 
    display: block; 
 
    margin: 0 auto; 
 
} 
 

 
.captcha{ 
 
    margin-top: 250px; 
 
    display: content; // This one changes 
 
} 
 

 
.homologation-line { 
 
    min-width: 200px; 
 
    background-color: #ffd800; 
 
    color: black; 
 
    text-align: center; 
 
    height: 30px; 
 
} 
 

 
#toggle { 
 
position: absolute; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<button id="toggle">toggle captcha</button> 
 
<div class="outer-wrapper"> 
 
    <div class="inner-wrapper"> 
 
     <div class="login-wrapper"> 
 
     <p>Login</p> 
 
     <div class="captcha"> 
 
      ENTER THE DIGITS: 
 
     </div> 
 
    </div> 
 
    <div class="homologation-line"> 
 
     HOMOLOGATION 
 
    </div> 
 
    </div> 
 
</div>

+0

你能改變這樣的另一個元素的確切邊距嗎? –

+0

我不確定你在問什麼。像這樣的解決方案的重點在於將內容集中在一個區域中,以便用戶始終可以看到它,無論大小如何,因此您不必依賴諸如邊距和斷點等內容。因爲採取這種方法時,你依靠的是假設。 –