Заполнение абсолютного div интерпретируется по-разному в Internet Explorer 7 - PullRequest
0 голосов
/ 25 сентября 2018

В Internet Explorer 8 и выше и во всех других браузерах заполнение абсолютного элемента div не толкает содержимое вниз страницы при наличии отрицательного поля.

Но в Internet Explorer 7 заполнениев любом случае выталкивает содержимое вниз.

Этот код не использует JavaScript.

Вот скриншот его работы в Internet Explorer 8, Firefox и Chrome (вертикального переполнения нет):

enter image description here

Вот рисунок того же кода, работающего в Internet Explorer 7:

enter image description here

Вот мой код:

p {
  margin-top: 0;
  margin-bottom: 0;
}

* {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
} 

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}
#container {
  min-height: 100%;
  position: relative;
}
#header {
  background: yellow;
  height:50px;
}
#body {
  padding-bottom: 50px; /* Height of the footer */
}
#footer {
  position: absolute;
  bottom: 0;
  width: 100%;
  height: 50px;         /* Height of the footer */
  background: green;
}

#body {
  height: 100%;
  width: 100%;
  position: absolute;
  margin-top: -50px;
  padding-top: 50px;
}
#main-content-container {
  height: 100%;
}
.inset-boxshadow-and-background {
  background-color: red;
  height: 100%;
  width: 100%;
}
</style>

<!--[if lt IE 7]>
<style media="screen" type="text/css">
#container {
  height: 100%;
}
</style>
<![endif]-->
<body>

<div id="container">
  <div id="header">

  </div>

    <div class="body-parent">
      <div id="body">
        <div id="main-content-container">
          <div class="inset-boxshadow-and-background">
          <!-- Body start -->
          <p>In this demo the footer is pushed to the bottom of the screen in all standards compliant web browsers even when there is only a small amount of content on the page. This with work with IE 6 and IE 5.5 too. Non-standards compliant browsers degrade gracefully by positioning the footer under the content as per normal. Read the <a href="https://matthewjamestaylor.com/bottom-footer">full article</a> for all the details.</p>
          <!-- Body end -->
          </div>
        </div>
      </div>
    </div>
  <div id="footer">

  </div>
</div>

</body>

И, пожалуйста, не "Internet Explorer 7 бесполезен", потому что я знаю, что он воняет!

Ответы [ 3 ]

0 голосов
/ 26 сентября 2018

Попробуйте использовать следующий код:

<style type="text/css">
    p {
        margin-top: 0;
        margin-bottom: 0;
    }

    * {
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
        box-sizing: border-box;
    }
    html,
    body {
        margin: 0;
        padding: 0;
        height: 100%;
    }
    /* Core styles */
    .header {
        position: absolute; /* needed for stacking */
        height: 50px;
        width: 100%;
        background-color: yellow;
    }

    .content {
        position: absolute;/* needed for stacking */
        top:50px;
        width: 100%;
        height: 100%;
        background-color:red;
    }
    .footer {
        position: absolute;/* needed for stacking */
        width: 100%;
        height: 50px;
        bottom:-50px;
        background-color:aqua;
    }
    #main-content-container {
        height: 100%;
    }

    .inset-boxshadow-and-background {
        background-color: red;
        height: 100%;
        width: 100%;
    }
</style>
<div class="header">
    <div class="header-inner"></div>
</div>
<div class="content">
    <div class="content-inner">
        <div id="body">
            <div id="main-content-container">
                <div class="inset-boxshadow-and-background">
                    <!-- Body start -->
                    <p>In this demo the footer is pushed to the bottom of the screen in all standards compliant web browsers even when there is only a small amount of content on the page. This with work with IE 6 and IE 5.5 too. Non-standards compliant browsers degrade gracefully by positioning the footer under the content as per normal. Read the <a href="https://matthewjamestaylor.com/bottom-footer">full article</a> for all the details.</p>
                    <!-- Body end -->
                </div>
            </div>
        </div>
    </div>
</div>
<div class="footer">
    <div class="footer-inner"></div>
</div>

Обновление : следующий код хорошо работает на моей стороне, пожалуйста, обратитесь к нему.

