如何使背景无限地沿X方向扩展



我现在有一个标头,其灰色背景的宽度为100%,最大宽度为1000px。我有一个单独的DIV,在实际的标头div后面具有绝对位置,该部门当前是灰色背景,因此灰色可以超过1000px的限制。我希望这种灰色背景扩展到屏幕上的大小,目前正在这样做,但是我遇到的问题是,如果用户必须在所有灰色背景上滚动,则宽度为100%浏览器,所以我在其他地方留下了白色背景。我可以做什么,即使水平滚动也是屏幕的完整宽度?

这是一个jsfiddle:https://jsfiddle.net/mb1brnma/1/

小提琴中的内容有点混乱,但是它确实代表了问题,如果您向右滚动,则背景不会完全扩展到右边。

编辑:

html:

    <div id="footerTopBG"></div>
    <div id="footerBG"></div>
<body>
<div id="footer-container">
    <div id="footer-holder">
        <footer>  
            <section id="mid">
                <div align=left class="box">
                    <h5>Customer Care</h5>
                    <ul>
                        <li><a href="/pages/Return-Policy.html">Return Policy</a></li>
                        <li><a href="/free-shipping.html">Free Shipping*</a></li>
                        <li><a href="/pages/Terms-And-Conditions.html">Terms &amp; Conditions</a></li>
                        <li><a href="/pages/Privacy-Statement.html">Privacy Statement</a></li>
                        <li><a href="/pages/FCC-Wireless-Alert.html">FCC Wireless Alert</a></li>
                    </ul>
</div>
                <div align=left class="box">
                        <h5>More About NLFX</h5>
                        <ul>
                            <li><a href="/pages/About-us.html">About Us</a></li>
                            <li><a href="http://gobos.nlfxpro.com">NLFX Pro Custom Gobo</a></li>
                            <li><a href="/pages/Installations.html">Installations</a></li>
                            <li><a href="/pages/Blog.html">Blog</a></li>
                        </ul>
</div>
                <div align=left class="box">
                      <FM>
                        <h5>Follow NLFX</h5>
                        <ul id="A">
                            <li class="one"><a href="https://www.facebook.com/nlfxpro/"><i class="fa fa-facebook-square fa-2x" aria-hidden="true"></i></a></li>
                            <li class="two"><a href="https://twitter.com/NLfxPro?ref_src=twsrc%5Etfw"><i class="fa fa-twitter-square fa-2x" aria-hidden="true"></i></a></li></ul>
                          <ul id="B">
                            <li class="one"><a href="https://www.youtube.com/user/NLFXProfessional?feature=sub_widget_1"><i class="fa fa-youtube-square fa-2x" aria-hidden="true"></i></a></li>
                            <li class="two"><a href="https://www.instagram.com/nlfxpro/?hl=en"><i class="fa fa-instagram fa-2x" aria-hidden="true"></i></a></li>
                        </ul>
                      </FM>
</div>
                <div align=left class="box">
                      <div id="af-form-2011966506" class="af-form"><div id="af-header-2011966506" class="af-header"><div class="bodyText"><p style="text-align: center;"><span style="font-size: 18px;white-space=nowrap;"><strong style="color: whitesmoke;">Newsletter signup!</strong></span></p></div></div><div id="af-body-2011966506" class="af-body af-standards"><div class="af-element"><div class="af-textWrap"><input id="awf_field-79641788" type="text" name="name" class="text" value="" onfocus=" if (this.value == '') { this.value = ''; }" onblur="if (this.value == '') { this.value='';} " tabindex="500" placeholder="Your Name"></div><div class="af-clear"></div></div><div class="af-element"><div class="af-textWrap"><input class="text" id="awf_field-79641789" type="text" name="email" value="" tabindex="501" onfocus=" if (this.value == '') { this.value = ''; }" onblur="if (this.value == '') { this.value='';} " placeholder="Email Address"></div><div class="af-clear"></div></div><div class="af-element"><div class="af-selectWrap"><select id="awf_field-79641790" name="custom Your Interests" tabindex="502"> <option selected="selected" class="multiChoice" value="">Select an Interest</option><option class="multiChoice" value="Dj">DJ</option><option class="multiChoice" value="House of worship">House of Worship</option><option class="multiChoice" value="Family fun center">Family Fun Center</option><option class="multiChoice" value="Live Production">Live Production</option><option class="multiChoice" value="Performance venue">Performance Venue</option><option class="multiChoice" value="Rental company">Rental Company</option></select></div><input type="hidden" name="meta_preselected_awf_field-79641790" value="---select one---"><div class="af-clear"></div></div><div class="af-element buttonContainer"><input name="submit" class="submit" type="submit" value="     Subscribe to our Newsletter!     " tabindex="503"><div class="af-clear"></div></div></div></div>
