displaying a div only on tumblr blog homepage?

前端 未结 9 1955
陌清茗
陌清茗 2020-12-24 11:17

I have a fairly novice understanding of CSS and HTML, and I\'m trying to do something that I think should be relatively simple (in a custom tumblr theme I\'m creating), but

9条回答
  •  孤独总比滥情好
    2020-12-24 11:57

    This is solved by using div:not() operator.

    The HTML Markup will be

    {block:IndexPage}
    
    {/block:IndexPage}
    

    Now add this CSS to

    #banner div:not(.banner_1)
    {
       display:none;
    }
    {block:SearchPage}
        #banner
        {
           display:none;
        }
    {/block:SearchPage}
    {block:TagPage}
        #banner
        {
           display:none;
        }
    {/block:TagPage}
    

    The background: {CurrentPage} is a Tumblr theme variable which returns the page number of index pages (like 1, 2, 3, ...). Thus the home of any Tumblr blog is page number "1". Now I have defined the class of a div with this page number concatenated with a string "banner_" (Class can not be numeric. WTF why?) - making the class name "banner_1" on homepage. Next, in CSS, I have added display:none property to :not selector of that banner_1 class div. Thus excluding div with banner_1 class, all other div in under #banner div will disappear. Additionally, div with id #banner is hidden in search and tag pages.

    Note:

    is required. Without this, :not will hide all divs in the html.


    Warning: IE users (is there anyone left?) need to change their habit. This is only supported in FF, Chrome, Safari and Opera.

    I have implemented this in http://theteazone.tumblr.com/ The Big Banner (Tea is a culture) is absent in http://theteazone.tumblr.com/page/2

提交回复
热议问题