रयान फ़ेट का चिपचिपा पाद बहुत अच्छा है, हालाँकि मुझे इसकी कमी * की मूल संरचना लगती है।
फ्लेक्सबॉक्स संस्करण
यदि आप पर्याप्त भाग्यशाली हैं कि आप पुराने ब्राउज़र का समर्थन करने के लिए बिना फ्लेक्सबॉक्स का उपयोग कर सकते हैं, तो चिपचिपा पाद तुच्छ रूप से आसान हो जाते हैं, और एक गतिशील आकार के पाद का समर्थन करते हैं।
फ्लेक्सबॉक्स के साथ नीचे चिपके रहने के लिए पाद प्राप्त करने की चाल एक ही कंटेनर फ्लेक्स में अन्य तत्वों को लंबवत रूप से रखना है। सभी इसे लेता है एक पूर्ण-ऊंचाई वाले रैपर तत्व display: flexऔर कम से कम एक सहोदर flexसे अधिक मूल्य वाला 0:
सीएसएस:
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
#main-wrapper {
display: flex;
flex-direction: column;
min-height: 100%;
}
article {
flex: 1;
}
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
#main-wrapper {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
min-height: 100%;
}
article {
-webkit-box-flex: 1;
-ms-flex: 1;
flex: 1;
}
header {
background-color: #F00;
}
nav {
background-color: #FF0;
}
article {
background-color: #0F0;
}
footer {
background-color: #00F;
}
<div id="main-wrapper">
<header>
here be header
</header>
<nav>
</nav>
<article>
here be content
</article>
<footer>
here be footer
</footer>
</div>
यदि आप flexbox का उपयोग नहीं कर सकते हैं, तो मेरी पसंद का आधार संरचना है:
<div class="page">
<div class="page__inner">
<header class="header">
<div class="header__inner">
</div>
</header>
<nav class="nav">
<div class="nav__inner">
</div>
</nav>
<main class="wrapper">
<div class="wrapper__inner">
<div class="content">
<div class="content__inner">
</div>
</div>
<div class="sidebar">
<div class="sidebar__inner">
</div>
</div>
</div>
</main>
<footer class="footer">
<div class="footer__inner">
</div>
</footer>
</div>
</div>
जो सब से दूर नहीं है:
<div id="main-wrapper">
<header>
</header>
<nav>
</nav>
<article>
</article>
<footer>
</footer>
</div>
पाद को छड़ी करने के लिए छल करने के लिए पाद को अपने युक्त तत्व के निचले पैडिंग के लिए लंगर डालना है। इसके लिए आवश्यक है कि पाद की ऊंचाई स्थिर हो, लेकिन मैंने पाया है कि पाद आमतौर पर स्थिर ऊँचाई के होते हैं।
HTML:
<div id="main-wrapper">
...
<footer>
</footer>
</div>
सीएसएस:
#main-wrapper {
padding: 0 0 100px;
position: relative;
}
footer {
bottom: 0;
height: 100px;
left: 0;
position: absolute;
width: 100%;
}
#main-wrapper {
padding: 0 0 100px;
position: relative;
}
footer {
bottom: 0;
height: 100px;
left: 0;
position: absolute;
width: 100%;
}
header {
background-color: #F00;
}
nav {
background-color: #FF0;
}
article {
background-color: #0F0;
}
footer {
background-color: #00F;
}
<div id="main-wrapper">
<header>
here be header
</header>
<nav>
</nav>
<article>
here be content
</article>
<footer>
here be footer
</footer>
</div>
पाद लेख के साथ #main-wrapper, आपको अब #main-wrapperपृष्ठ की कम से कम ऊंचाई चाहिए, जब तक कि उसके बच्चे लंबे न हों। यह बनाने के द्वारा किया जाता #main-wrapperएक है min-heightकी 100%। आपको यह भी याद रखना होगा कि इसके माता-पिता, htmlऔर bodyपेज के समान ही लंबा होना चाहिए।
सीएसएस:
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
#main-wrapper {
min-height: 100%;
padding: 0 0 100px;
position: relative;
}
footer {
bottom: 0;
height: 100px;
left: 0;
position: absolute;
width: 100%;
}
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
#main-wrapper {
min-height: 100%;
padding: 0 0 100px;
position: relative;
}
footer {
bottom: 0;
height: 100px;
left: 0;
position: absolute;
width: 100%;
}
header {
background-color: #F00;
}
nav {
background-color: #FF0;
}
article {
background-color: #0F0;
}
footer {
background-color: #00F;
}
<div id="main-wrapper">
<header>
here be header
</header>
<nav>
</nav>
<article>
here be content
</article>
<footer>
here be footer
</footer>
</div>
बेशक, आपको मेरे फैसले पर सवाल उठाना चाहिए, क्योंकि यह कोड पृष्ठ के नीचे से पाद लेख को नीचे गिराने के लिए मजबूर कर रहा है, तब भी जब कोई सामग्री हो। पिछले चाल द्वारा प्रयोग किया जाता बॉक्स मॉडल बदलने के लिए है #main-wrapper, इसलिए है कि min-heightके 100%शामिल 100pxगद्दी।
सीएसएस:
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
#main-wrapper {
box-sizing: border-box;
min-height: 100%;
padding: 0 0 100px;
position: relative;
}
footer {
bottom: 0;
height: 100px;
left: 0;
position: absolute;
width: 100%;
}
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
#main-wrapper {
box-sizing: border-box;
min-height: 100%;
padding: 0 0 100px;
position: relative;
}
footer {
bottom: 0;
height: 100px;
left: 0;
position: absolute;
width: 100%;
}
header {
background-color: #F00;
}
nav {
background-color: #FF0;
}
article {
background-color: #0F0;
}
footer {
background-color: #00F;
}
<div id="main-wrapper">
<header>
here be header
</header>
<nav>
</nav>
<article>
here be content
</article>
<footer>
here be footer
</footer>
</div>
और वहां आपके पास, आपके मूल HTML संरचना के साथ एक चिपचिपा पाद है। बस ऐसे ही यह सुनिश्चित कर लें footerकी heightके बराबर है #main-wrappers ' padding-bottom, और आप सेट होना चाहिए।
* इसका कारण मुझे फेट की संरचना में दोष लगता है क्योंकि यह अनावश्यक तत्व को जोड़ते समय विभिन्न पदानुक्रमित स्तरों पर तत्वों .footerऔर .headerतत्वों को सेट करता है .push।