<style type="text/css">
    p {
        margin-top: 0;
        margin-bottom: 0;
    }

    * {
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
        box-sizing: border-box;
    }

    html,
    body {
        margin: 0;
        padding: 0;
        height: 100%;
    }

    #container {
        height: 100%;
        position: relative;
        background-color:red;
    }
    #header {
        position: absolute;
        top:0;
        width:100%;
        background-color: yellow;
        height: 50px;
    }
    .body-parent {
        margin-top: 50px;
        position: absolute;
    }
    #footer {
        position: absolute;
        bottom: 0;
        width: 100%;
        height: 50px; /* Height of the footer */
        background-color: green;
    }
    #body {
        height: 100%;
        width: 100%;
        padding-bottom: 50px; 
    }

    #main-content-container {
        height: 100%;
    }

    .inset-boxshadow-and-background {
        background-color: red;
        height: 100%;
        width: 100%;
    }

</style>
<div id="container">
    <div id="header">
    </div>
    <div class="body-parent">
        <div id="body">
            <div id="main-content-container">
                <div class="inset-boxshadow-and-background">
                    <!-- Body start -->
                    <p>In this demo the footer is pushed to the bottom of the screen in all standards compliant web browsers even when there is only a small amount of content on the page. This with work with IE 6 and IE 5.5 too. Non-standards compliant browsers degrade gracefully by positioning the footer under the content as per normal. Read the <a href="https://matthewjamestaylor.com/bottom-footer">full article</a> for all the details.</p>
                    <!-- Body end -->
                </div>
            </div>
        </div>
    </div>
    <div id="footer">
    </div>
</div>

Результат как показано ниже: enter image description here

0 голосов
/ 27 сентября 2018

Этот странный только для IE7 (IE6 и IE8 + отображаются нормально) можно исправить, напрямую изменив любой абсолютно позиционированный div с отрицательным полем и положительным заполнением тех же цифр.

Вот JS:

window.onload = function(){
  $('body').height( $(window).height() - 100 );
};
p {
  margin-top: 0;
  margin-bottom: 0;
}

* {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
} 

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}
#container {
  min-height: 100%;
  position: relative;
}
#header {
  background: yellow;
  height:50px;
}
#body {
  padding-bottom: 50px; /* Height of the footer */
}
#footer {
  position: absolute;
  bottom: 0;
  width: 100%;
  height: 50px;         /* Height of the footer */
  background: green;
}

#body {
  height: 100%;
  width: 100%;
  position: absolute;
  margin-top: -50px;
  padding-top: 50px;
}
#main-content-container {
  height: 100%;
}
.inset-boxshadow-and-background {
  background-color: red;
  height: 100%;
  width: 100%;
}
</style>

<!--[if lt IE 7]>
<style media="screen" type="text/css">
#container {
  height: 100%;
}
</style>
<![endif]-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<body>

<div id="container">
  <div id="header">

  </div>

    <div class="body-parent">
      <div id="body">
        <div id="main-content-container">
          <div class="inset-boxshadow-and-background">
          <!-- Body start -->
          <p>In this demo the footer is pushed to the bottom of the screen in all standards compliant web browsers even when there is only a small amount of content on the page. This with work with IE 6 and IE 5.5 too. Just remove the javascript to make it work in every browser except ie7, and keep the javascript to only run successfully it in IE7.</p>
          <!-- Body end -->
          </div>
        </div>
      </div>
    </div>
  <div id="footer">

  </div>
</div>

</body>
0 голосов
/ 26 сентября 2018

Я провел тест с IE 7, и могу создать проблему.

Когда статическому элементу задается отрицательное поле сверху / слева, он тянет элемент в указанном направлении.

Но если вы примените его внизу / справа, он не сдвинет элемент вниз / вправо, как вы могли бы подумать.Вместо этого он вытягивает любой последующий элемент в основной элемент, перекрывая его.

Так что по этой причине я думаю, что ваш нижний колонтитул вытянут на 50 пикселей в верхнем направлении.Вполне возможно, что именно так IE 7 работает с отрицательным полем.

Вы можете попытаться удалить его, чтобы решить эту проблему.

Ссылка:

Полное руководство по использованию отрицательных полей

...