2016-08-05 19 views
0

我在下拉列表中選擇了這些數據(選擇框) 我選擇的值數據更改應該顯示爲兩行。在同一個下拉列表中。如何使用JS或CSS數據基礎在下拉菜單中顯示兩行數據(選擇框)

<select id="q1"> 
    <option value="">Select</option> 
    <option value="1">In what city did you meet your spouse/significant other?</option> 
    <option value="2">In what city or town did your mother and father meet?</option> 
    <option value="3">In what city or town was your first job?</option> 
    <option value="4">What is the middle name of your oldest child?</option> 
    <option value="5">What is your maternal grandmothers maiden name?</option> 
    <option value="6">What is your oldest cousins first and last name?</option> 
    <option value="7">What school did you attend for sixth grade?</option> 
</select> 

價值變動應該在二線顯示,如果以適應單行中無法數據。 否則它應該出現在單行中。 我使用這個CSS: -

select { 
    border-left: 0 none; 
    border-right: 0 none; 
    border-top: 0 none; 
    min-height: 30px; 
    padding-left: 5px; 
    padding-right: 5px; 
    text-align: left; 
    max-width: 500px; 
} 
+0

請重新表述它應該做的事'上change',因爲它沒有任何意義。 – Rvervuurt

+0

關於我選擇的價值數據的變化應該在兩行中顯示。在同一個下拉列表中。 –

+0

請勿使用最大寬度。 – James

回答

0

添加以下代碼,選擇CSS會顯示多行的內容。

word-break: break-word; 
white-space: normal; 

select { 
 
    border-left: 0 none; 
 
    border-right: 0 none; 
 
    border-top: 0 none; 
 
    min-height: 30px; 
 
    padding-left: 5px; 
 
    padding-right: 5px; 
 
    text-align: left; 
 
    max-width: 300px; 
 
    word-break: break-word; 
 
    white-space: normal; 
 
}
<select id="q1"> 
 
    <option value="">Select</option> 
 
    <option value="1">In what city did you meet your spouse/significant other?</option> 
 
    <option value="2">In what city or town did your mother and father meet?</option> 
 
    <option value="3">In what city or town was your first job?</option> 
 
    <option value="4">What is the middle name of your oldest child?</option> 
 
    <option value="5">What is your maternal grandmothers maiden name?</option> 
 
    <option value="6">What is your oldest cousins first and last name?</option> 
 
    <option value="7">What school did you attend for sixth grade?</option> 
 
</select>

0

請參考以下鏈接。

http://jsfiddle.net/243p5fzd/6/

select { 
    border-left: 0 none; 
    border-right: 0 none; 
    border-top: 0 none; 
    min-height: 30px; 
    padding-left: 5px; 
    padding-right: 5px; 
    text-align: left; 
    max-width: 200px; 
    word-break: break-word; 
    overflow-wrap: break-word; /*Mozilla */ 
    white-space: pre-wrap; /* css-3 */ 
    white-space: -moz-pre-wrap; /* Mozilla, since 1999 */ 
    white-space: -pre-wrap; /* Opera 4-6 */ 
    white-space: -o-pre-wrap; /* Opera 7 */ 
    word-wrap: break-word; 

}

相關問題