1

I have a blog on Blogger and have some widgets. I was wondering that is it possible that a widget is displayed differently on a homepage as compared to rest of the pages?

For example a box

/* on home page, it should appear like this */
#box {
background: green;
width:200px; height:100px;
}

/* on other pages, it should appear like this */
#box {
background: red;
width:200px; height:200px;
}
1
  • 1
    default wordpress add class in your body. if you access on home page added home class and other page to page class added by wordpress theme. use .home #box{} for home page other page for .page #box{}. Commented Jul 18, 2013 at 6:47

4 Answers 4

7

I would suggest, put an ID into your home page like,

<body id="home"> and other ids for other pages

Now the CSS changes would be

/* on home page, it should appear like this */
#home #box {
background: green;
width:200px; height:100px;
}

/* on other pages, it should appear like this */
#others #box {
background: red;
width:200px; height:200px;
}
Sign up to request clarification or add additional context in comments.

1 Comment

I have already mentioned that I am on blogger. When I looked up my template, there is only one body element. How can I create different body elements for different pages and posts.
2

give the body a id

<body id="page">

then you can identify it with

#page #box { 
    .... your CODE
}

I guarantee this will work :)

Comments

0

You can't apply different stylesheets to different parts of a page. You have a few options:

The best is to wrap the different parts of the page in divs with class names: REFER

  <div class='part1'>
    ....
</div>

<div class='part2'>
    ....
</div>

Then in your part1 CSS, prefix every CSS rule with ".part1 " and in your part2 CSS, prefix every CSS rule with ".part2 ". Note that by using classes, you can use a number of different "part1" or "part2" divs, to flexibly delimit which parts of the page are affected by which CSS rules.

Comments

0

you have to put this code htlm code page not css code page if you said !important it is override other code

      <style>
             #box {
              background: red !important;
    width:200px !important; 
height:200px !important;
    }    
        </style>

8 Comments

This is invalid syntax.
Better, but it doesn't answer the question.
ı have same problem last months. Are you sure you put this code at your html page at part of css import? becase it work at me :( update it ı am again
Read the question again; it isn't asking how to make a box red, but rather how to have css affect items differently, on different pages.
ı read question body =) ı write my html code with notepad++ may be your ide is different becase ı was used carusel its height and width is different all of my page.. have a good day
|

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.