Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

attach css to single div 1

Status
Not open for further replies.

ThomasJSmart

Programmer
Sep 16, 2002
634
Hi

I have an html document with a main css file include that has styles for the whole document and im trying to attach a second css file but i want the styles in it to be only active inside a single div. i can strip out body/html tags with php but the remaining styles like div, p, a, etc should all only be active inside the div i want it attached to. It is also importent that the styling inside the holder div in no way effects what is outside the div, for example positioning and such. the holder div has a fixed width/height and overflow:hidden.

how could i get this to work?

i know it could also be done by using an iframe instead of a div but that gives a lot of complications with javascript functions i need to execute in the div/iframe so if possible i would rather not do this.



I learned a bit yesterday, today i learned a lot, imagine what i'll learn tomorrow!
 
Put an id on the div, and then set up all your styles for the content inside the div to be more specific than your page-based styles by adding the id first.

The code below shows the CSS (which could equally be in the page or linked through a CSS file) that over-rides all styles for the div with the id 'specialDiv':
Code:
...
div { font-weight: bold; color: #FF3333; }
[!]#specialDiv[/!] div { font-weight: normal; color: #000000; }
p { background-color: #EEFFDD; }
[!]#specialDiv[/!] p { background-color: #FFFFFF; }
...
<div><p>Some text</p></div>
...
<div [!]id="specialDiv"[/!]>
  ... content here ...
</div>
...
Cheers,
Jeff

[tt]Visit my blog [!]@[/!] Visit Code Couch [!]@[/!] [/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
right :D i was thinking much to complicated, easiest solution is often the best, i can add the #id to the css with php automatically :)

cheers!

I learned a bit yesterday, today i learned a lot, imagine what i'll learn tomorrow!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top