当我将元素从 _Layout.cshtml 文件移动到 ASP.NET Core MVC 项目中的 Index.cshtml 文件时,它破坏了 CSS 样式。但是当我将元素移回具有完整 html 结构的 Layout.cshtml 时,工作正常。 所有的样式都在 Bootstrap 中。
提前致谢
如果 ASP.NET Core MVC 项目主要使用 Bootstrap 类进行样式设置,则将元素从 _Layout.cshtml 文件移动到 Index.cshtml 文件通常不会导致 CSS 样式问题,因为 Bootstrap 类被设计为响应式的,并且应该适应 HTML 结构的变化。
我找到了解决方案 xD 问题出在这里:
<div class="container-fluid">
<main role="main" class="pb-3">
@RenderBody()
</main>
</div>
新版本:
<div>
<main>
@RenderBody()
</main>
</div>