我现在有一个标题,灰色背景宽度为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 & 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 © 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;
}
答案 0 :(得分:0)
好吧,所以,在你的小提琴上工作,我们可以看到问题不是背景颜色不会拉伸到页面宽度的100%,而是页脚中的元素加起来100%!因此,让背景颜色真正占据整个页面的唯一方法是A.)提供一些真正包含其所有子元素的父元素,并赋予背景颜色;或者,B。)设置背景颜色大于页面宽度的100%(或者至少超出页面右边界)的任何内容。
下面的第一个选项适用于方法A;第二种选择是基于方法B;第三种选择只是奖励积分。 确保在两个屏幕上调整屏幕大小以查看它们在宽屏和窄屏尺寸下的比较。
首先,这是我们的问题风格:
footer {
min-width: 770px;
}
footer #mid {
min-width: 720px;
}
footer #bottom {
min-width: 720px;
}
此外,除了<body>
之外,您不应在<head>
标记之外添加任何元素。这不是有效的HTML。但在这种情况下我们实际上并不需要<div id="footerTopBG">
或<div id="footerBG">
,所以我只是在以下示例中对它们进行了评论(除了删除body
和html
标记你有,在小提琴或堆栈片段中没有必要)。
第一种方法是在包装元素上设置背景颜色,并确保元素的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 & 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 © 2012 NLFX Professional
</div>
</section>
</footer>
</div>
</div>
我们可以解决问题的第二种方法是找到你内容的实际宽度,并将一个伪元素放在向右延伸的页脚后面,超过典型的右边界,所以背景基本上是超过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
中删除显式高度。< / p>
选项二:
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 & 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 © 2012 NLFX Professional
</div>
</section>
</footer>
</div>
</div>
正如我所看到的,症状是你的背景颜色不会一直延伸到右边,但底层的问题是页脚没有'响应 - 它不适合浏览器窗口。
要解决这个问题,你必须基本调整你的样式以摆脱许多最小宽度,并删除许多不必要的定位和溢出规则,以便一切只是在一个小空间中正常流动。然后你只需给页脚提供背景颜色,你就可以去了,因为你不需要向右滚动。
我会留给你判断这是否真的是你想要做的,但我想把它作为一种选择。
这种方法基本上相当于删除了许多与定位和溢出相关的样式,然后添加了媒体查询来调整某些样式。这是必需品:
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 */
}
}
请注意,您可以删除其他样式以进一步简化事项,这些不是我在下面的代码段中注释的唯一样式,但这应该说明这个概念。
结果仍然有点难看,随机的子弹漂浮在诸如此类的地方,但我认为你会在你的实际网站上纠正这些问题。
由于我在这篇文章中用完了字符,here's a fiddle link供你查看。