【问题标题】:How to have a background extend indefinitely in the x direction如何让背景在 x 方向上无限延伸
【发布时间】:2017-06-26 16:28:47
【问题描述】:

我现在有一个灰色背景的标题,宽度为 100%,最大宽度为 1000 像素。我有一个单独的 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;
}

【问题讨论】:

  • 请提供代码。理想情况下是带有相关 html 和 css 的 sn-p
  • @mikepa88 代码已添加。如果这还不够,我可以添加更多代码,但我相信这就是页脚的所有内容,这就是问题所在。
  • 如果我取出&lt;body&gt; 标签,我看不出该代码有问题。这实际上是您的代码的样子吗?#footerBG&lt;body&gt; 标记之外?如果是这样,请不要这样做;把它移进去,看看它是否有效。如果没有,那么看看您是否可以提供一个堆栈 sn-p 来重现该问题,因为必须存在其他问题。
  • @cjl750 我的代码实际上就是这样。将它带入正文的问题是 width 100% 属性使其仅与正文一样宽,最大为 1000 像素。我希望它始终是屏幕的全宽。

标签: html css background repeat


【解决方案1】:

好的,所以,用你的小提琴,我们可以看到问题不在于背景颜色没有拉伸到页面宽度的 100%,而是你的页脚中的元素加起来超过100%!因此,让背景颜色真正占据整个页面的唯一方法是 A.) 提供一些真正包含其所有子元素的父元素,并改为提供背景颜色;或者,B.) 将背景颜色设置为大于 100% 的页面宽度(或至少超出页面的右边界)。

下面的第一个选项适用于方法 A;第二种选择基于方法 B;第三种选择只是奖励积分。 确保调整它们的屏幕大小,看看它们在宽屏和窄屏上的比较。

首先,这是我们的问题样式:

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

此外,除了&lt;head&gt; 之外,您不应包含&lt;body&gt; 标记之外的任何元素。那不是有效的 HTML。但在这种情况下,我们实际上并不需要&lt;div id="footerTopBG"&gt;&lt;div id="footerBG"&gt;,所以我在下面的示例中简单地将它们注释掉(除了删除您拥有的bodyhtml 标签,这些标签在小提琴或堆栈中的sn-p)。

选项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;
}

就是这样。就像在选项一中一样,伪元素的精确宽度将取决于您使用的字体和字体大小、其他元素的宽度和边距/填充,以及其他一切。

要完成这项工作,我们必须做的其他事情是清除#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 */
  }
}

请注意,您可能可以删除其他样式以进一步简化事情,这些不是我在下面的 sn-p 中注释掉的唯一样式,但这应该说明这个概念。

结果仍然有点难看,到处都是随机的子弹等等,但我认为你会在你的实际网站上纠正这些问题。

由于我在这篇文章中的字符用完了,here's a fiddle link 供您查看。

【讨论】:

  • 选项二看起来最适合我。我仍然遇到的一个问题是,使用此选项(以及选项一),背景颜色仍被包含在 900 像素的限制内。我不希望我的内容宽于 1000 像素,但我希望颜色超出此范围。
  • 尝试稍微调整一下定位。您可以将left: 0 更改为right: ?? 并填写问号。请记住,您可能还必须针对特定情况调整宽度。我建议检查浏览器控制台中的元素(在 Chrome 中,右键单击 > 检查),然后更改其中的宽度和位置,以确定哪些数字是完全正确的。然后,更新您的 CSS 文件。
  • 在搞砸之后,我能够让它超过 1000 像素。不过,这现在引起了一个不同的问题,为了让它仍然显示背景,我必须按照你所说的将宽度扩展到 100% 以上。如果我这样做,那么网站会将其视为内容,即使那里只有灰色,也会让我向右滚动。这是唯一剩下的问题。
  • 是的,这就是我一开始没有完全理解的整个部分。理想情况下,该站点无论如何都不会横向滚动。但是,如果您不想采用完全响应式路线来解决该问题,那么我建议您只需找到可以制作伪元素的最小数量,同时仍然覆盖所有内容,然后继续。如果适用,您还可以使用媒体查询仅在较小的屏幕尺寸上添加伪元素(从而导致滚动)。或者在大屏幕上使用body { overflow-x: hidden }至少可以去掉桌面上的滚动条。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-01
  • 1970-01-01
相关资源
最近更新 更多