</div>
            </section>            
            <section id="bottom">
                <address>
                    <p class="big">NLFX Professional</p>
                    <p>1319 Naylor Drive SE</p>
                    <p>Bemidji, MN 56601</p>
                    <p><a href="https://www.google.com/maps/place/NLFX+Professional/@47.4419595,-94.8508662,17z/data=!3m1!4b1!4m5!3m4!1s0x52b82dc7d2024257:0xd700f2707b61b267!8m2!3d47.4419559!4d-94.8486775" target="_blank">View Map</a></p>
                </address>
                <div class="phone">
                    <p class="big">Contact Us</p>
                    <p>Toll Free: 1-888-660-6696</p>
                    <p>Local: 218-444-2994</p>
                    <p>Email: <a href="mailto:customercare@nlfxpro.com">customercare@nlfxpro.com</a></p>
                </div>
                <div class="hours">
                    <p class="big">Store Hours</p>
                    <p>Monday - Friday</p>
                    <p>8:30am - 5:00pm</p>
                </div>
                <div class="copy">
                    Copyright &copy; 2012 NLFX Professional 
                </div>
            </section>
        </footer>
    </div>
</div>
</body>

CSS:

    footer {
    width: 100%;
    max-width:900px;
    min-width:770px;
    float: left;
    height:310px;
    background: linear-gradient(to bottom, #9b9b9b 61.2%,#414141 61.2%); 
}
footer #mid {
    width: 96%;
    margin: 2%;
    float: left;
    position: relative;
    display: inline;
    max-width:900px;
    min-width:720px;
}
footer #mid .box {
    width: 25%;
    overflow: visible;
    float: left;
}
footer #mid .box h5 {
    overflow: hidden;
    font-size: 18px;
    position: absolute;
    color: white;
    font-weight: bold;
}
footer #mid .box ul {
    width: 170px;
    margin-top: 20px;
    float: left;
    position: relative;
}
footer #mid .box ul li a{
    color: white;
    display: inline-block;
    padding-top: 10px;
}
footer #mid .box FM li a{
    display:inline;
    font-size:23px;
    padding-top:0px !!important;
}
footer #mid .box FM li a:hover{
    font-size: 25px;
}
footer #mid .box FM .one{
    position: absolute;
    text-align: right;
    right:120px
}
footer #mid .box FM .two{
    position: absolute;
    text-align: left;
    left:58px;
}
footer #mid .box FM #B{
    bottom:-30px;
}
footer #mid .box FM #A{
    bottom:-5px;
}
footer #mid .box FM #A li:hover{
    transform: translateY(-5px);
}
footer #mid .box ul li a:hover {
    color: #ccc;
    transform: translate(2%);
}
#af-form-2011966506{
    float: left;
    margin-left: -60px;
    padding:8px;
    overflow: visible;
    border:1px solid white;
}
#awf_field-79641790{
    width:100%;
    text-align: center;
    vertical-align:middle;
    background-color: white;
    border-radius: 2.5px;
}
footer #bottom {
    width: 100%;
    max-width:900px;
    min-width:720px;
    height: auto;
    float: left;
    color: ghostwhite;
    margin: 10px 2%;
    display:inline;
}
footer #bottom address {
    width: 26%;
    margin-right: 50px;
    float: left;
    font-style: normal;
}
footer #bottom .big {
    color: whitesmoke;
    font-family: 'TeXGyreAdventor', sans-serif;
    font-weight: bold;
    font-size: 18px;
}
footer #bottom address a {
    color:deepskyblue;
}
footer #bottom address a:hover {
    color:skyblue;
}
footer #bottom .phone {
    margin: 0;
    width: 30%;
    min-width: 230px;
    float: left;
}
footer #bottom .phone a {
    color: deepskyblue;
}
footer #bottom .phone a:hover {
    color: skyblue;
}
footer #bottom .hours {
    margin-left: 50px;
    float: left;
    width: 26%;
}
footer #bottom .copy {
    width: 100%;
    margin-top: 10px;
    float: left;
    text-align: center;
    font-family: "Trebuchet MS";
    color: whitesmoke;
    font-size: 12px;
}

#footerBG{
    background-color:#414141;
    background-repeat: repeat-x;
    width: 100%;
    min-width:700px;
    position:relative;
    height: 120px;
    z-index: -999999;
}
#footerTopBG{
    background-color:#9b9b9b;
    background-repeat: repeat-x;
    width: 100%;
    min-width:700px;
    position:relative;
    margin-top: -310px;
    height: 190px;
    z-index: -9999;
}

好吧,所以,在您的小提琴中努力,我们可以看到问题不是背景颜色不扩展到页面宽度的100%页脚中的元素总计高达100%!因此,获得背景颜色真正占用整个页面的唯一方法是要么a。或,B。(设置具有背景颜色的任何内容,要大于页面宽度的100%(或至少伸出页面的正确界限(。

下面的第一个选项可在方法a上使用;第二种选择是基于方法B;第三种选择只是奖励积分。确保调整两个屏幕的大小,以查看它们在较宽的屏幕尺寸上的比较。

开始,这是我们的问题风格:

footer {
  min-width: 770px;
}
footer #mid {
  min-width: 720px;
}
footer #bottom {
  min-width: 720px;
}

此外,除了<head>之外,您不应在<body>标签之外包含任何元素。那不是有效的HTML。但是在这种情况下,我们实际上不需要<div id="footerTopBG"><div id="footerBG">,因此我只是在以下示例中对它们进行了评论(除了删除您拥有的bodyhtml标签之外,这是在小提琴中不需要的,或者在堆栈snippet中不需要的(。

选项1:父元素卷轴

第一种方法是在包装元素上设置背景颜色,并确保元素的min-width足够宽以真正包含所有内容。

#footer-container {
  background-color: #9b9b9b;
  min-width: 900px;
  overflow-x: auto;
}

您基本上希望使min-width值尽可能小,以防止在小屏幕上滚动过多。精确值将由您的字体大小和字体面确定,以及子元素的宽度和边距以及其他。

选项一:

footer {
  width: 100%;
  max-width: 900px;
  min-width: 770px;
  float: left;
  height: 310px;
}
footer #mid {
  width: 96%;
  margin: 2%;
  float: left;
  position: relative;
  display: inline;
  max-width: 900px;
  min-width: 720px;
}
footer #mid .box {
  width: 25%;
  overflow: visible;
  float: left;
  width: 25%;
}
footer #mid .box h5 {
  overflow: hidden;
  font-size: 18px;
  /* position: absolute; */
  color: white;
  font-weight: bold;
}
footer #mid .box ul {
  width: 170px;
  margin-top: 20px;
  float: left;
  position: relative;
}
footer #mid .box ul li a {
  color: white;
  display: inline-block;
  padding-top: 10px;
}
footer #mid .box FM li a {
  display: inline;
  font-size: 23px;
  padding-top: 0px !important;
}
footer #mid .box FM li a:hover {
  font-size: 25px;
}
footer #mid .box FM .one {
  position: absolute;
  text-align: right;
  right: 120px
}
/* footer #mid .box FM .two {
  position: absolute;
  text-align: left;
  left: 58px;
} */
footer #mid .box FM #B {
  bottom: -30px;
}
footer #mid .box FM #A {
  bottom: -5px;
}
footer #mid .box FM #A li:hover {
  transform: translateY(-5px);
}
footer #mid .box ul li a:hover {
  color: #ccc;
  transform: translate(2%);
}
#af-form-2011966506 {
  float: left;
  margin-left: -60px;
  padding: 8px;
  /* overflow: visible; */
  border: 1px solid white;
}
#awf_field-79641790 {
  width: 100%;
  text-align: center;
  vertical-align: middle;
  background-color: white;
  border-radius: 2.5px;
}
footer #bottom {
  width: 100%;
  max-width: 900px;
  min-width: 720px;
  height: auto;
  float: left;
  color: ghostwhite;
  margin: 10px 2%;
  display: inline;
}
footer #bottom address {
  width: 26%;
  margin-right: 50px;
  float: left;
  font-style: normal;
}
footer #bottom .big {
  color: whitesmoke;
  font-family: 'TeXGyreAdventor', sans-serif;
  font-weight: bold;
  font-size: 18px;
}
footer #bottom address a {
  color: deepskyblue;
}
footer #bottom address a:hover {
  color: skyblue;
}
footer #bottom .phone {
  margin: 0;
  width: 30%;
  min-width: 230px;
  float: left;
}
footer #bottom .phone a {
  color: deepskyblue;
}
footer #bottom .phone a:hover {
  color: skyblue;
}
footer #bottom .hours {
  margin-left: 50px;
  float: left;
  width: 26%;
}
footer #bottom .copy {
  width: 100%;
  margin-top: 10px;
  float: left;
  text-align: center;
  font-family: "Trebuchet MS";
  color: whitesmoke;
  font-size: 12px;
}
/* NEW */
body {
  margin: 0;
}
#footer-container {
  background-color: #9b9b9b;
  min-width: 900px;
  overflow-x: auto;
}
<!-- <div id="footerTopBG"></div>
<div id="footerBG"></div> -->
<div id="footer-container">
  <div id="footer-holder">
    <footer>
      <section id="mid">
        <div align=left class="box">
          <h5>Customer Care</h5>
          <ul>
            <li><a href="/pages/Return-Policy.html">Return Policy</a></li>
            <li><a href="/free-shipping.html">Free Shipping*</a></li>
            <li><a href="/pages/Terms-And-Conditions.html">Terms &amp; Conditions</a></li>
            <li><a href="/pages/Privacy-Statement.html">Privacy Statement</a></li>
            <li><a href="/pages/FCC-Wireless-Alert.html">FCC Wireless Alert</a></li>
          </ul>
        </div>
        <div align=left class="box">
          <h5>More About NLFX</h5>
          <ul>
            <li><a href="/pages/About-us.html">About Us</a></li>
            <li><a href="http://gobos.nlfxpro.com">NLFX Pro Custom Gobo</a></li>
            <li><a href="/pages/Installations.html">Installations</a></li>
            <li><a href="/pages/Blog.html">Blog</a></li>
          </ul>
        </div>
        <div align=left class="box">
          <FM>
            <h5>Follow NLFX</h5>
            <ul id="A">
              <li class="one"><a href="https://www.facebook.com/nlfxpro/"><i class="fa fa-facebook-square fa-2x" aria-hidden="true"></i></a></li>
              <li class="two"><a href="https://twitter.com/NLfxPro?ref_src=twsrc%5Etfw"><i class="fa fa-twitter-square fa-2x" aria-hidden="true"></i></a></li>
            </ul>
            <ul id="B">
              <li class="one"><a href="https://www.youtube.com/user/NLFXProfessional?feature=sub_widget_1"><i class="fa fa-youtube-square fa-2x" aria-hidden="true"></i></a></li>
              <li class="two"><a href="https://www.instagram.com/nlfxpro/?hl=en"><i class="fa fa-instagram fa-2x" aria-hidden="true"></i></a></li>
            </ul>
          </FM>
        </div>
        <div align=left class="box">
          <div id="af-form-2011966506" class="af-form">
            <div id="af-header-2011966506" class="af-header">
              <div class="bodyText">
                <p style="text-align: center;"><span style="font-size: 18px;white-space=nowrap;"><strong style="color: whitesmoke;">Newsletter signup!</strong></span></p>
              </div>
            </div>
            <div id="af-body-2011966506" class="af-body af-standards">
              <div class="af-element">
                <div class="af-textWrap">
                  <input id="awf_field-79641788" type="text" name="name" class="text" value="" onfocus=" if (this.value == '') { this.value = ''; }" onblur="if (this.value == '') { this.value='';} " tabindex="500" placeholder="Your Name">
                </div>
                <div class="af-clear"></div>
              </div>
              <div class="af-element">
                <div class="af-textWrap">
                  <input class="text" id="awf_field-79641789" type="text" name="email" value="" tabindex="501" onfocus=" if (this.value == '') { this.value = ''; }" onblur="if (this.value == '') { this.value='';} " placeholder="Email Address">
                </div>
                <div class="af-clear"></div>
              </div>
              <div class="af-element">
                <div class="af-selectWrap">
                  <select id="awf_field-79641790" name="custom Your Interests" tabindex="502">
                    <option selected="selected" class="multiChoice" value="">Select an Interest</option>
                    <option class="multiChoice" value="Dj">DJ</option>
                    <option class="multiChoice" value="House of worship">House of Worship</option>
                    <option class="multiChoice" value="Family fun center">Family Fun Center</option>
                    <option class="multiChoice" value="Live Production">Live Production</option>
                    <option class="multiChoice" value="Performance venue">Performance Venue</option>
                    <option class="multiChoice" value="Rental company">Rental Company</option>
                  </select>
                </div>
                <input type="hidden" name="meta_preselected_awf_field-79641790" value="---select one---">
                <div class="af-clear"></div>
              </div>
              <div class="af-element buttonContainer">
                <input name="submit" class="submit" type="submit" value="     Subscribe to our Newsletter!     " tabindex="503">
                <div class="af-clear"></div>
              </div>
            </div>
          </div>
        </div>
      </section>
      <section id="bottom">
        <address>
                    <p class="big">NLFX Professional</p>
                    <p>1319 Naylor Drive SE</p>
                    <p>Bemidji, MN 56601</p>
                    <p><a href="https://www.google.com/maps/place/NLFX+Professional/@47.4419595,-94.8508662,17z/data=!3m1!4b1!4m5!3m4!1s0x52b82dc7d2024257:0xd700f2707b61b267!8m2!3d47.4419559!4d-94.8486775" target="_blank">View Map</a></p>
                </address>
        <div class="phone">
          <p class="big">Contact Us</p>
          <p>Toll Free: 1-888-660-6696</p>
          <p>Local: 218-444-2994</p>
          <p>Email: <a href="mailto:customercare@nlfxpro.com">customercare@nlfxpro.com</a></p>
        </div>
        <div class="hours">
          <p class="big">Store Hours</p>
          <p>Monday - Friday</p>
          <p>8:30am - 5:00pm</p>
        </div>
        <div class="copy">
          Copyright &copy; 2012 NLFX Professional
        </div>
      </section>
    </footer>
  </div>
</div>

选项2:伪元素

我们可以解决问题的第二种方法是找到内容的实际宽度,并制作一个伪元素,以坐在页脚后面,向右延伸,经过典型的权利,因此背景基本上是超过100%宽。

如果将伪元素添加到最大的容器中,这将是最简单的,因此我将其添加到#footer-container中。

#footer-container {
  background-color: #9b9b9b;
}
#footer-container::after {
  content: '';
  display: block;
  background-color: #9b9b9b;
  width: 793px;
  height: 492px;
  position: absolute;
  top: 0;
  left: 0;
  z-index: -1;
}

就是这样。就像选项One一样,伪元素的精确宽度将取决于您所使用的字体和字体大小,其他元素的宽度和边距/填充物以及其他所有内容。

我们要做的其他事情是要清除fearfix #footer-holder,以便它足够高以包含所有孩子,然后删除footer的明确高度。

选项两个:

footer {
  width: 100%;
  max-width: 900px;
  min-width: 770px;
  float: left;
  /* height: 310px; */
}
footer #mid {
  width: 96%;
  margin: 2%;
  float: left;
  position: relative;
  display: inline;
  max-width: 900px;
  min-width: 720px;
}
footer #mid .box {
  width: 25%;
  overflow: visible;
  float: left;
  width: 25%;
}
footer #mid .box h5 {
  overflow: hidden;
  font-size: 18px;
  /* position: absolute; */
  color: white;
  font-weight: bold;
}
footer #mid .box ul {
  width: 170px;
  margin-top: 20px;
  float: left;
  position: relative;
}
footer #mid .box ul li a {
  color: white;
  display: inline-block;
  padding-top: 10px;
}
footer #mid .box FM li a {
  display: inline;
  font-size: 23px;
  padding-top: 0px !important;
}
footer #mid .box FM li a:hover {
  font-size: 25px;
}
footer #mid .box FM .one {
  position: absolute;
  text-align: right;
  right: 120px
}
footer #mid .box FM .two {
  position: absolute;
  text-align: left;
  left: 58px;
}
footer #mid .box FM #B {
  bottom: -30px;
}
footer #mid .box FM #A {
  bottom: -5px;
}
footer #mid .box FM #A li:hover {
  transform: translateY(-5px);
}
footer #mid .box ul li a:hover {
  color: #ccc;
  transform: translate(2%);
}
#af-form-2011966506 {
  float: left;
  margin-left: -60px;
  padding: 8px;
  overflow: visible;
  border: 1px solid white;
}
#awf_field-79641790 {
  width: 100%;
  text-align: center;
  vertical-align: middle;
  background-color: white;
  border-radius: 2.5px;
}
footer #bottom {
  width: 100%;
  max-width: 900px;
  min-width: 720px;
  height: auto;
  float: left;
  color: ghostwhite;
  margin: 10px 2%;
  display: inline;
}
footer #bottom address {
  width: 26%;
  margin-right: 50px;
  float: left;
  font-style: normal;
}
footer #bottom .big {
  color: whitesmoke;
  font-family: 'TeXGyreAdventor', sans-serif;
  font-weight: bold;
  font-size: 18px;
}
footer #bottom address a {
  color: deepskyblue;
}
footer #bottom address a:hover {
  color: skyblue;
}
footer #bottom .phone {
  margin: 0;
  width: 30%;
  min-width: 230px;
  float: left;
}
footer #bottom .phone a {
  color: deepskyblue;
}
footer #bottom .phone a:hover {
  color: skyblue;
}
footer #bottom .hours {
  margin-left: 50px;
  float: left;
  width: 26%;
}
footer #bottom .copy {
  width: 100%;
  margin-top: 10px;
  float: left;
  text-align: center;
  font-family: "Trebuchet MS";
  color: whitesmoke;
  font-size: 12px;
}
/* NEW */
body {
  margin: 0;
}
#footer-container {
  background-color: #9b9b9b;
}
#footer-container::after {
  content: '';
  display: block;
  background-color: #9b9b9b;
  width: 793px;
  height: 492px;
  position: absolute;
  top: 0;
  left: 0;
  z-index: -1;
}
.clearfix::after {
  content: '';
  display: table;
  clear: both;
}
<!-- <div id="footerTopBG"></div>
<div id="footerBG"></div> -->
<div id="footer-container">
  <div id="footer-holder" class="clearfix">
    <footer>
      <section id="mid">
        <div align=left class="box">
          <h5>Customer Care</h5>
          <ul>
            <li><a href="/pages/Return-Policy.html">Return Policy</a></li>
            <li><a href="/free-shipping.html">Free Shipping*</a></li>
            <li><a href="/pages/Terms-And-Conditions.html">Terms &amp; Conditions</a></li>
            <li><a href="/pages/Privacy-Statement.html">Privacy Statement</a></li>
            <li><a href="/pages/FCC-Wireless-Alert.html">FCC Wireless Alert</a></li>
          </ul>
        </div>
        <div align=left class="box">
          <h5>More About NLFX</h5>
          <ul>
            <li><a href="/pages/About-us.html">About Us</a></li>
            <li><a href="http://gobos.nlfxpro.com">NLFX Pro Custom Gobo</a></li>
            <li><a href="/pages/Installations.html">Installations</a></li>
            <li><a href="/pages/Blog.html">Blog</a></li>
          </ul>
        </div>
        <div align=left class="box">
          <FM>
            <h5>Follow NLFX</h5>
            <ul id="A">
              <li class="one"><a href="https://www.facebook.com/nlfxpro/"><i class="fa fa-facebook-square fa-2x" aria-hidden="true"></i></a></li>
              <li class="two"><a href="https://twitter.com/NLfxPro?ref_src=twsrc%5Etfw"><i class="fa fa-twitter-square fa-2x" aria-hidden="true"></i></a></li>
            </ul>
            <ul id="B">
              <li class="one"><a href="https://www.youtube.com/user/NLFXProfessional?feature=sub_widget_1"><i class="fa fa-youtube-square fa-2x" aria-hidden="true"></i></a></li>
              <li class="two"><a href="https://www.instagram.com/nlfxpro/?hl=en"><i class="fa fa-instagram fa-2x" aria-hidden="true"></i></a></li>
            </ul>
          </FM>
        </div>
        <div align=left class="box">
          <div id="af-form-2011966506" class="af-form">
            <div id="af-header-2011966506" class="af-header">
              <div class="bodyText">
                <p style="text-align: center;"><span style="font-size: 18px;white-space=nowrap;"><strong style="color: whitesmoke;">Newsletter signup!</strong></span></p>
              </div>
            </div>
            <div id="af-body-2011966506" class="af-body af-standards">
              <div class="af-element">
                <div class="af-textWrap">
                  <input id="awf_field-79641788" type="text" name="name" class="text" value="" onfocus=" if (this.value == '') { this.value = ''; }" onblur="if (this.value == '') { this.value='';} " tabindex="500" placeholder="Your Name">
                </div>
                <div class="af-clear"></div>
              </div>
              <div class="af-element">
                <div class="af-textWrap">
                  <input class="text" id="awf_field-79641789" type="text" name="email" value="" tabindex="501" onfocus=" if (this.value == '') { this.value = ''; }" onblur="if (this.value == '') { this.value='';} " placeholder="Email Address">
                </div>
                <div class="af-clear"></div>
              </div>
              <div class="af-element">
                <div class="af-selectWrap">
                  <select id="awf_field-79641790" name="custom Your Interests" tabindex="502">
                    <option selected="selected" class="multiChoice" value="">Select an Interest</option>
                    <option class="multiChoice" value="Dj">DJ</option>
                    <option class="multiChoice" value="House of worship">House of Worship</option>
                    <option class="multiChoice" value="Family fun center">Family Fun Center</option>
                    <option class="multiChoice" value="Live Production">Live Production</option>
                    <option class="multiChoice" value="Performance venue">Performance Venue</option>
                    <option class="multiChoice" value="Rental company">Rental Company</option>
                  </select>
                </div>
                <input type="hidden" name="meta_preselected_awf_field-79641790" value="---select one---">
                <div class="af-clear"></div>
              </div>
              <div class="af-element buttonContainer">
                <input name="submit" class="submit" type="submit" value="     Subscribe to our Newsletter!     " tabindex="503">
                <div class="af-clear"></div>
              </div>
            </div>
          </div>
        </div>
      </section>
      <section id="bottom">
        <address>
                    <p class="big">NLFX Professional</p>
                    <p>1319 Naylor Drive SE</p>
                    <p>Bemidji, MN 56601</p>
                    <p><a href="https://www.google.com/maps/place/NLFX+Professional/@47.4419595,-94.8508662,17z/data=!3m1!4b1!4m5!3m4!1s0x52b82dc7d2024257:0xd700f2707b61b267!8m2!3d47.4419559!4d-94.8486775" target="_blank">View Map</a></p>
                </address>
        <div class="phone">
          <p class="big">Contact Us</p>
          <p>Toll Free: 1-888-660-6696</p>
          <p>Local: 218-444-2994</p>
          <p>Email: <a href="mailto:customercare@nlfxpro.com">customercare@nlfxpro.com</a></p>
        </div>
        <div class="hours">
          <p class="big">Store Hours</p>
          <p>Monday - Friday</p>
          <p>8:30am - 5:00pm</p>
        </div>
        <div class="copy">
          Copyright &copy; 2012 NLFX Professional
        </div>
      </section>
    </footer>
  </div>
