简体   繁体   English

asp.net母版页css不适用于asp表单页面

[英]asp.net master page css not applying to asp form pages

I am new to asp.net programming and have come into this unusual error.我是 asp.net 编程的新手,遇到了这个不寻常的错误。 I have a master page called Master.Master which contains the following code for specifying a CSS file.我有一个名为Master.Master的母版页,其中包含以下用于指定 CSS 文件的代码。

<head runat="server">
    <title></title>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>

    <asp:ContentPlaceHolder ID="Stylesheets" runat="server">
        <link rel="stylesheet" href="~/Styles/StyleSheet.css" type="text/css" />
    </asp:ContentPlaceHolder>
</head>

note that for the master page the CSS works perfectly with no issues, I have since created a default asp web form which takes all contents from the Master.Master page.请注意,对于母版页,CSS 可以完美运行,没有任何问题,此后我创建了一个默认的 asp Web 表单,该表单从 Master.Master 页面中获取所有内容。 This page however is not displaying the CSS at all, here is that pages code.然而,这个页面根本不显示 CSS,这是页面代码。

<%@ Page Title="Home" Language="C#" MasterPageFile="~/Master.Master" AutoEventWireup="true" CodeBehind="Home.aspx.cs" Inherits="GarageManager.WebForm1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="stylesheets" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
</asp:Content>

from researching this issue many users on here even suggested using script language for resolving URL like such, but to no avail.通过研究这个问题,这里的许多用户甚至建议使用脚本语言来解析这样的 URL,但无济于事。

<a runat="server" href="<%= this.ResolveUrl(~/Styles/StyleSheet.css) %>" onmouseover="document.Home_Img.src='<%= this.ResolveUrl("Images/home_2.png") %>'"
        onmouseout="document.Home_Img.src='<%= this.ResolveUrl("Images/home.png") %>'">
        <img alt="" src="Images/home.png" name="Home_Img" runat="server" />
    </a>

thanks in advance提前致谢

Just get rid of the head and stylesheets ContentPlaceHolders and do this in your Master.Master file:只需去掉头部和样式表 ContentPlaceHolders 并在您的 Master.Master 文件中执行此操作:

<head>
    <link rel="stylesheet" href="~/Styles/StyleSheet.css" type="text/css" />
</head>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM