html <hr> 标签奇怪显示

标签 html css asp.net

为什么是<hr/>标签显示这么奇怪?如何解决?

enter image description here

家庭 Controller :

namespace MvcApplication4.Controllers
{
public class HomeController : Controller
{
    //
    // GET: /Home/

    public ActionResult Index()
    {
        List<Department> department = new List<Department>();
        department.Add(new Department { Computers = new List<Computer> { new Computer { ID = 1 }, new Computer { ID = 2 } }, Employees = new List<Employee> { new Employee { Number = 1, Text = "Jhon" }, new Employee { Number = 2, Text = "Conorrrrrrrrrrrr" }, new Employee { Number = 3, Text = "Nick" } } });
        department.Add(new Department { Computers = new List<Computer> { new Computer { ID = 1 }, new Computer { ID = 2 }, new Computer { ID = 3} }, Employees = new List<Employee> { new Employee { Number = 1, Text = "David" } } });
        return View(new IndexViewModel { Department = department });
    }
}
public class IndexViewModel
{
    public IEnumerable<Department> Department { get; set; }

}

public class Department
{
    public IEnumerable<Employee> Employees { get; set; }

    public IEnumerable<Computer> Computers { get; set; }
}

public class Computer
{
    public int ID {get;set;}
}
public class Employee
{
    public string Text { get; set; }

    public int Number { get; set; }
}
}

索引.cshtml:

@model MvcApplication4.Controllers.IndexViewModel
@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

@foreach(var department in Model.Department)
{
<table style="float:left;">
    <tbody>
        @foreach (var computer in department.Computers)
        {
            <tr>
                <td>
                    @computer.ID
                </td>
            </tr>
        }
    </tbody>
</table>

<table>
    <tbody>
        @foreach (var employee in department.Employees)
        {
            <tr>
                <td>
                    @employee.Text
                </td>
                <td>
                    @employee.Number
                </td>
            </tr>
        }
    </tbody>
</table>
<br />
<hr />
}

最佳答案

您应该清除 float 。否则,如果 hr 直接在 float 表之后,它将显示在其右侧。

<hr style="clear:left" />

或者,最好是,把

hr {clear:left;}

在你的样式表中。

关于html <hr> 标签奇怪显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36626897/

相关文章:

html - <p> 横跨报纸

asp.net - 无需进入 Visual Studio 中的任何代码即可进行调试

asp.net - ASP.net MVC Webforms View 引擎的缺点?

c# - Winforms 登录中的 ASP .NET Core 身份未进行身份验证

javascript - 如何水平定位我的元素以与CSS react

javascript - 引导模式中的按钮没有响应

javascript - 很难在我的 jQuery 中找到导致元素消失的问题

javascript - 在 Javascript 中解析 html 以进行 Canvas 渲染

javascript - 过渡问题 CSS 和 JS

html - Bootstrap navbar-toggleable-sm 不工作