</div>

选项3:响应式设计

正如我所看到的,症状是您的背景颜色不会一直向右扩展,但是基本的问题是页脚是't响应迅速 - 它不适合浏览器窗口。

要解决此问题,您必须基本上调整样式,以摆脱许多最小宽度,并删除许多不必要的定位和溢出规则,以便在小空间中一切正常流动。然后,您只给页脚颜色,您就可以了,因为您不需要向右滚动。

我会把它留给您,以决定这是否真的是您想做的,但认为我会选择它。

这种方法基本上等于删除与定位和溢出相关的许多样式,然后添加媒体查询以调整某些样式。这是要点:

footer {
  width: 100%;
  max-width: 900px;
  /* min-width: 770px; */
  /* float: left; */
  /* height: 310px; */
}
footer #mid {
  width: 96%;
  margin: 2%;
  max-width: 900px;
  /* float: left; */
  /* position: relative; */
  /* display: inline; */
  /* min-width: 720px; */
}
footer #mid .box {
  /* width: 25%; */
  /* overflow: visible; */
  float: left;
  width: 25%;
}
#footer-container {
  background-color: #9b9b9b;
}
@media all and (max-width: 620px) {
  footer #mid .box:nth-child(odd) {
    clear: left;
  }  
  footer #mid .box {
    width: 48%; /* 96% width of #mid, divided by 2 */
  }
}

请注意,您可能还可以删除其他样式来进一步简化事物,而这些并不是我在下面的摘要中评论的唯一样式,但这应该说明该概念。

结果仍然有些丑陋,随机子弹在周围浮动,但我认为您会在实际网站上纠正这些问题。

由于我在这篇文章上没有字符,这是一个小提琴链接,供您查看。

最新更新