2017-04-27 72 views
1

我有一個位置設置爲固定的div容器。當我嘗試在div標籤內添加內容時,內容從標籤的底部開始,而不是在頂部。嵌套格造型偏移

#toolbox{ 
    width: 300px; 
    height: 400px; 
    position: fixed; 
    top: 250px; 
    background-color: grey; 
    z-index: 1; 
} 
#secondary{ 
    position: relative; 
    margin: 0px; 
    padding:0px; 
    height: 10px; 
    width:10px; 
} 

我的HTML看起來像

<div id="toolbox"> 
    <span id="secondary">Test</span> 
</div> 

文本 '測試' 來對工具箱的底部。如果我添加多個元素,如單選按鈕或另一個div標籤(並在工具箱中將溢出設置爲自動),這些元素在工具箱本身內形成一個大頁面。

添加源代碼:

<html> 
<head> 
    <title>Crisper</title> 
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
    <script type="text/javascript" src="script.js"></script> 
    <link href="styles.css" rel="stylesheet" /> 
</head> 

<body onload="start()"> 
    <header> 
     <h1>Test Util</h1> 

     <input type="file" name="file" id="file" class="inputfile" /> 
    </header> 
    <hr> 

    <div id="dropbox"> 
     <div id="toolbox"> 
      <span id="secondary">Res</span> 
     </div> 
     <img id="canvas" src="https://upload.wikimedia.org/wikipedia/commons/c/ce/Transparent.gif" > 
    </div> 

    <hr> 
    <footer> 
     <button id="download-butotn">Download</button> 
    </footer> 
</body> 

CSS:

#dropbox { 
    min-height: 70%; 
    text-align: center; 
} 

img{ 
    min-height: 500px; 
    min-width: 500px; 
    position: relative; 
    margin: auto auto auto auto; 
} 

#toolbox{ 
    width: 300px; 
    height: 400px; 
    position: fixed; 
    top: 250px; 
    background-color: grey; 
    z-index: 1; 

} 

#secondary{ 
    position: absolute; 
    height: 100px; 
} 

This is what is seen on my local machine

+0

不按照此琴:https://jsfiddle.net/32gyhd3b/ – Toby

+0

無法重現。 https://jsfiddle.net/9azmf2cq/ – Roope

+0

我認爲你的問題是其他的地方!它沒有你說的問題。刪除'top:250px'並測試結果。 –

回答

1

我正在設置線高度通過JavaScript導致偏移。只需重寫CSS文件中行高度屬性的值即可完成作業。

0

有它的多個可能原因。但是,您提供的代碼不包含任何代碼。下面是一些常見的:

  1. bottom: 0;
  2. 它擁有一套height並使得其孩子的顯示規則對準底部
    (即:display:flex;flex-direction:column;justify-content: flex-end;
  3. padding-topmargin-toptop

注1:最可能的原因是
注2:有多種其他的方法來對準孩子底部的高大父裏面。 (2.


如果沒有上面的幫助下,你必須提供一個最小的,完整的和可覈查的例子。

+1

還有更多,如'display:flex; align-items:flex-end; ','column-reverse','vertical-align'等等,所以這個列表退出很長 – LGSon

+0

奇怪的是,即使我複製粘貼我的代碼在小提琴上,它不會重現。然而在本地機器上看到 – user2326079

+0

請問爲什麼你發佈了一個有很多猜測的答案? ...你一直在這麼做,以便做到這一點 – LGSon