gpt4 book ai didi

css - 下载布局模板的布局页面无法正确呈现

转载 作者:行者123 更新时间:2023-11-28 08:18:15 26 4
gpt4 key购买 nike

我创建了一个新的 ASP .Net MVC 5 元素,其中包含所有示例 View 、 Controller 等。它具有最新版本的 jQuery 和 Bootstrap。

所以我想要一个漂亮的模板,所以我下载了 this one我将图像和 css 文件添加到内容文件夹,修改了 BundleConfig 类,以便包含新的 css 文件,还更改了 _ViewStart.cshtml 文件,以便它采用我命名为 _myLayout.cshtml 的新布局。

从技术上讲,它工作得很好,因为所有页面现在都使用新的布局模板,但它没有正确呈现,菜单看起来被截断了,标题图像和内容部分超出了右侧的边框,并且页脚在底部显示了不应该存在的边距。

我已经能够将问题确定为模板的 css 和 bootstrap 之间的“冲突”,因为如果我从 BundleConfig 文件中删除 bootstrap 样式表,然后样式会按预期呈现。

我更像是一名后端/javascript 开发人员,所以我对 css 的了解非常有限,而且我对这个一头雾水。太多了,我什至不知道要包含哪些代码,而且两个 css 文件都太大而无法将它们包含在问题中。

如果有人能够提供帮助,我将不胜感激和/或如果有人可以提供一些线索,说明哪些 CSS 部分可以包含在帖子中以帮助查明问题,请告诉我。

提前致谢。

更新:

要重现该问题,您必须:
- 下载 the template I mentioned above
- 创建一个新的 ASP .Net MVC 5 元素
- 在元素的内容文件夹中添加模板中的图像和 styles.css 文件
- 在元素的共享文件夹中创建一个名为 _myLayout.cshtml 的新布局页面
- 对这些文件进行以下更改:

BundleConfig.cs

using System.Web;
using System.Web.Optimization;

namespace SC.Web
{
public class BundleConfig
{
// For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));

bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.validate*"));

// Use the development version of Modernizr to develop with and learn from. Then, when you're
// ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
"~/Scripts/modernizr-*"));

bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
"~/Scripts/bootstrap.js",
"~/Scripts/respond.js"));

bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/site.css",
"~/Content/styles.css"));
}
}
}

_ViewStart.cshtml

@{
Layout = "~/Views/Shared/_myLayout.cshtml";
}

_myLayout.cshtml

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewBag.Title - My ASP.NET Application</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
</head>
<body>
<div id="main">
<!-- start header -->
<div id="header">
<div id="logo">
<h1><a href="#">metamorph_highway</a></h1>
<h2><a href="http://www.metamorphozis.com/" id="metamorph">Design by Metamorphosis Design</a></h2>
</div>
<div id="menu">
<ul>
<li>@Html.ActionLink("Home", "Index", "Home")</li>
<li>@Html.ActionLink("About", "About", "Home")</li>
<li>@Html.ActionLink("Contact", "Contact", "Home")</li>
</ul>
</div>
<!-- end header -->
</div>
<hr />
<!-- start page -->
<div id="page">
<!-- start content -->
<div id="content">
@RenderBody()
</div>
<!-- end content -->
<div style="clear: both;">&nbsp;</div>
</div>
<!-- end page -->
<hr />
<!-- start footer -->
<div id="footer">
<p>&copy; @DateTime.Now.Year - My ASP.NET Application</p>
<p>Copyright &copy; 2008. <a href="#">Privacy Policy</a> | <a href="#">Terms of Use</a> | <a href="http://validator.w3.org/check/referer" title="This page validates as XHTML 1.0 Transitional"><abbr title="eXtensible HyperText Markup Language">XHTML</abbr></a> | <a href="http://jigsaw.w3.org/css-validator/check/referer" title="This page validates as CSS"><abbr title="Cascading Style Sheets">CSS</abbr></a></p>
<p>
Design by <a href="http://www.metamorphozis.com/" title="Free Site Templates">Free Site Templates</a>, coded by <a href="http://www.flashtemplatesdesign.com" title="Free Flash Templates">Free Flash Templates</a>
</p>
</div>
</div>
<!-- end footer -->
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)
</body>
</html>

最佳答案

原来在 Bootstrap 上有这个定义:

* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}

因为我下载的模板搞砸了,所以我在它自己的 css 文件中添加了以下内容:

*{
-webkit-box-sizing: content-box;
-moz-box-sizing: content-box;
box-sizing: content-box;
}

我不知道以后这是否会导致 bootstrap 无法正常运行,如果发生这种情况,我将不得不处理它。

关于css - 下载布局模板的布局页面无法正确呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28883455/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com