将样式应用于母版页中的嵌套页面 [英] Applying style to nested pages in a master page

查看:94
本文介绍了将样式应用于母版页中的嵌套页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我无法在使用母版页的嵌套页面上应用样式?我只是想在单个页面中将简单的某些底色应用于正文和某些div.

Why could I be unable to apply style on a nested page which is using a master page? I am just trying to apply simple some back-color to body and some div in an individual page.

我的(嵌套)页面Reservations.aspx具有此代码

My (nested)page Reservations.aspx has this code

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" 
AutoEventWireup="true" CodeFile="Reservations.aspx.cs" Inherits="Reservations" %>
<asp:Content runat="server" ContentPlaceHolderID="HeadContent">
    <link href="~/Styles/input.css" rel="stylesheet" type="text/css" />
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<div class="mainDiv">
........
</div></asp:Content>

input.cs具有此代码

body { background-color:Silver; }
.mainDiv { background-color:Blue; }

Site.Master具有此代码

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

仅当将其应用于不需要的母版页时,我才能将Silver Color用作Reservations.aspx的背景.我无法从此问题的可接受答案中得到帮助. a>和教程.

I can get Silver Color as background of Reservations.aspx only if I apply this to master page which I do not want. I have not been able to get helped from accepted answer of This question and tutorials.

之前或之后使用<link..可能会有所不同,感谢您提供信息,但是在这种情况下它没有做任何事情.解决问题后,我已经进行了两种方式的测试.

using <link.. before or after might make some difference, thanks for info but it is not doing anything in this case. I have tested it both ways after my problem was solved.

指导ResolveUrl解决了我的问题,因为我尝试在visual-studio 2010中使用pickurl而不是手动输入,并获得了该URL Styles/input.css而不是~/Styles/input.css.

Guidance to ResolveUrl solved my problem, because I tried using pickurl in visual-studio 2010 instead of typing manually and got this url Styles/input.css instead of ~/Styles/input.css.

我的问题解决了.如何?我告诉过,但是为什么呢?我不能说.我认为~/Styles/Site.cssStyles/Site.cssStyles/input.css都是正确的url,但~/Style/input.css是不正确的.为什么?这仍然是开放的,它的答案肯定是真实的和可接受的答案.

My problem solved. How? i told, but why? i can not tell. I have fould that ~/Styles/Site.css, Styles/Site.css,Styles/input.css are all correct url but ~/Style/input.css is incorrect. Why? This is still open and its answer will surely be real and acceptable answer.

推荐答案

您需要按以下方式使用resolve url.

You need to use resolve url as follows.

<%= ResolveUrl("~/")%>

如下

<link href='<%= ResolveUrl("~/Styles/Site.css")%>'  rel="stylesheet" type="text/css" />

Master PageContent Page位于同一文件夹中时,可以正常工作,然后母版页中的所有内容都将起作用.

Working when your Master Page and Content Page are on the same folder then any include in the master page will work.

但是,当Master PageContent Page位于不同的文件夹中时,它将不会找到相同的样式表或Java脚本文件,因为文件不在同一文件夹中.

But when your Master Page and Content Page are in different folder it will not find the same style sheet or java-script file because files are not in the same folder.

因此,Resolve Url解析服务器上的URL.

So Resolve Url resolve the URL on the server.

这篇关于将样式应用于母版页中的嵌套页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