Re: Applying a style sheet only to a single div

Discussion in 'HTML' started by brm6546545, Apr 19, 2007.

  1. brm6546545

    brm6546545 Guest

    On Apr 19, 2:54 pm, Desmond <> wrote:
    > On 19 Apr, 19:28, 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"
    brm6546545, Apr 19, 2007
    #1
    1. Advertising

  2. 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/
    Jukka K. Korpela, Apr 19, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    495
  2. Tatyana
    Replies:
    2
    Views:
    470
    Tatyana
    Aug 25, 2006
  3. Orgun
    Replies:
    6
    Views:
    347
    H. S. Lahman
    Sep 26, 2006
  4. Replies:
    2
    Views:
    1,844
    Toby A Inkster
    Apr 20, 2007
  5. Replies:
    9
    Views:
    141
    Randy Webb
    Dec 30, 2004
Loading...

Share This Page