2011-05-08 79 views
4

我有以下几点:我怎样才能让我的DIV下方出现相互

<div style="float: left; padding-right: 1%;"> 
    <label class="editor-label" for="BrowserTitle">Browser Title</label> 
    <input class="editor-field" id="BrowserTitle" name="Question.BrowserTitle" size="30" type="text" value="Test title" /> 
</div> 

我想使输入字段出现在标签下面。现在它只是在同一行上的标签之后。有没有办法,我可以用CSS来做到这一点?

+1

使用'显示:block'上''

回答

5

要么标签或输入上设置

display: block; 

注:正如评论指出的那样,你也会需要如果你想的div出现低于对方从包含分区删除float风格。一个div里面

+0

不要忘记删除DIV上的'float'。否则,这将不起作用 – JohnP 2011-05-08 05:19:44

+0

即使包含div浮动,“display:block”也会使输入显示在标签下方。不过,保持“浮动”会让多个标签/输入对并排出现。 – 2011-05-08 05:26:34

+0

这就是问题所在。标题要求DIV也低于对方。不是并排的。 – JohnP 2011-05-08 05:33:50

2

您可以将labelinput放在它们自己的div中,或在CSS中分别设置为display: block

1

放标签:

<div style="float: left; padding-right: 1%;"> 
<div> 
    <label class="editor-label" for="BrowserTitle">Browser Title</label> 
<div> 
<input class="editor-field" id="BrowserTitle" name="Question.BrowserTitle" size="30" type="text" value="Test title" /> 


看到成绩:http://jsfiddle.net/uUEn8/ 您还可以设置两种标签或者输入上display:block

+0

我想你可能已经发布了错误的小提琴 – JohnP 2011-05-08 05:21:03

+0

是!对不起,更新... – Kamyar 2011-05-08 05:22:31

2

为什么不移除DIV上的浮点并使LABEL成为块?

<div style=" padding-right: 1%;"> 
    <label class="editor-label" style='display:block;' for="BrowserTitle">Browser Title</label> 
    <input class="editor-field" id="BrowserTitle" name="Question.BrowserTitle" size="30" type="text" value="Test title" /> 
</div> 

演示:http://jsfiddle.net/h7mnJ/

0

由于所有的CSS的解决方案已经用尽,这里是一个与<br />元素的HTML解决方案:

<div style="float: left; padding-right: 1%;"> 
    <label class="editor-label" for="BrowserTitle">Browser Title</label> 
    <br /> 
    <input class="editor-field" id="BrowserTitle" name="Question.BrowserTitle" size="30" type="text" value="Test title" /> 
</div>