2011-04-06 33 views

回答

0
<label><input type='text', id='name'><span style="padding-left:20px;">my name is xyz</span></label> 
+0

出於某種原因,我想用外部CSS文件接近的結果,因爲內容是動態創建的,而不是內聯樣式。但是謝謝你! – Mellon 2011-04-06 13:14:54

+0

@Mellon:只是一個提示,絕不使用內聯樣式 – Christophe 2011-04-06 13:17:18

+0

內聯樣式僅作爲示例。 – 2011-04-06 13:51:50

0

您可以浮動的元素來實現這一點:

input { float: left; } 
p { 
    float: left; 
    margin-left: 20px; 
} 
1

我意識到,這是比簡單地增加一個CSS樣式聲明更多一點的工作,但我可以建議你使用slightly-更多的語義標記來設計你的表單?沿着線的東西:

<form action="path/to/script.php" method="post"> 
    <fieldset> <!-- to associate related inputs --> 
     <legend>Name</legend> <!-- a broad description of this group of inputs --> 
     <input name="name" id="name" type="text" /> <!-- input elements are usually self-closing --> 
     <label for="name">My name is</label> <!-- the for attribute takes the id of the associated input, and allows a click on the label to focus the input --> 
    </fieldset> 
</form> 

然後,在CSS,如果你想label要20像素的input的權利,所有你需要做的是:

input { 
    margin-right: 20px; 
} 

/* or */ 

label { 
    margin-left: 20px; 
} 

JS Fiddle demo of margin-rightJS Fiddle demo of margin-left

推薦閱讀:

相關問題