将 CSS 应用到 Asp.NET 中的内容页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1117256/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 20:47:06  来源:igfitidea点击:

Apply CSS to Content Page in Asp.NET

asp.netcss

提问by Tarik

Normally when we are using Master/Content style pages, we apply the css to Master page so every page child of the master page can use the style but I don't want this,I want I wanna apply css to content page directly instead of master page. Where should I put

通常当我们使用母版/内容样式页面时,我们将 css 应用到母版页,这样母版页的每个子页面都可以使用该样式,但我不想要这个,我想直接将 css 应用于内容页面而不是母版页。我应该放在哪里

<link rel="stylesheet" href="css/lightbox.css" type="text/css" media="screen" />

that reference code ?

那个参考代码?

Thanks in advance by the way.

顺便提前致谢。

回答by Steve Temple

Normally I put a content placeholder in the head section of the master page. That way any content page can add extra css/js/etc references to the head of the page.

通常我会在母版页的头部放置一个内容占位符。这样,任何内容页面都可以向页面的头部添加额外的 css/js/etc 引用。

In your master page put the following

在您的母版页中放置以下内容

<head>
  ... title, meta tags, js and css links ...
  <asp:contentPlaceholder id="head" runat="server" />
</head>

Then in your pages you can include extra elements in the head using this

然后在你的页面中,你可以使用这个在头部包含额外的元素

<asp:content contentplaceholderid="head" runat="server">
 <link rel="stylesheet" href="css/lightbox.css" type="text/css" media="screen" />
</asp:content>

回答by Spencer Ruport

Put a content placeholder in the head portion of your master page. Not all content pages will need to place anything in it but this particular content page can place the CSS file you want to link.

在母版页的头部放置一个内容占位符。并非所有内容页面都需要在其中放置任何内容,但此特定内容页面可以放置您要链接的 CSS 文件。

回答by Guffa

You can't apply a style sheet to a content page only, it applies to the whole web page.

您不能将样式表仅应用于内容页面,它适用于整个网页。