简体   繁体   English

在 razor 中添加不带 br 的元素

[英]Adding elements without br in razor

I want to know how can I add elements to page without breaking line我想知道如何在不换行的情况下向页面添加元素

Now I have a piece of code:现在我有一段代码:

@foreach (var item in Model.TagModels)
    { 

        <div class="editor-field">
            @Html.EditorFor(model => item.Name)
            @Html.ValidationMessageFor(model => item.Name)
        </div>

    }

which adds me inputs to page, but with breaking line.这将我的输入添加到页面,但带有断线。

I want to have it in one row.我想把它排成一排。 Could be done?能做到吗?

Try this:尝试这个:

@foreach (var item in Model.TagModels)
{ 

    <div class="editor-field" style="float: left">
        @Html.EditorFor(model => item.Name)
        @Html.ValidationMessageFor(model => item.Name)
    </div>

}

The float property in CSS is used for alignment. CSS 中的 float 属性用于 alignment。 This would place all the divs in one line.这会将所有 div 放在一行中。 Each DIV is added to the right of the previous DIV每个 DIV 都添加到前一个 DIV 的右侧

It's the div container that your inputs are in that are causing them to appear below each other.正是您的输入所在的div容器导致它们出现在彼此下方。 Just remove the div or replace it with a span or display:inline只需删除div或将其替换为spandisplay:inline

The validationmessage is probably a div.验证消息可能是一个 div。 Try changing the CSS to display:inline尝试将 CSS 更改为 display:inline

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM