tags:

views:

1320

answers:

3

I am sure sure if this is even possible due to the nature of CSS and being cascading, but I will try anyway.

I am creating a Terms and Conditions box which will contain some key elements that the user will select. Since the T&C's will have form components (radio buttons, check boxes). I don't really want to go through the trouble of putting it into an IFrame and getting the user input that way.

I figured using a with the overflow: auto property added, I could create an scrolling box with the T&C's and have the user select their options that way.

Well, because the T&C's have some mark up which would be directly effected by the sites css, I need to figure out a way to have this div not use the main CSS of the site.

Here is some sample code which would be similar to the approach I am trying:

<html>
<head>
    <style>
        div
        {
            border: solid 1px #000;
        }
        div small
        {
            font-size: 17pt;
        }
    </style>
</head>
<body>
    <div style="overflow: auto; width: 500px; height: 300px;">
        <small>This is small text</small>
        <div>
            <small>This is small text</small> 
            Lorem ipsum dolor sit amet, consectetur adipiscing
            elit. Donec vulputate mi sed nisl blandit sed porttitor massa fringilla.
        </div>
    </div>
</body>
</html>

The result of this is a pretty little black box with some text and then a sub box with more text and the key item in here is the text wrapped in .

Is there a way to have anything under a certain div NOT inherit the CSS? Maybe I need to take a completely different approach with this.

Thought? Ideas? Suggestions?

Thanks in advance!

+1  A: 

Instead of working directly with tag names, keep two sets of classes ("inner" and "outer") and work with those.

So you can have a div.inner definition, and a div.outer definition, and work on them separately. The inner one would have to explicitly undo the settings outer has, though.

Something like

<div class="outer">
  <div class="outer">Some content. <small>Small text.</small></div>
  <div class="inner container">
     <small>Blah blah blah</small>
     More content
  </div>
</div>

And in your CSS define whatever you need,

div.outer {
   border: 1px solid black;
}
div.outer small {
   font: 17pt;
}
div.inner {
   border: none;
}
div.inner small {
   font: 15pt;
}
div.container {
   overflow: auto;
   width: 500px;
   height: 300px;
}
Welbog
Okay, this is what I feared. So if my sub content has a ton of different tags that would be directly changed from the css, I would need to create the CSS classes as described above to change all my tags... I am sad, but the first step towards grief is denial.
Jason Heine
A: 

don't think there is a way to not inherit css. i think the only way is to 'reset' all the styles set on its parents explicitly. see eg http://meyerweb.com/eric/thoughts/2007/05/01/reset-reloaded/ for a list of default properties.

second
A: 

There is, as second notes, no way to inherently prevent the cascade of styles, it's the cascade that defines CSS after all. So you are reduced to using the .inner and .outer approach that Welbog suggested.

So you're reduced to defining your styles for the main document as you normally would. However to override those styles for the same elements under the T&C div you would have to explicitly override/re-style. You could use two stylesheets to retain clarity, but you'd have to remember, in the t_and_c.css to explicitly preface every declaration with the id of the enclosing div, for example:

#t&c p {...}

#t&c a:link,
#t&c a:visited {...}
David Thomas