Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Using jQuery Plugins Add a Sticky Navigation Bar Adding Sticky Navigation

Abhijit Das
Abhijit Das
5,022 Points

I want to add a back ground color of header

Hi friends, Just out of curiosity, I want to add a default background color on my header class on document load..it seems it's not happening here, pls help me. Thanks

2 Answers

Tsenko Aleksiev
Tsenko Aleksiev
3,819 Points

Aaaaa,

.header{
  background-color: red; //for example
}

Is this what you want? Post your code to check it.

Abhijit Das
Abhijit Das
5,022 Points

I did that already Tsenko Aleksiev still it's not reflect on the page. Later i figure out that i have to put height for header element as well..Thank you for your reply.

Jordan Watson
Jordan Watson
14,738 Points

Hi Abhijit Das,

There are a few ways you can do this on is by adding an inline style directly on to the

    <header style="background-color: dodgerblue;"></header> 

element or add a style within the head of the document

    <style>
        header{background-color: dodgerblue;}
    </style>

or you can do it the most common way which is include it in an external style.css file which you can include in the head also

    <link rel="stylesheet" type="text/css" href="css/style.css" />

But going but what you are asking adding the a style directly to the element will ensure that the background color will be applied as soon as the page starts to load.

Abhijit Das
Abhijit Das
5,022 Points

Hi Jordan Watson thank you for your reply...with that background-color; I have to declare height for getting the BG color.