Skip to main content

How to use the !important tag in CSS

"CSS" stands for: "Cascading Style Sheets'. 

This means that the styles cascade and are applied in order as they are read by the browser. The browser reads CSS from top down. The first style is applied and then the second and so on. So if a style appears at the top of a style sheet and then is changed lower down in the document, the last one wins!

For example, in the following style sheet, the div class "text" will be white, even though the first style property applied is black:

#text{ color: #000000;}

#text{ color: #FFFFFF;}

The !important rule is a way to force styles out of order. A rule that has the !important property will always be applied no matter where that rule appears in the CSS document. So if you wanted to make sure that a property always applied, simply add the !important property to the tag.

So, to make the div class text always black, simply add the
"!important" tag right before the closing semicolon.

#text{ color: #000000 !important;}

#text{ color: #FFFFFF;}

To relate this back to SharePoint here are  few examples where you might need to use the !important tag to get your styles listen.

Example 1: You have applied a custom theme to a site. But on some of your pages the colors are inconsistent. Use the !important tag to force the class attributes so that all color behaviors act as expected.

Example 2: You are in the middle of creating your custom brand and notice that around the content area there is some hard coded margins. You could either create your own custom master page to fix this or you could force the margins the way you want them by using the !important tag.

I do not suggest using the !important tag for everything. Its a bit of a cop out. But there are some cases where it really does help keep your design functioning as your want it.


Anonymous said…
u have opened my eyes
Sqiar BI said…
It's actually a cool and useful piece of info. I am glad that you simply shared this useful info with us. Please keep us up to date like this. Thanks for sharing, You can also check out this

Popular posts from this blog

SharePoint 2010 Base CSS Classes

This will be the first of many SharePoint 2010 posts. I will be focusing on a few of the main CSS classes used for SharePoint 2010 Public Beta. As the product becomes more final there might be some changes to the class names but I will be sure to create a new post if that happens. This will be quite a lengthy but it should be helpful. The default CSS given below are just highlights of the full CSS attributes for that class.I will be using a basic team site as my base for the screenshots. Here is a basic structure of the main areas that I will cover.Ribbon RowTable Row Left Site Actions Navigate Up Edit Tab List Browse Page Table Row Right Give Feedback Welcome Menu WorkspaceBody Container Title Row Title Title Logo Title Text / BreadcrumbPage DescriptionSocial Data SeparatorI like It Tags/Notes Top Header 2/Top Links li Static-Selected li Static SearchHelpStatus Bar Container Main A…

How To: Hide Left Side Navigation on Home Page

I was recently asked: "How can I hide the side nav bar on the main homepage layout ?? I want to be able to use the side NAV with in the team site etc etc, but I don't want it on the front page.. " There are a couple of ways to do this in SharePoint 2010. If you are using a non-publishing site you can add a Content Editor Web Part to the page and add the following to the HTML Source.
body #s4-leftpanel
display: none;
margin-left: 0px;
Basically the CSS above hides the left navigation Div, and then sets the content area to not have a left margin. Once you are done, simply modify the web part and hide it on the page. If you are using a publishing site for your homepage simply add the same styles specified above to a custom page layout. That way if you have a need for other pages that do not need the left side navigation you can re-use the page layout.

SharePoint 2010 Content Query for Blog Posts

I hope this post will help many of you feel comfortable with using the Content Query Web Part.In this post I will walk you through the process of creating a content query web part and configuring it to show custom field types. I will also give details on how to use XSLT to stylize and format the data being pulled. I will be using the following scenario as an example. Say that you had a site collection with a top level publishing site. This publishing site would display a the most recent blog posts from all blog sites within its own site collection. To solve this problem we will use a Content Query Web Part and a customized ItemStyle.xsl using XSLT.Please note that the “SharePoint Server Publishing Infrastructure” needs to be enabled at the site collection to display the content query web part.Step 1: Add a Content Query Web Part to PageNavigate to the site that you want the blog posts to show up and click on edit page. Under Editing Tools in the Ribbon, Click on insert > Web PartUn…