ASP.NET Web 表单:母版页和主页CSS文件

发布于 2024-12-05 03:00:29 字数 1431 浏览 1 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

飘然心甜 2024-12-12 03:00:29
  1. 强烈建议使用母版页。它使您能够在所有页面上保持一致的外观。另外,如果您决定更改布局,则只需更改一个文件!

  2. 只需在母版页中引用 CSS 文件,它将应用于使用母版页的每个页面。类似于

应该注意的是,您也可以有多个母版页。 Visual Studio 还允许您创建页面并选择母版页,这是添加项目时的其他选项之一。

  1. I would highly recommend using a master page. It gives you the ability to have one consistent look across all your pages. Also if you decide to change the layout your only changing one file!

  2. Simply reference the CSS file in your master page and it will be applied to every page the master page is used on. Something like <link href="~/styles/Style.css" rel="stylesheet" type="text/css" />

It should be noted that you can also have more then one master page. Visual studio also allows you to create pages and select the master page, it's one of the other options when adding an item.

ゞ记忆︶ㄣ 2024-12-12 03:00:29

如果您的许多或所有页面共享一个通用的用户界面(例如页眉、页脚、导航栏等),您应该拥有一个母版页。

将 CSS 文件的链接放在哪里并不重要,因为无论哪种方式 CSS 都会应用到整个页面。如果 CSS 对于整个网站(或共享同一母版页的所有网站)是通用的,请将其放在母版页中。如果 CSS 文件是特定于页面的,并且您不能将其放入母版页中,因为它与其他特定于页面的冲突,请将其放入页面中(在 ContentSection 的头部)。

You should have a master page if many or all of your pages share a common User Interface (such as a header, footer, navigation bar, etc).

It really doesn't matter where you put the link to the CSS file, because the CSS will be applied to the whole page either way. If the CSS is common to the entire website (or all the ones that share the same master page) put it in the Master Page. If the CSS file is page specific and you can't put it in the Master page because it conflicts with another page specific, put it in the page (in the head ContentSection).

怪我入戏太深 2024-12-12 03:00:29

我建议使用母版页来控制网站的总体布局,这样您就不必在每个页面上重复布局。您不需要在 CSS 文件中执行任何特殊操作来说明母版页,但您应该在母版页的标题中添加指向 CSS 文件的链接,以便它可以传递到使用母版页的所有页面页。

母版页标题:

<head runat="server">    
    <link rel="Stylesheet" href="~/pathtocssfile/cssfilename.css" type="text/css" />
</head>

I would suggest using master pages to control the general layout of your site, so you don't have to repeat the layout on every page. You don't need to do anything special in the CSS file to account for the master page, but you should add the link to the CSS file in the header of the master page, so it carries through to all of the pages using the master page.

Master page header:

<head runat="server">    
    <link rel="Stylesheet" href="~/pathtocssfile/cssfilename.css" type="text/css" />
</head>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文