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.

CSS

Change Background Color of Panel-Heading (Bootstrap)

Hey guys, For my own project I am trying to customize bootstrap but when I try to change the background color of the panel heading component nothing changes.

I use this code:

.panel-heading { background-color: red; }

3 Answers

Hi Jacob,

bootstrap.css contains a few style rules like this:

.panel-default > .panel-heading {
  color: #333;
  background-color: #f5f5f5;
  border-color: #ddd;
}

This is one of the style rules that sets the background on "panel-heading". There are a few more like this depending on the type of panel you nested your panel-heading in.

The selector that you tried to use, .panel-heading, doesn't have enough specificity to override that.

If you simply match the selector that bootstrap uses then you'll be able to override that css.

Assuming that you nested your .panel-heading in a .panel-default then this should work:

.panel-default > .panel-heading {
  background-color: red;
}

I can give a more specific answer if you want to show the html that you're using for this .panel-heading, specifically what is it nested inside.

try to put your code in the end of bootstrap css file and adding !important in your css selector.

.panel-heading {background-color: red!important}

hope that's work.

Hi Donny,

I think that !important should be used sparingly if at all.

If you do this then you won't be able to override this style later on in a media query for example. You're pretty much stuck with red now.

Thanks that worked! I actually wasn't aware that I could add !important, that made it work in my css file