12

I have an external css file which applies 35px padding to my content div. All my html pages are loaded inside that div but for one of them I want to use 0 padding-right.

I tried inline css, applying it directly on the body of that page and also using !important but nothing worked.

What I am I doing wrong?

index.html:

<div id="content"><?php include "page.html"?></div>

main.css:

#content{
    margin-top: 303px;
    padding: 35px;
    z-index:1;
}

page.html:

<body style="padding:0px;">
Tasos
  • 1,622
  • 4
  • 28
  • 47

4 Answers4

22

To override a css setting you must use the keyword important.

<body style="padding:0px ! important;"> 
Armando Peña
  • 415
  • 2
  • 6
8

CSS reads top-down, therefore anything lower in the code should be overwritten, see: http://jsfiddle.net/PFx9h/

If something isn't taking effect it's because there's some other code overriding it. Use an element inspector such as Webkit Dev Tools or Firebug to see what styles are being applied and how.

EDIT:

Since you posted your code, body styling won't apply to a div.

Fluidbyte
  • 5,162
  • 9
  • 47
  • 76
3

Fluidbyte was right, I was being stupid trying to apply 0 padding on the wrong element. Adding

<style>
#content{
    padding-right:0px;  
}
</style>

on page.html worked fine, overrides the external css.

Tasos
  • 1,622
  • 4
  • 28
  • 47
0

Either apply the style="padding:0px;" on the content div inline (not recommended), or load your style after you load your external style sheet. Applying style="padding:0px;" to the body will only affect the body, and not apply to every element within it.

j08691
  • 204,283
  • 31
  • 260
  • 272