2012-03-18 45 views
2

我想在選擇框前添加一個標籤,我已經將包含兩個元素的div標籤設置爲「內嵌塊」。但是,跨度仍然在選擇框的頂部。在下拉列表前添加一個文本標籤

<div class="unselected-field" style="display: inline-block;" id="selectCountry"> 
    <span>test</span><select id="countrySelect" name="countrySelect"></select> 
</div> 

任何想法?我在Chrome ...

+0

難道是我的父母的HTML元素有一些類型的重寫我的默認樣式的CSS? – thinkanotherone 2012-03-18 21:39:49

+0

你有活的網站看嗎?會很方便地看到所有的代碼。 – SmithMart 2012-03-18 21:44:50

回答

2

如果<select>的寬度加上<span>的寬度比所述含<div>越大,<select>將被迫去而不是被它旁邊的<span>下方。另外,<select>的寬度依賴於它包含的文本,所以它可以有不同的寬度,除非您給它一個靜態寬度。

4

我通常纏繞在輸入標籤:

<div class="unselected-field" style="display: inline-block;" id="selectCountry"> 
    <label>Test:<select id="countrySelect" name="countrySelect"> 
     <option>Option 1</option> 
     </select> 
    </label> 
</div>​ 
+0

不錯的提示。謝謝 :) – thinkanotherone 2012-03-18 21:49:40

5

一個選項將只是disable第一個選擇的選項:

<select id="countrySelect" name="countrySelect"> 
    <option disabled selected>Select Your Country:</option> 
    <option>USA</option> 
    <option>Germany</option> 
    <option>France</option> 
</select> 
相關問題