CSS新手:在我的例子中如何设置元素位置?
我有CSS新手:在我的例子中如何设置元素位置?,css,Css,我有 我有 <input type='text', id='name'></input> 我的名字是xyz 我希望元素位于20px的右侧,如何使用CSS实现此目的?我的名字是xyz <p>my name is xyz</p> 您可以浮动元素以实现此目的: <label><input type='text', id='name'><span style="padding-left:20px;">my na
我有
<input type='text', id='name'></input>
我的名字是xyz
我希望
元素位于20px的右侧
,如何使用CSS实现此目的?我的名字是xyz
<p>my name is xyz</p>
您可以浮动元素以实现此目的:
<label><input type='text', id='name'><span style="padding-left:20px;">my name is xyz</span></label>
我意识到这比简单地添加CSS样式声明要多一些工作,但是我可以建议您使用稍微多一些语义标记来设置表单的样式吗?大致如下:
input { float: left; }
p {
float: left;
margin-left: 20px;
}
。
建议阅读:
<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>
input {
margin-right: 20px;
}
/* or */
label {
margin-left: 20px;
}