2017-10-05 66 views
-1

在這裏,我想修復頁面下方的頁腳。我似乎無法完成此頁面,而footer的css代碼在其他頁面上運行良好。再次,我想將頁腳固定在頁面的下方。頁腳不固定在頁面下方

需要幫助。

(function() { 
 
    function onSubmitClicked(event) { 
 

 
    var product = document.getElementById('product'), 
 
     productVal = product.value, 
 
     profile = document.getElementById('profile'), 
 
     profileVal = profile.value; 
 
    url = 'testPoint.html?product=' + encodeURIComponent(productVal) + '&profile=' + encodeURIComponent(profileVal); 
 
    location.href = url; 
 
    } 
 

 
    var submitButton = document.getElementById('btngo'); 
 
    submitButton.addEventListener('click', onSubmitClicked); 
 
})();
body { 
 
    background-color: #d62929; 
 
    margin: 0; 
 
} 
 

 
ul { 
 
    list-style-type: none; 
 
    margin: 0; 
 
    padding: 0; 
 
    overflow: hidden; 
 
    background-color: whitesmoke; 
 
    font-weight: bold; 
 
    font-size: 18px; 
 
} 
 

 
li { 
 
    float: left; 
 
} 
 

 
li a, 
 
.dropbtn { 
 
    display: inline-block; 
 
    color: black; 
 
    text-align: center; 
 
    padding: 22px 30px; 
 
    text-decoration: none; 
 
} 
 

 
li a:hover, 
 
.dropdown:hover .dropbtn { 
 
    background-color: #c12525; 
 
    color: white; 
 
} 
 

 
li.dropdown { 
 
    display: inline-block; 
 
} 
 

 
.dropdown-content { 
 
    display: none; 
 
    position: absolute; 
 
    background-color: whitesmoke; 
 
    min-width: 250px; 
 
    box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2); 
 
    z-index: 1; 
 
} 
 

 
.dropdown-content a { 
 
    color: black; 
 
    padding: 20px 20px; 
 
    text-decoration: none; 
 
    display: block; 
 
    text-align: left; 
 
    font-size: 15px; 
 
} 
 

 
.dropdown-content a:hover { 
 
    background-color: #c12525; 
 
} 
 

 
.dropdown:hover .dropdown-content { 
 
    display: block; 
 
} 
 

 
.active { 
 
    background-color: #d62929; 
 
    color: white; 
 
    font-weight: bold; 
 
    font-size: 18px; 
 
} 
 

 
@media screen and (max-width: 600px) { 
 
    ul li, 
 
    ul li { 
 
    float: none; 
 
    } 
 
} 
 

 
@media screen and (max-width: 300px) { 
 
    footer { 
 
    -webkit-order: 3; 
 
    order: 3; 
 
    } 
 
} 
 

 
h1 { 
 
    font-size: 40px; 
 
    font-weight: bold; 
 
} 
 

 
h2 { 
 
    font-size: 20px; 
 
    font-weight: bold; 
 
} 
 

 
p2 { 
 
    font-size: 15px; 
 
    font-weight: bold; 
 
} 
 

 
tr, 
 
