Jump to content

[SOLVED] Is this a CSS bug in IE7?


phpknight

Recommended Posts

not really.... that would center it but 25% of the parents width woudl yeild a variable width for the element in question - great for fluid layouts BUT IMO it is better to give it a width and margin auto.

 

The reason the css in the OP didn't work is becasue of width: 400 - you need to specify a unit measure like px or % otherwise the browser is guessing...

Link to comment
Share on other sites

--cross browser centering, inner block is centered, but text within inner block is left aligned:

<div style="text-align:center;">
    <div style="width:400px;text-align:left;margin-left:auto;margin-right: auto;">
        **your content**
    </div>
</div>

 

Link to comment
Share on other sites

no, just put that structure within whatever you want:

<table><tr>
    <td><!-- left col -->
        <div style="text-align:center;">
            <div style="text-align:left;width:400px;margin-left:auto;margin-right:auto;">
                **your content**
            </div>
        </div>
        ** some other content, non centered **
    <td>
    <td><!-- right col -->
           ** more non centered stuff **
           ** repeat the structure above for centered content within whatever you want **
           ** you're not limited to the whole page centered or non centered **
    <td>
</tr></table>

--only center the content you want! The method above is the cross browser compatable way.

Link to comment
Share on other sites

Auto margins work fine with IE.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>IE auto margins</title>
</head>

<style type="text/css">

body {
    font-family: "Trebuchet MS", Verdana, Arial;
    font-size: 18px;
    background-color: #F1F1F1;
}

#container {
    width: 780px;
    margin: 20px auto; /* auto margins */
}


#header, #content {
    border: 2px solid #E1E1E1;
    padding: 20px;
    margin-bottom: 30px;
    background-color: #FFF;
}

#header h1 {
    color: #333;
    text-align: center;
    margin: 0;
}

#content code {
    margin: 5px 30px;
    width: 90%;
    display: block;
    font-size: 14px;
}

</style>

<body>

<div id="container">

    <div id="header">
        <h1>IE Auto margins</h1>
    </div>

    <div id="content">
      <p>Auto margins work fine within IE!</p>

      <p>I find auto margins work fine within IE when you use valid DOCTYPE, like the following:</p>
      <code><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"></code>

      <p>And that you provide a width to the element you wish to center</p>
      <code>#container { width: 780px; margin: 20px auto; /* auto margins */}</code>

      <p>Both of the above is the minimun requirement for auto margins</p>

      <p>AFAIK this works for IE6 and IE7 not sure about other versions.</p>

    </div>

</div>

</body>
</html>

Link to comment
Share on other sites

I think you are right.  I got rid of the two divs and wrote testing.  It was centered.  Once I removed the DOCTYPE, it was messed up.  So, that DOCTYPE appears to be the solution.  How did you ever figure that one out?  Great call!

You are supposed to define a valid doctype at the top of every page. Without the doctype the browser will go into quirks mode, the doctype tells the browser what version of html you are using and works in standards mode.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.