Re: Possible to have nested <div> tags!

Discussion in 'HTML' started by Jukka K. Korpela, Jun 23, 2003.

  1. "Hans Börjesson" <> wrote:

    > Is it possible to use nested <div> tags?


    Of course. Wasn't this easy to check from HTML specifications?

    > The sample is not html validated


    Why bother playing with it then? You can throw all kinds of tag soups
    and sallads at browsers and watch them misbehave, but it's not
    civilized entertainment.

    > and require javascript to be enabled


    Well, then it's not an HTML problem and surely has nothing to do with
    the question on the Subject line.

    > <div id="div1" name="div1" style="top:10;left:10;display:block;">


    All correctly behaving browsers ignore that style sheet. Well,
    technically they don't ignore the last declaration, but it coincides
    with the initial (default) setting. This, in turn, has nothing to do
    with HTML and nothing to do with JavaScript.

    Hint: Create an HTML page that works robustly. Use validators to
    help you in this if you understand what a DTD is. Time permitting, add
    then some optional CSS. Don't forget to use available CSS checkers.
    Having done this, you might try to play with JavaScript, and then
    comp.lang.javascript is surely the best group to ask for help.

    --
    Yucca, http://www.cs.tut.fi/~jkorpela/
    Pages about Web authoring: http://www.cs.tut.fi/~jkorpela/www.html
    Jukka K. Korpela, Jun 23, 2003
    #1
    1. Advertising

  2. Ok here is a validated document then. Still the same problem. Maybe you are
    right this is a javascript problem but it does not have to be. I would say
    that it could also be an html problem for example if nested <div> tags is
    not feasible (now you say it is feasible so I guess you are right that it is
    not a html problem but I was too stupid to realise this) or it can be a
    rendering problem in the browser (IE and Opera does not behave in the same
    way as for example Netscape in this case). Well I will give it a try in
    javascript newsgroup but I guess they will forward me to yet another
    newsgroup...

    Anyway thanx for you help
    Regards
    /Hans Börjesson


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <TITLE>DIV Test</TITLE>
    </head>

    <body>
    <div id="div1" >
    This is Div1!
    <div id="div2" >
    This is Div2!
    </div>
    </div>
    <br>
    <br>

    <form id="frm1" action="http://www.w3c.org/" method="post">
    <input type="button" value="Toggle Div1" onclick="ToggleDiv('div1');">
    <input type="button" value="Toggle Div2" onclick="ToggleDiv('div2');">
    </form>

    <script language="javascript" type="text/javascript">
    <!--
    function ToggleDiv(div_in) {
    var mydiv;
    mydiv = document.getElementById(div_in);
    if (mydiv.style.visibility == "hidden")
    mydiv.style.visibility = "visible";
    else
    mydiv.style.visibility = "hidden";
    }
    //-->
    </script>
    </body>
    </html>
    Hans Börjesson, Jun 24, 2003
    #2
    1. Advertising

  3. Jukka K. Korpela

    Mark Parnell Guest

    Hans Börjesson wrote:
    > Ok here is a validated document then. Still the same problem.
    >

    <snip>

    I get the same problem as you do, in both Mozilla and IE. I would certainly
    say that it is a JS problem, but I can't help you there, I'm afraid.

    Good luck with it.

    --

    Mark Parnell
    http://www.clarkecomputers.com.au
    Mark Parnell, Jun 24, 2003
    #3
  4. Jukka K. Korpela

    rf Guest

    "Hans Börjesson" <> wrote in message
    news:bd8o4g$e$...
    > Ok here is a validated document then. Still the same problem. Maybe you

    are
    > right this is a javascript problem but it does not have to be. I would say
    > that it could also be an html problem for example if nested <div> tags is
    > not feasible (now you say it is feasible so I guess you are right that it

    is
    > not a html problem but I was too stupid to realise this) or it can be a
    > rendering problem in the browser (IE and Opera does not behave in the same
    > way as for example Netscape in this case). Well I will give it a try in
    > javascript newsgroup but I guess they will forward me to yet another
    > newsgroup...


    <snip code>

    If you have a quick look at section 11.2 of the CSS2 specs:
    http://www.w3.org/TR/REC-CSS2/visufx.html#visibility
    you will see that the default value for the visibility property is inherit.
    That is, inherit the visibility property value of the parent element.

    When you first open this page div1 _inherits_ visible from the body element
    (which BTW has inherited this from the html element). div 2 also _inherits_
    visible.

    When you click toggle div 1 the visibility property of div1 gets set to
    hidden. Since the visibility property of div2 is still inherit then div2
    disappears as well, since it inherits hiddenness.

    When you click toggle div 1 again, the reverse happens, with the exception
    that the value for div1 is now visible. Div2 inherits this and magically
    reappears.

    Now, click toggle div2. Sure enough div2 disappears. Click toggle div2
    again. Now, the visibility property has a value of visible, not inherit.
    Div2 reappears.

    Now, click toggle div1. Div1 is now hidden, it disappears. What about div2
    though. It no longer inherits this value, its visibility property has the
    value visible, just like you told it to. Div2 remains visible.

    That wasn't too hard after all now, was it. :)

    Although the spec is somewhat unclear on this I think is quite in order to
    have visible elements nested inside invisible elements. The spec actually
    does say the visiblity property specifies whether the boxes *generated by an
    element* are rendered. It does not say anything about boxes generated by
    child elements, I think they should behave independently.

    IMHO the browsers where this 'problem' of yours does not appear are, in
    fact, the ones that are broken.

    I doubt that you will get any joy over at clj as this is a CSS issue, not a
    javascript one. That is why I answered here rather than over there.

    If you want these divs to behave the way I think you do then change
    mydiv.style.visibility = "visible";
    to
    mydiv.style.visibility = "inherit";

    Cheers
    Richard.
    rf, Jun 24, 2003
    #4
  5. Hi Mark!

    I see when I removed the <table> I had in inside my "outer" div also IE
    behaves the same way as NN6+ (if you test the html in my original post you
    will see that IE will behave in another way). I removed my <table> when I
    created the validated sorce code to make the code as small as possible but I
    only tested the result in NN6+ and the problem still occured but the problem
    was now also the same in IE.


    Thanks for letting me know.

    Regards
    /Hans Börjesson



    "Mark Parnell" <> wrote in message
    news:3ef7ebe9$0$...
    > Hans Börjesson wrote:
    > > Ok here is a validated document then. Still the same problem.
    > >

    > <snip>
    >
    > I get the same problem as you do, in both Mozilla and IE. I would

    certainly
    > say that it is a JS problem, but I can't help you there, I'm afraid.
    >
    > Good luck with it.
    >
    > --
    >
    > Mark Parnell
    > http://www.clarkecomputers.com.au
    >
    >
    Hans Börjesson, Jun 24, 2003
    #5
  6. Ahh I see! Thanks for a good explanation Richard.

    I found out that IE behaved the same way with my validated code (actually I
    removed a <table> inside my "outer" <div> that seems to make IE behave
    differently. If I "re-add" this table (which you can see in my original
    post) in the validated source code IE behaves differently than NN6+.

    Once again thanks for pointing me in the right direction.

    Regards
    /Hans Börjesson
    Hans Börjesson, Jun 24, 2003
    #6
  7. Jukka K. Korpela

    rf Guest

    "Hans Börjesson" <> wrote in message
    news:bd8t8f$j4$...
    > Ahh I see! Thanks for a good explanation Richard.
    >
    > I found out that IE behaved the same way with my validated code (actually

    I
    > removed a <table> inside my "outer" <div> that seems to make IE behave
    > differently. If I "re-add" this table (which you can see in my original
    > post) in the validated source code IE behaves differently than NN6+.


    I suspect because IE has more bugs than a rain forest.

    Tables are layed out differently than other elements. I suspect that IE is
    saying "I can't be bothered, lets just disappear the whole table, contents
    and all".

    If two browsers behave differently and one of them is IE then it's a safe
    bet the other browser is doing it correctly (unless of course if it's
    Netscape 4.x).

    On reflection: since the specs are possibly open to interpretation you
    should anticipate those interpretations. In this case, pressing "toggle div
    1" should disappear both divs, just to be sure (and I assume that is what
    you want).

    > Once again thanks for pointing me in the right direction.


    No problem.

    Cheers
    Richard.
    rf, Jun 24, 2003
    #7
    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. Dean H. Saxe
    Replies:
    0
    Views:
    1,016
    Dean H. Saxe
    Jan 3, 2004
  2. Kwasi
    Replies:
    13
    Views:
    591
    Kwasi Yeboah via JavaKB.com
    Dec 1, 2004
  3. Tim Radford
    Replies:
    0
    Views:
    948
    Tim Radford
    Jun 23, 2003
  4. Chris

    table-tags within div-tags

    Chris, Feb 9, 2004, in forum: HTML
    Replies:
    5
    Views:
    13,245
    Chris
    Feb 10, 2004
  5. Jimmy
    Replies:
    7
    Views:
    4,889
    Chaddy2222
    Nov 21, 2008
Loading...

Share This Page