简体   繁体   中英

Change h1 to h2 on site master from content page

I have logo in H1 tags on my master page. Now I have some more important stuff on one of content pages and would like to change H1 on master page to H2,and change H2 to H1 on that content page, what is best way to do it?

Im not talking about CSS style,I need to change markup, it is for optimization purpose.

Indeed you can, turn the heading tag into a server-side control and change when appropriate:

HTML

<h1 id="myHeading" runat="server">...</h1>

C#

myHeading.TagName = "h2";

I want to add to @GoranMottram's solution that you should provide a public method in your MasterPage, so that the ContentPage can call it:

In your Master:

public void ChangeHeading(int type)
{
    if(type < 1 || type > 6) throw new ArgumentException("type");
    myHeading.TagName = "h" + type;
}

Then you can call it from your Page(assuming your Master is called SiteMaster :

((SiteMaster)Page.Master).ChangeHeading(2);

Goran's is a good answer but if you don't want to or are unable to change the master page you could manipulate the document with JavaScript also.

I can give you sample if the posted answer doesn't help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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