td { 
 
    padding: 15px; 
 
    text-align: left; 
 
} 
 

 
table { 
 
    margin: auto; 
 
    border-collapse: collapse; 
 
    width: 30%; 
 
    table-layout: fixed; 
 
    text-align: center; 
 
} 
 

 
tr { 
 
    height: 200px; 
 
    vertical-align: middle; 
 
    text-align: left; 
 
} 
 

 
.button { 
 
    background-color: #4CAF50; 
 
    border: none; 
 
    color: white; 
 
    padding: 16px 32px; 
 
    text-align: center; 
 
    text-decoration: none; 
 
    display: inline-block; 
 
    font-size: 16px; 
 
    margin: 4px 2px; 
 
    transition-duration: 0.4s; 
 
    cursor: pointer; 
 
} 
 

 
.button2 { 
 
    background-color: white; 
 
    color: black; 
 
    border: 2px solid black; 
 
    width: 8%; 
 
} 
 

 
.button2:hover { 
 
    background-color: black; 
 
    color: white; 
 
} 
 

 
.button3 { 
 
    background-color: white; 
 
    color: black; 
 
    border: 2px solid black; 
 
    width: 8%; 
 
} 
 

 
.button3:hover { 
 
    background-color: black; 
 
    color: white; 
 
} 
 

 
.rfloat { 
 
    margin: 5px; 
 
    text-align: center; 
 
} 
 

 
.clear { 
 
    clear: both 
 
} 
 

 
footer { 
 
    background: #aaa; 
 
    color: #fff; 
 
    text-align: center; 
 
    padding: 1rem; 
 
    clear: both; 
 
    /* clearing floating affects from both left,right sides */ 
 
} 
 

 
.footp { 
 
    margin: 0; 
 
    padding: 0; 
 
    margin-left: 20px; 
 
    display: inline-block; 
 
    line-height: 30px; 
 
    vertical-align: top; 
 
}
<ul> 
 
    <li><a href="home.html">Home</a></li> 
 
    <li class="dropdown"> 
 
    <a class="active dropbtn" href="javascript:void(0)">Capacity Study</a> 
 
    <div class="dropdown-content"> 
 
     <a href="mainFrame.html">Conduct Study</a> 
 
     <a href="report.html">Reports</a> 
 
    </div> 
 
    </li> 
 
    <li><a href="contact.html">Contact</a></li> 
 
</ul> 
 
<div class="txt"> 
 
    <table> 
 
    <tr> 
 
     <td> 
 
     <p2>Choose a Product : </p2> 
 

 
     <select id="product"> 
 
\t 
 
\t <!--Setting the 'NONE' value for the drop down menu list option when user do not want to choose any value. optgroup is used for the subtitles off the main product dept.--> 
 
\t <optgroup label="DEFAULT"> 
 
\t <option value = "NONE">NONE</option> 
 
\t </optgroup> 
 
\t 
 
\t <!--Product List for PCR Legacy--> 
 
\t <br><br> 
 
\t <!--End of first drop down list--> 
 
\t </select> 
 
     <br><br> 
 

 
     <p2>Choose a Profile : </p2> 
 
     <select id="profile"> 
 
\t 
 
\t <optgroup label="DEFAULT"> 
 
\t <option value = "NONE">NONE</option> 
 
\t </optgroup> 
 
\t </select> 
 
     </td> 
 
    </tr> 
 
    </table> 
 
    <br><br><br> 
 

 
    <div class="rfloat"> 
 
    <input type="button" value="Back" onclick="goBack()" class="button button3" /> 
 
    <input type="submit" id="btngo" value="Go" class="button button2" /> 
 
    </div> 
 

 
    <div class="clear"></div> 
 
    <br><br><br> 
 
</div> 
 

 
<div> 
 
    <footer> 
 
    <p class="footp">&copy;All rights reserved.</p> 
 
    <p class="footp">|</p> 
 
    <p class="footp">Internal Use Only</p> 
 
    <p class="footp">|</p> 
 
    <p class="footp">Maintained By</p> 
 
    </footer> 
 
</div>

+0

所以,你想解決您的頁面底部的頁腳的答案嗎?如果是這樣,只需添加CSS位置:固定;底部:0; – zhuravlyov

+0

感謝您的反饋。不,我不希望它是固定的 - 當我向下滾動頁面時,可以看到頁腳。我不希望用戶在頁面上下滾動時看到頁腳,我只想將頁腳放置在頁面下方。 – cerberus99

+0

@ cerberus99檢查了這我已經更新了答案,以及https://jsfiddle.net/2h6j11kL/ –

回答

1

查看下面的代碼片段。只有當內容不夠高時,這會強制頁腳位於頁面的底部。

Staale @ How do you get the footer to stay at the bottom of a Web page?

(function() { 
 
    function onSubmitClicked(event) { 
 

 
    var product = document.getElementById('product'), 
 
     productVal = product.value, 
 
     profile = document.getElementById('profile'), 
 
     profileVal = profile.value; 
 
    url = 'testPoint.html?product=' + encodeURIComponent(productVal) + '&profile=' + encodeURIComponent(profileVal); 
 
    location.href = url; 
 
    } 
 

 
    var submitButton = document.getElementById('btngo'); 
 
    submitButton.addEventListener('click', onSubmitClicked); 
 
})();
/* --- This below --- */ 
 
