0

I have a master page which contains the header and footer for all pages. It invokes a css file ( master.css) which contains styles for pages : page1.aspx, page2.aspx, page3.aspx.

However, I now have another css file ( firstpage.css) for the page1.aspx alone. This must override the styles of the page1.aspx in the master.css (chaos!!)

Is there a tool that does this comparison for me? - search for the similar tags in the given 2 pages and merges them

Can I call the master.css for all other pages besides page1.aspx?

1
  • first option is dont user css file on master page instead use page1.aspx ,pag2.aspx css respectively their own css second option is use javascript and set css according to page Commented Jun 25, 2013 at 12:48

6 Answers 6

1

If you include the firstpage.css after master.css, and your css is well structured, the contents of firstpage.css will override those of master.css.

If you have very specific rules in master.css you need to ensure a higher selector specificity value for the same rule in firstpage.css. You can read more here: http://www.w3.org/TR/css3-selectors/#specificity http://css-tricks.com/specifics-on-css-specificity/

As a last resort you can use !important in your page specific rules. However, this is probably going to cause you even more pain in the future.

Sign up to request clarification or add additional context in comments.

Comments

0

If there aren't many pages on your site, you could define a content area for css files and specify on each page which styles to reference. If you have 100 pages this could be tedious though.

If this page is very different, you may consider not using master page.

Also, take into account that styles can be overwritten so having both css files on the same page could provide desired result if styles are defined properly.

Comments

0

Cascading stylesheets are designed to work in a cascading manner. However, you can create a content placeholder with default content in master page. This can contain master.css that you can override in your page with firstpage.css. Personally I would design a common css file for all pages within a site and then have one or more "page specific" css files that can override and add new styles.

Comments

0

You could do it this way if you don't want to use any of the styles from site.css. In Site.master where you have your current site.css reference, replace that with: (You'll need to change about.aspx)

NOTE - this is potentially bad because you might end up with CSS duplication if you completely remove the reference to site.css and then decide you need some of the styles, and have to add them to the new stylesheet.

<%
    string sPagePath = System.Web.HttpContext.Current.Request.Url.AbsolutePath;
    System.IO.FileInfo oFileInfo = new System.IO.FileInfo(sPagePath);
    string sPageName = oFileInfo.Name.ToLower();

    if (sPageName == "about.aspx") { %>
        <link href="~/Styles/about.css" rel="stylesheet" type="text/css" />
    <% } else { %>
        <link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
    <% } %>

Getting the current page name code from - https://stackoverflow.com/a/1833313/2470724

EDIT

It also depends on what kind of styles you want to override, if it's text etc, then you could just add a class to your body content, and then style each page accordingly.

Comments

0

You have the following options:

  1. The best way to do it would be to pull out the style definitions from the master css which you want to be duplicated and put them in a seperate stylesheet. Then you can do conditional statements in the head to apply the relevant stylesheet for the appropriate page.
  2. You could also put the duplicate sylesheet that you want to apply after the master css in the head or on the page itself (which would obviously be after the head), this way the styles would be overridden. You should note that this might not work well across all browsers specially IE.
  3. You could have !important next to every style you wish to override but this would be a lot of work and again you might run into some cross-browser compatibilty (read IE) issues.
  4. The last option you have is to apply styles to the elements using javascript/jquery after the document is loaded. This will definitely work but this would again be a lot of work.
  5. Read option 1.

Comments

0

"StyleSheetTheme" is what you are looking for. Take advantage of the Theming support of ASP.Net instead of applying stylesheets separately to all pages. If there is a page you want to be styled differently, then disable "theme" in its page declaration.

EnableTheming="true" / "false" in the page declaration

and styleSheetTheme="theme_folder_name" inside "pages" element of web.config

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.