Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > Re: Applying a style sheet only to a single div

Reply
Thread Tools

Re: Applying a style sheet only to a single div

 
 
brm6546545
Guest
Posts: n/a
 
      04-19-2007
On Apr 19, 2:54 pm, Desmond <(E-Mail Removed)> wrote:
> On 19 Apr, 19:28, (E-Mail Removed) wrote:
>
> > I am developing a custom content management solution for a client. I
> > was wondering if there was a way to allow them to maintain a style
> > sheet that would only affect only a certain DIV. I know you could make
> > the div a class or make my style sheet take precedence, but they could
> > still affect anything I haven't implicitly defined in my style sheet.
> > I'm no so worried about them intentionally changing anything but they
> > could accidentally affect other parts of the page unknowingly

>
> > any ideas?

>
> This is easy every DIV can have it's own style. A dive will have a
> unique ID
>
> <head>
> <LINK href="holclub.css" type=text/css rel=stylesheet>
> </head>
>
> <DIV id=PageContent>
>
> *** In the style sheet ****
>
> #PageContent
> {
> position:absolute;
> font-family:verdana,helvetica,arial;
> font-size: 14px;
> position:absolute;
> left:150px;
> width:600px;
> top: 106px;
> height:360px;
> border-width: 0px;
> border-style:solid;
> margin-top:5px;
> margin-left:5px;
>
> }
>
> Hope this helps.
> Dssmond.


I know how IDs and classes work. but i guess i would like a style
sheet to be edited by the user that cannot affect any other items on
the page

example if the user sets

table{
border:solid 5px red;
}

it will not affect any of my tables just tables within thier DIV

I know they could do

#PageContent table{
border:solid 5px red;
}

but i don't want to give them the ability to mess up anything outside
there "box"

 
Reply With Quote
 
 
 
 
Jukka K. Korpela
Guest
Posts: n/a
 
      04-19-2007
Scripsit brm6546545:

> I know how IDs and classes work. but i guess i would like a style
> sheet to be edited by the user that cannot affect any other items on
> the page


That's not possible. If they can write anything into a style sheet, you
cannot prevent them from affecting all elements on a page. The "best" you
could do in that direction is that you could make the HTML code contain
<link> elements referring to their style sheet and your style sheet, in that
order, and declare as !important everything that you want to "force" upon
them. They could still beat your rules by using !important and more specific
selectors. Besides, how could you force your style rules on all elements
except one div? The answer is that you can't.

> I know they could do
>
> #PageContent table{
> border:solid 5px red;
> }
>
> but i don't want to give them the ability to mess up anything outside
> there "box"


Well, it's their site, isn't it? If you clearly specify that they must
precede all rules with #PageContent and explain why, then it's up to them
whether they mess up their site.

You could make things easier, though, by using a short id value. If they
need to prefix everything in a fixed way, the prefix need not be mnemonic;
it could be just #c for example - harder to mistype than #PageContent.

As a completely different approach, if you make the box content a separate
HTML document, embedded with <iframe> or <object>, you could make it use
their style sheet and yours and the embedding document your style sheet
only. That way, everything they set in their style sheet would affect the
box content only.

Embedding approaches have their drawbacks of course. In particular, the box
would have a fixed size and it might need its own scrolling mechanism.

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
<div ... /> and <div ...></div> K Viltersten ASP .Net 4 03-31-2009 07:33 PM
Applying a style sheet only to a single div russell.allbritain@gmail.com HTML 2 04-20-2007 09:43 AM
Email Confirmation Message Doesn't pick up the style sheet only in hotmail/yahoo Tatyana ASP .Net 2 08-25-2006 06:11 PM
Content Page specific style style sheet rshillington@gmail.com ASP .Net 0 07-14-2006 03:45 PM
how do I get all the div's that have a certain style sheet class lkrubner@geocities.com Javascript 9 12-30-2004 02:05 AM



Advertisments