* { 
 
    margin: 0; 
 
} 
 

 
html, 
 
body { 
 
    height: 100%; 
 
} 
 

 
.wrapper { 
 
    min-height: 100%; 
 
    height: auto !important; 
 
    height: 100%; 
 
    margin: 0 auto -62px; 
 
    /* the bottom margin is the negative value of the footer's height */ 
 
} 
 

 
.push { 
 
    height: 62px; 
 
    /* .push must be the same height as .footer */ 
 
} 
 

 
/* --- This ahead --- */ 
 

 
body { 
 
    background-color: #d62929; 
 
    margin: 0; 
 
} 
 

 
ul { 
 
    list-style-type: none; 
 
    margin: 0; 
 
    padding: 0; 
 
    overflow: hidden; 
 
    background-color: whitesmoke; 
 
    font-weight: bold; 
 
    font-size: 18px; 
 
} 
 

 
li { 
 
    float: left; 
 
} 
 

 
li a, 
 
.dropbtn { 
 
    display: inline-block; 
 
    color: black; 
 
    text-align: center; 
 
    padding: 22px 30px; 
 
    text-decoration: none; 
 
} 
 

 
li a:hover, 
 
.dropdown:hover .dropbtn { 
 
    background-color: #c12525; 
 
    color: white; 
 
} 
 

 
li.dropdown { 
 
    display: inline-block; 
 
} 
 

 
.dropdown-content { 
 
    display: none; 
 
    position: absolute; 
 
    background-color: whitesmoke; 
 
    min-width: 250px; 
 
    box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2); 
 
    z-index: 1; 
 
} 
 

 
.dropdown-content a { 
 
    color: black; 
 
    padding: 20px 20px; 
 
    text-decoration: none; 
 
    display: block; 
 
    text-align: left; 
 
    font-size: 15px; 
 
} 
 

 
.dropdown-content a:hover { 
 
    background-color: #c12525; 
 
} 
 

 
.dropdown:hover .dropdown-content { 
 
    display: block; 
 
} 
 

 
.active { 
 
    background-color: #d62929; 
 
    color: white; 
 
    font-weight: bold; 
 
    font-size: 18px; 
 
} 
 

 
@media screen and (max-width: 600px) { 
 
    ul li, 
 
    ul li { 
 
    float: none; 
 
    } 
 
} 
 

 
@media screen and (max-width: 300px) { 
 
    footer { 
 
    -webkit-order: 3; 
 
    order: 3; 
 
    } 
 
} 
 

 
h1 { 
 
    font-size: 40px; 
 
    font-weight: bold; 
 
} 
 

 
h2 { 
 
    font-size: 20px; 
 
    font-weight: bold; 
 
} 
 

 
p2 { 
 
    font-size: 15px; 
 
    font-weight: bold; 
 
} 
 

 
tr, 
 
td { 
 
    padding: 15px; 
 
    text-align: left; 
 
} 
 

 
table { 
 
    margin: auto; 
 
    border-collapse: collapse; 
 
    width: 30%; 
 
    table-layout: fixed; 
 
    text-align: center; 
 
} 
 

 
tr { 
 
    height: 200px; 
 
    vertical-align: middle; 
 
    text-align: left; 
 
} 
 

 
.button { 
 
    background-color: #4CAF50; 
 
    border: none; 
 
    color: white; 
 
    padding: 16px 32px; 
 
    text-align: center; 
 
    text-decoration: none; 
 
    display: inline-block; 
 
    font-size: 16px; 
 
    margin: 4px 2px; 
 
    transition-duration: 0.4s; 
 
    cursor: pointer; 
 
} 
 

 
.button2 { 
 
    background-color: white; 
 
    color: black; 
 
    border: 2px solid black; 
 
    width: 8%; 
 
} 
 

 
.button2:hover { 
 
    background-color: black; 
 
    color: white; 
 
} 
 

 
.button3 { 
 
    background-color: white; 
 
    color: black; 
 
    border: 2px solid black; 
 
    width: 8%; 
 
} 
 

 
.button3:hover { 
 
    background-color: black; 
 
    color: white; 
 
} 
 

 
.rfloat { 
 
    margin: 5px; 
 
    text-align: center; 
 
} 
 

 
.clear { 
 
    clear: both 
 
} 
 

 
footer { 
 
    background: #aaa; 
 
    color: #fff; 
 
    text-align: center; 
 
    padding: 1rem; 
 
    clear: both; 
 
    /* clearing floating affects from both left,right sides */ 
 
} 
 

 
.footp { 
 
    margin: 0; 
 
    padding: 0; 
 
    margin-left: 20px; 
 
    display: inline-block; 
 
    line-height: 30px; 
 
    vertical-align: top; 
 
}
<div class="wrapper"> <!-- START: Wrap everything in this div --> 
 
    <ul> 
 
    <li><a href="home.html">Home</a></li> 
 
    <li class="dropdown"> 
 
     <a class="active dropbtn" href="javascript:void(0)">Capacity Study</a> 
 
     <div class="dropdown-content"> 
 
     <a href="mainFrame.html">Conduct Study</a> 
 
     <a href="report.html">Reports</a> 
 
     </div> 
 
    </li> 
 
    <li><a href="contact.html">Contact</a></li> 
 
    </ul> 
 
    <div class="txt"> 
 
    <table> 
 
     <tr> 
 
     <td> 
 
      <p2>Choose a Product : </p2> 
 

 
      <select id="product"> 
 
