CSS显示文本框

时间:2013-03-17 21:29:27

标签: css asp.net-mvc twitter-bootstrap

感谢James Donnelly,这已经解决了。我的示例已更新为工作解决方案。

我的声誉不够高,所以我无法发布图片,因此我将尝试尽可能最好地描述它。我在表单上有7个文本框和一个textarea,当我加载页面时,它当前在一个单独的行上加载每个文本框。

但是,我希望文本框像这样加载:
1 2 3
4 5 6 7
--- 8 ---(跨越)

我应该将每行放在div中吗?我尝试将每个文本框浮动到左侧,但这不能正常工作。我的项目中有Twitter引导设置,如果这样可以让事情变得更容易。

这是我的工作代码:

<div class="well">
<h4>Enter Movie in System:</h4>

@using (Html.BeginForm()) {
    <div>
        <div class="input-prepend">
            <span class="add-on"><i class="icon-film"></i></span>
            @Html.TextBoxFor(m => m.Title, new { placeholder = "Title" })
            @Html.ValidationMessageFor(m => m.Title)
        </div>

        <div class="input-prepend">
            <span class="add-on"><i class="icon-facetime-video"></i></span>
            @Html.TextBoxFor(m => m.Director, new { placeholder = "Director" })
            @Html.ValidationMessageFor(m => m.Director)
        </div>

        @* Make dropdown *@
        <div class="input-prepend">
            <span class="add-on"><i class="icon-tags"></i></span>
            @Html.TextBoxFor(m => m.parentGenre, new { placeholder = "Genre" })
            @Html.ValidationMessageFor(m => m.parentGenre)
        </div>  


        <div class="input-prepend">
            <span class="add-on"><i class="icon-star-empty"></i></span>
            @Html.TextBoxFor(m => m.Stars, new { placeholder = "Actor" })
            @Html.ValidationMessageFor(m => m.Stars)
        </div>



        <div class="input-prepend">
            <span class="add-on"><i class="icon-time"></i></span>
            @Html.TextBoxFor(m => m.Duration, new { placeholder = "Duration (mins)" })
            @Html.ValidationMessageFor(m => m.Duration)
        </div>


    @* Make dropdown *@

        <div class="input-prepend">
            <span class="add-on"><i class="icon-warning-sign"></i></span>
            @Html.TextBoxFor(m => m.Rating, new { placeholder = "Rating" })
            @Html.ValidationMessageFor(m => m.Rating)
        </div>



        <div class="input-prepend">
            <span class="add-on"><i class="icon-calendar"></i></span>
            @Html.TextBoxFor(m => m.releaseDate, new { placeholder = "Release Date" })
            @Html.ValidationMessageFor(m => m.releaseDate)
        </div>


    <div class="control-group">
        <div class="input-prepend">
            <span class="add-on"><i class="icon-comment"></i></span>
            @Html.TextAreaFor(m => m.Description, new { placeholder = "Description", @class="input-xxlarge" })
            @Html.ValidationMessageFor(m => m.Description)
        </div>
    </div>



        <p>
            <button class="btn" type="submit" value="Register">Register</button>
        </p>
        @Html.ValidationSummary()
    </div>
}

3 个答案:

答案 0 :(得分:1)

默认情况下,

.content-group设置为display:table;,这会将您的每个输入强制转换为新行。您只需将每个.input-prepend容器放入一个容器中:

    <div>
        <div class="input-prepend">
            <span class="add-on"><i class="icon-tags"></i></span>
            @Html.TextBoxFor(m => m.parentGenre, new { placeholder = "Genre" })
            @Html.ValidationMessageFor(m => m.parentGenre)
        </div>  

        <div class="input-prepend">
            <span class="add-on"><i class="icon-tags"></i></span>
            @Html.TextBoxFor(m => m.parentGenre, new { placeholder = "Genre" })
            @Html.ValidationMessageFor(m => m.parentGenre)
        </div> 

        <div class="input-prepend">
            <span class="add-on"><i class="icon-tags"></i></span>
            @Html.TextBoxFor(m => m.parentGenre, new { placeholder = "Genre" })
            @Html.ValidationMessageFor(m => m.parentGenre)
        </div> 
    </div>

答案 1 :(得分:0)

这是你的意思吗?

<div>
   <input id="tbx1" />
   <input id="tbx2" />
   <input id="tbx3" /><br />   
   <input id="tbx4" />
   <input id="tbx5" />
   <input id="tbx6" />
   <input id="tbx7" />
   <span id="span1" style="padding-left:200px">
      <input id="tbx8" />
   </span>
</div>

答案 2 :(得分:0)

你必须发布你尝试过的css样式。但我猜测给窗体一个左边的浮动,宽度和高度应该让你能够浮动输入字段,确保前六个输入都没有大于窗体宽度的30%。为最后一个宽度100%