div positioning - firefox/ie

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jamesrharper
    New Member
    • Nov 2006
    • 4

    #1

    div positioning - firefox/ie

    hi everyone

    i got into the old browser compatability issues because i wanted to make my site centred. now i dont know a great deal about html and css to be quite honest but i found what i needed from the iternet and got the page centred in explorer. but there are some pretty big differences when the site is viewed in firefox.

    ok so here is the website not centred: www.princelee.c o.uk/gecko
    and here is my centred messy version: www.princelee.c o.uk/gecko/central

    to make it central i went from absolute div positioning to relative and then changed the left value to 50% and altered a margin-left value accordingly.

    there now appears to be two problems...
    1) the width of the div layers increase by about 15 pixels in firefox.
    2) the background colour of the navigation pane stops halfway through in firefox

    any help would be appreciated
    thanks
    james
  • dswethar
    New Member
    • Nov 2006
    • 65

    #2
    Originally posted by jamesrharper
    hi everyone

    i got into the old browser compatability issues because i wanted to make my site centred. now i dont know a great deal about html and css to be quite honest but i found what i needed from the iternet and got the page centred in explorer. but there are some pretty big differences when the site is viewed in firefox.

    ok so here is the website not centred: www.princelee.c o.uk/gecko
    and here is my centred messy version: www.princelee.c o.uk/gecko/central

    to make it central i went from absolute div positioning to relative and then changed the left value to 50% and altered a margin-left value accordingly.

    there now appears to be two problems...
    1) the width of the div layers increase by about 15 pixels in firefox.
    2) the background colour of the navigation pane stops halfway through in firefox

    any help would be appreciated
    thanks
    james
    Hi James,

    You can try this:
    body
    {
    text-align:center;
    margin:0px;
    padding:0px;
    width:100%
    }

    div
    {
    text-align:left;
    margin:10px auto;
    width:780px;
    }

    I've tried this, it worked for me. Please let me know if it did not work for you.

    Comment

    • drhowarddrfine
      Recognized Expert Expert
      • Sep 2006
      • 7434

      #3
      First quick observations:
      Browsers use their own default margins and padding on some elements so it is always better to set all to zero and set each element to what you want as needed.

      Most of your problems now and later are caused by IE. IE incorrectly expands divs to enclose absolutely positioned and floated elements. This is a bug in IE. Firefox and all other browsers are performing correctly. To get modern browsers to enclose the elements, add overflow:auto; to the css of the containing element.

      You are not using a doctype. Without one, IE goes into quirks mode and doesn't attempt to perform like modern browsers do. Add this to your first line:
      <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
      "http://www.w3.org/TR/html4/strict.dtd">

      IE will now work in standards mode, as any other browser would normally do, but may change what you have now, unfortunately. This is why we professional coders never test using IE until we get it working in Firefox or Opera first.

      You should also validate your html and css and correct any errors there.

      Comment

      • jamesrharper
        New Member
        • Nov 2006
        • 4

        #4
        Originally posted by drhowarddrfine
        First quick observations:
        Browsers use their own default margins and padding on some elements so it is always better to set all to zero and set each element to what you want as needed.

        Most of your problems now and later are caused by IE. IE incorrectly expands divs to enclose absolutely positioned and floated elements. This is a bug in IE. Firefox and all other browsers are performing correctly. To get modern browsers to enclose the elements, add overflow:auto; to the css of the containing element.

        You are not using a doctype. Without one, IE goes into quirks mode and doesn't attempt to perform like modern browsers do. Add this to your first line:
        <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd">

        IE will now work in standards mode, as any other browser would normally do, but may change what you have now, unfortunately. This is why we professional coders never test using IE until we get it working in Firefox or Opera first.

        You should also validate your html and css and correct any errors there.

        ok so i tried the doctype thing and you were right it caused loads of changes. if this was an important site or going to be visited loads then maybe i would use that but for now im going to leave it as it is i.e. with no doctype.

        i hope you can still help me even if i dont do this??

        i only have one problem now....and that is that ie and firefox read the div widths differently.
        so i want ie to see the main panel div width as 517 and the navigation panel as 230
        and i want firefox to have the main panel as 497 and the navigation panel as 210

        is there any sort of quick cheaty way to get the two to read this value differently??

        thanks

        Comment

        • drhowarddrfine
          Recognized Expert Expert
          • Sep 2006
          • 7434

          #5
          They don't read them differently. You are now seeing IEs broken 'box model' which is one of the reasons IE is the worst browser on the planet. It is why it's called 'quirks mode' and is created by the lack of a doctype.

          I know of no way around this except, perhaps, "conditiona l comments" which allow you to target IE with one set of values but I'm not sure you can make IE ignore the values given to other browsers. You'll have to google for that.

          Comment

          • AricC
            Recognized Expert Top Contributor
            • Oct 2006
            • 1885

            #6
            You need to use a DOCTYPE in your (X)HTML pages

            Comment

            • jamesrharper
              New Member
              • Nov 2006
              • 4

              #7
              Originally posted by AricC
              You need to use a DOCTYPE in your (X)HTML pages
              ok ok i am using a doctype

              here is the doctype version: www.princelee.c o.uk/gecko/doctype

              and now its a complete mess in both browsers. can anyone help me sort this layout

              i have 7 div layers setup

              one for the banner,
              one for the image just below the banner
              one for the main panel
              one for the navigation panel
              one for the curved bottom under the main panel
              one for the curved bottom under the navgation panel

              it all worked smoothly when i had it left aligned. all i want to do is have it centred.
              any ideas???

              Comment

              • drhowarddrfine
                Recognized Expert Expert
                • Sep 2006
                • 7434

                #8
                Now that all browsers are using the same set of 'rules' (the doctype), you can start on all the errors in your html and css I mentioned earlier. Validate for both to find your errors. You are using a lot of deprecated code. You can't expect browsers to work with invalid pages.

                Don't worry about the 'alt' errors for now. And your invalid, IE-only, scroll bar stuff can be ignored, too.

                I'm going out of town and won't be back for at least three days.

                Comment

                • jamesrharper
                  New Member
                  • Nov 2006
                  • 4

                  #9
                  Originally posted by drhowarddrfine
                  Now that all browsers are using the same set of 'rules' (the doctype), you can start on all the errors in your html and css I mentioned earlier. Validate for both to find your errors. You are using a lot of deprecated code. You can't expect browsers to work with invalid pages.

                  Don't worry about the 'alt' errors for now. And your invalid, IE-only, scroll bar stuff can be ignored, too.

                  I'm going out of town and won't be back for at least three days.
                  ok i'm on it
                  thanks for the help

                  Comment

                  Working...