2011-04-06 37 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

推荐阅读:

相关问题