2015-02-10 58 views
0

我有以下HTML:HTML DIV並選擇間距

<div class="blueBackground" style="height:350px; width:550px"> 

    <div class="txtSmallGrey fl" style="height:20px; margin:15px; clear:left;"> 
     <div style="width:150px"><%= oUtils.GetContentText("Collect_Config_Expense_return") %> </div> 
    </div> 

    <div class="txtSmallGrey fl" style="height:20px; margin:15px; clear:left;"> 
     <div style="width:150px; float:left"><%= oUtils.GetContentText("Collect_Config_Wrong_Garment_Sounds") %> </div><select id="WrongGarmentSelector" class="fl" style="float:right; width:150px;"></select> 
    </div> 

    <div class="txtSmallGrey fl" style="height:20px; margin:15px; clear:left;"> 
     <div style="width:150px; float:left"><%= oUtils.GetContentText("Collect_Config_Out_Of_Credit_Sounds") %> </div><select id="OutOFCreditSelector" class="fl" style="float:right; width:150px;"></select> 
    </div> 

    </div> 

我的目標是創建一個藍色的盒子,然後一些行。上述HTML中的第二行和第三行旨在在文本的右側有文本和「選擇」。

我已經實現了這一點,它們按預期顯示。我的問題是我現在想減少藍色背景的寬度,所以它會在選擇器的左側留下一個小間隙,然後結束。

從我所看到的:

  • 藍色背景的寬度爲550像素;
  • 文本div的寬度爲150像素。
  • 選擇器的寬度爲150像素。
  • 內部div有15px的餘量。
  • bluebackground div沒有餘量。
  • 選擇器沒有餘量。

這將使div和選擇爲總寬度:

150 + 150 + 30 = 330像素

然而,如果我使bluebackground寬度500像素或更小,它將選擇器移動到div下面。

這讓我覺得我沒有正確計算出邊距。我曾嘗試使用DOM瀏覽器進行檢查,但無法查看邊距。

我錯過了什麼?

+0

你不明白的背景是如何工作的。而你在尋找的是背景位置,但我不知道這是否足夠。你可以張貼一些代碼來工作嗎? – Slime 2015-02-10 16:38:53

回答

0

如果我正確理解你,你有3個div有每個邊緣。

所以正確的計算是:150 + 30 +150 + 30 + 150 + 30 = 450 + 90 = 540 px?

告訴我,如果你不瞭解calcul。

編輯:當你有保證金:15px的,你有保證金左:15px的和保證金左:15px的