\t 
 
\t <!--Setting the 'NONE' value for the drop down menu list option when user do not want to choose any value. optgroup is used for the subtitles off the main product dept.--> 
 
\t <optgroup label="DEFAULT"> 
 
\t <option value = "NONE">NONE</option> 
 
\t </optgroup> 
 
\t 
 
\t <!--Product List for PCR Legacy--> 
 
\t <br><br> 
 
\t <!--End of first drop down list--> 
 
\t </select> 
 
      <br><br> 
 

 
      <p2>Choose a Profile : </p2> 
 
      <select id="profile"> 
 
\t 
 
\t <optgroup label="DEFAULT"> 
 
\t <option value = "NONE">NONE</option> 
 
\t </optgroup> 
 
\t </select> 
 
     </td> 
 
     </tr> 
 
    </table> 
 
    <br><br><br> 
 

 
    <div class="rfloat"> 
 
     <input type="button" value="Back" onclick="goBack()" class="button button3" /> 
 
     <input type="submit" id="btngo" value="Go" class="button button2" /> 
 
    </div> 
 

 
    <div class="clear"></div> 
 
    <br><br><br> 
 
    </div> 
 
    <div class="push"></div> <!-- START & END: Push div --> 
 
</div> <!-- END: Wrap everything in this div --> 
 
<div class="footer"> <!-- START: Footer WITH class --> 
 
    <footer> 
 
    <p class="footp">&copy;All rights reserved.</p> 
 
    <p class="footp">|</p> 
 
    <p class="footp">Internal Use Only</p> 
 
    <p class="footp">|</p> 
 
    <p class="footp">Maintained By</p> 
 
    </footer> 
 
</div> <!-- END: Footer WITH class -->

+0

感謝您的反饋。我嘗試了我的代碼並運行代碼。它似乎並沒有工作:( – cerberus99

+0

你是否用'wrapper'封裝了你的內容,'wrapper'裏面有'push div','wrapper div'後面有'footer'?我已經給代碼添加了一些註釋。這對你有幫助 –

+0

這種方法是完美的,所以很抱歉,我想我昨天錯過了一些代碼行,今天再次完成它,它工作的非常好! – cerberus99

-1

請使用以下的CSS,使尾棒在底部:

footer { 
/*it will allow to scroll page while staying at top incase page is long*/ 
    position: fixed; 
    bottom: 0; 
    width: 100%; 
    } 

JSFIDDLE

此外,如果你不希望這種行爲你這樣做總是讓頁腳粘在底部。

footer { 
     position: absolute; 
     bottom: 0; 
     width: 100%; 
     } 
+0

檢查問題隊友下的答案 – zhuravlyov

+0

它出現遲了,但我提供了兩種方法不只是固定的 –

+0

@AamirShahzad嗨埃米爾。感謝您的反饋。我遇到過,當我添加更多功能並傾向於向下滾動頁面時,它似乎不起作用。當我向下滾動時,頁腳似乎也移動了。 Fyi,我採取了你的第二種方法。 – cerberus99