HTML 将元素放在同一行

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

我有以下用于在 Asp.NET MVC 中上传文件(使用一些 Bootstrap css)的表单。现在,“清除”按钮位于输入字段下方;如何使其位于输入字段的右侧?

我考虑过使用 <table>一列用于输入字段,一列用于按钮,但它似乎不合适,当我尝试时,Visual Studio 给了我波浪线。

@using (Html.BeginForm("Index", "Uploader", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    <div class="form-group">
        <input type="file" name="files" id="file1" />
        <button onclick="reset2($('#file1'));event.preventDefault()">Clear</button>
        <span class="field-validation-error" id="err1"></span>
        @Html.ValidationMessage("1")
    </div>

    <div class="form-group">
        <input type="file" name="files" id="file2" />
        <button onclick="reset2($('#file2'));event.preventDefault()">Clear</button>
        <span class="field-validation-error" id="err2"></span>
        @Html.ValidationMessage("2")
    </div>
... more file input fields
}

最佳答案

输入上的一个简单的 style="display:inline" 将按如下方式工作;

   <div class="form-group">
     <input type="file" name="files" id="file1" style="display:inline" />
        <button onclick="reset2($('#file1'));event.preventDefault()">Clear</button>
        <span class="field-validation-error" id="err1"></span>

    </div>

    <div class="form-group">
        <input type="file" name="files" id="file2" style="display:inline" />
        <button onclick="reset2($('#file2'));event.preventDefault()">Clear</button>
        <span class="field-validation-error" id="err2"></span>

    </div>

我敢肯定,有些人会比我的答案更好,但更具体的 Bootstrap 。

Fiddle

屏幕抓取

enter image description here

关于HTML 将元素放在同一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28083735/

相关文章:

javascript - 检查横幅是否加载

javascript - 影响 ("bleeding"的外部 CSS 成)shadow DOM with Polymer

html - 我的 Bootstrap 模式显示正常,但背景不会褪色

html - bootstrap 3 中的 Contant 缩进

javascript - encodeURIComponent,ü,ç,İ,ı,ğ,ö 有问题

html - 读取 <mat-option> angular 的值

javascript - 使用 PhoneGap 在 iOS 上录音

javascript - 这种造型从何而来?

asp.net - GridView 中 (ASP.NET) ButtonField 的 JQuery 选择器

asp.net - 如何隐藏 ASP.NET ChangePassword 控件上的取消按钮