标题,主页和页脚定位

时间:2017-04-27 11:16:15

标签: html css header footer

我的页面分为3个部分。 标题 主要页脚标题固定在顶部,为109px,其6px边框为高,因此 main 与顶部的边距为109px。我希望扩展到标题下方的整个页面以及页脚,如果没有可用于推送它的内容向下,休息在屏幕的底部。 页脚高86px,因为它的顶部边框为80px和6px。我怎样才能实现这一切。我不知道

html {
  height: 100%;
  box-sizing: border-box;
}

body {
  background-color: #f5f5f5;
  margin: 0;
  padding: 0;
  position: relative;
  margin: 0;
  padding-bottom: 9rem;
  min-height: 100%;
}


/* ---------------------------------------------------------------- */

main {
  margin-top: 109px;
  text-align: center;
  min-height: 100%;
  min-width: 100%;
}

#header {
  background-color: #25211e;
  border-bottom: 6px solid #1d1a18;
  text-align: center;
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 103px;
  box-shadow: 0px 0px 14px 2px rgba(0, 0, 0, 0.75);
  z-index: 99;
}

#heading {
  font-family: "Arial";
  color: #c1b497;
  font-size: 45px;
  display: inline-block;
  margin-bottom: 10px;
  margin-top: 15px;
}


/* ---------------------------------------------------------------- */

#footer {
  background-color: #25211e;
  border-top: 6px solid #1d1a18;
  text-align: center;
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 80px;
  z-index: 98;
}

#credit {
  font-family: "Helvetica";
  font-size: 14px;
  color: #c1b497;
  font-weight: 600;
}
<div id="all">
  <header id="header">
    <h1 id="heading">My Page</h1>
  </header>
  <main id="main">



  </main>
  <footer id="footer">
    <p id="credit">FOOTER</p>
  </footer>
</div>

2 个答案:

答案 0 :(得分:0)

请让你的问题更清楚,我会试一试,这是你想要的(固定位置并删除不必要的边距)?

html {
  	height: 100%;
    box-sizing: border-box;
}
body {
    background-color: #f5f5f5;
    margin: 0;
    padding: 0;
 	  min-height: 100%;
}

	/* ---------------------------------------------------------------- */

main {
    text-align: center;
    min-height: 100%;
  	min-width: 100%;
}

#header {
	background-color: #25211e;
	border-bottom: 6px solid #1d1a18;
	text-align: center;
  width: 100%;
  height: 103px;
  box-shadow: 0px 0px 14px 2px rgba(0,0,0,0.75);
  z-index: 99;
}

#heading {
  font-family: "Arial";
	color: #c1b497;
	font-size: 45px;
	display: inline-block;
	margin-bottom: 10px;
	margin-top: 15px;
}

#navigation {  
	margin: 0px;
	margin-bottom: 20px;
	padding: 0px;

}

.navigationlink {
	font-family: "Helvetica";
	text-decoration: none;
	font-weight: 800;
	color: #ffffff;
	font-size: 11px;
	height: 52px;
	letter-spacing: 1px;
	margin: 0 10px;
	padding-left: 0px;
	padding-right: 0px;
	position: relative;
	text-transform: uppercase;
	transition: color 0.3s;
}	

.navigationlink:hover {
	color: #c1b497;
}

.activelink:hover {
	border-bottom-color: #c1b497;
}

.activelink {
	border-bottom: 2px solid #ffffff;
	transition: color 0.3s;
}
	/* ---------------------------------------------------------------- */

#footer {
    background-color: #25211e;
	border-top: 6px solid #1d1a18;
	text-align: center;
	position: fixed;
  	right: 0;
 	bottom: 0;
  	left: 0;
  	height: 80px;
  	z-index: 98;
}

#credit {
    font-family: "Helvetica";
    font-size: 14px;
	color: #c1b497;
	font-weight: 600;
}
	<div id="all">
			<header id="header">
              	<h1 id="heading">My Page</h1>
                <nav id="navigation">
					<a class="navigationlink activelink" href="index.html">Home</a>
					<a class="navigationlink" href="page1.html">Page1</a>
					<a class="navigationlink" href="page2.html">Page2</a>
					<a class="navigationlink" href="page3.html">Page3</a>
					<a class="navigationlink" href="page4.html">Page4</a>
				</nav>
            </header>
			<main id="main">
      
      
      
			</main>
			<footer id="footer">
				<p id="credit">FOOTER</p>
			</footer>
		</div>

答案 1 :(得分:0)

您只需要从padding-bottom移除body,然后将margin-top替换为padding-top&amp; padding-bottom

&#13;
&#13;
html {
  height: 100%;
  box-sizing: border-box;
}

body {
  background-color: #f5f5f5;
  margin: 0;
  padding: 0;
  position: relative;
  min-height: 100%;
}

/* ---------------------------------------------------------------- */

main {
  padding-top: 109px;
  padding-bottom: 86px;
  text-align: center;
}

#header {
  background-color: #25211e;
  border-bottom: 6px solid #1d1a18;
  text-align: center;
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 103px;
  box-shadow: 0px 0px 14px 2px rgba(0, 0, 0, 0.75);
  z-index: 99;
}

#heading {
  font-family: "Arial";
  color: #c1b497;
  font-size: 45px;
  display: inline-block;
  margin-bottom: 10px;
  margin-top: 15px;
}

#navigation {
  margin: 0px;
  margin-bottom: 20px;
  padding: 0px;
}

.navigationlink {
  font-family: "Helvetica";
  text-decoration: none;
  font-weight: 800;
  color: #ffffff;
  font-size: 11px;
  height: 52px;
  letter-spacing: 1px;
  margin: 0 10px;
  padding-left: 0px;
  padding-right: 0px;
  position: relative;
  text-transform: uppercase;
  transition: color 0.3s;
}

.navigationlink:hover {
  color: #c1b497;
}

.activelink:hover {
  border-bottom-color: #c1b497;
}

.activelink {
  border-bottom: 2px solid #ffffff;
  transition: color 0.3s;
}

/* ---------------------------------------------------------------- */

#footer {
  background-color: #25211e;
  border-top: 6px solid #1d1a18;
  text-align: center;
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 80px;
  z-index: 98;
}

#credit {
  font-family: "Helvetica";
  font-size: 14px;
  color: #c1b497;
  font-weight: 600;
}
&#13;
<div id="all">
  <header id="header">
    <h1 id="heading">My Page</h1>
    <nav id="navigation">
      <a class="navigationlink activelink" href="index.html">Home</a>
      <a class="navigationlink" href="page1.html">Page1</a>
      <a class="navigationlink" href="page2.html">Page2</a>
      <a class="navigationlink" href="page3.html">Page3</a>
      <a class="navigationlink" href="page4.html">Page4</a>
    </nav>
  </header>
  <main id="main"></main>
  <footer id="footer">
    <p id="credit">FOOTER</p>
  </footer>
</div>
&#13;
&#13;
&#13;