是否可以在页面底部设置页脚?
页脚宽度应为100%,.wrapper
也应为960px。
我已经尝试过:
position: relative;
-粘在.content
标签之间position: absolute;
-坚持使用.nav
position: fixed;
-可能是一个解决方案,但是我不需要一直都在最后一页的底部。.footer
移动到.wrapper
之外并设置.wrapper:not(footer);
-页脚固定在底部,但是宽度没有变化。 任何建议如何将其设置在底部?
@charset "UTF-8";
@import url('https://fonts.googleapis.com/css?family=Montserrat|Nunito+Sans|Roboto&display=swap');
* {
margin: 0;
padding: 0;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
html {
scroll-behavior: smooth;
word-wrap: break-word;
}
html,
body,
header,
main {
height: 100%;
}
body {
width: 100%;
font-family: Roboto, Verdana, sans-serif;
font-size: 1em;
background-image: url(../images/extra_clean_paper.png);
background-repeat: repeat;
}
header {
text-align: center;
background-color: yellow;
}
#hero-header {
position: relative;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
#hero-btn {
width: 50px;
height: 50px;
position: absolute;
bottom: 4em;
left: 50%;
-webkit-transform: translateX(-50%);
-ms-transform: translateX(-50%);
transform: translateX(-50%);
}
.hero-btn a {
position: relative;
display: inline-block;
color: black;
text-decoration: none;
-webkit-transition: opacity .3s;
-o-transition: opacity .3s;
transition: opacity .3s;
}
.hero-btn a:hover {
opacity: 0.5;
}
header a {
padding-top: 70px;
}
header a span {
position: absolute;
top: 0;
left: 50%;
width: 24px;
height: 24px;
margin-left: -12px;
border-left: 1px solid black;
border-bottom: 1px solid black;
-webkit-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
transform: rotate(-45deg);
-webkit-animation: sdb07 2s infinite;
animation: sdb07 2s infinite;
opacity: 0;
}
header a span:nth-of-type(1) {
-webkit-animation-delay: 0s;
animation-delay: 0s;
}
header a span:nth-of-type(2) {
top: 16px;
-webkit-animation-delay: .15s;
animation-delay: .15s;
}
header a span:nth-of-type(3) {
top: 32px;
-webkit-animation-delay: .3s;
animation-delay: .3s;
}
@-webkit-keyframes sdb07 {
0% {
opacity: 0;
}
50% {
opacity: 1;
}
100% {
opacity: 0;
}
}
@keyframes sdb07 {
0% {
opacity: 0;
}
50% {
opacity: 1;
}
100% {
opacity: 0;
}
}
#resp-nav {
text-align: center;
display: none;
background-color: grey;
}
#resp-nav i {
font-size: 2em;
color: white;
}
#nav {
text-align: center;
background-color: dimgray;
z-index: 2;
}
main:not(#footer) {
max-width: 960px;
margin: 0 auto;
}
.container {
background-color: #eeeeee;
border: 1px solid red;
border-radius: 5px;
clear: both;
overflow: hidden;
margin-top: 1em;
min-height: 100%;
padding: 3.125em 0.625em;
-webkit-box-shadow: 0 15px 20px rgba(0, 0, 0, 0.3);
box-shadow: 0 15px 20px rgba(0, 0, 0, 0.3);
}
.aboutme img {
width: 100%;
height: auto;
}
.aboutme .col-40 {
margin-top: 1em;
padding-left: 1em;
padding-right: 1em;
width: 39%;
}
.aboutme .col-60 {
margin-top: 1em;
padding-left: 1em;
padding-right: 1em;
width: 59%;
}
.left {
float: left;
}
.right {
float: right;
}
.table {
display: table;
border-collapse: collapse;
table-layout: fixed;
}
.hobbies .table-row {
display: table-row;
border-bottom: 0.1em solid darkgrey;
}
.hobbies .table-row:last-child {
border: 0;
}
.hobbies .table-cell {
display: table-cell;
padding-left: 1em;
padding-right: 1em;
vertical-align: middle;
text-align: center;
width: 50%;
}
.portfolio .col-50 {
margin-top: 1em;
padding-left: 1em;
padding-right: 1em;
width: 49%;
}
.projects .flex-row {
display: flex;
flex-wrap: wrap;
width: 100%;
padding-right: 15px;
padding-left: 15px;
margin-right: auto;
margin-left: auto;
}
.projects .col-33 {
position: relative;
width: 100%;
max-width: 33%;
-ms-flex: 0 0 33%;
-webkit-box-flex: 0;
-webkit-flex: 0 0 33%;
flex: 0 0 33%;
}
.projects .services-box {
background: #f9f9f9;
padding: 10px;
margin: 20px 5px 0 5px;
}
footer {
background: red;
height: 50px;
width: 100%;
position: relative;
bottom: 0;
left: 0;
margin-top: 10px;
}
<header id="link-hero-page">
<div id="hero-header">
</div>
</header>
<nav>
<ul id="nav">
</ul>
</nav>
<main>
<section id="link-main" class="aboutme container">
<div class="col-40 left">
</div>
<article class="col-60 right">
</article>
</section>
<section id="link-hobbies" class="hobbies container">
<div class="table">
<div class="table-row">
<article class="table-cell">
</article>
</div>
<div class="table-row">
<div class="table-cell">
</div>
<article class="table-cell">
</article>
</div>
<div class="table-row">
<article class="table-cell">
</article>
</div>
</div>
</section>
<section id="link-portfolio" class="portfolio container">
<article class="col-50 left">
</article>
<article class="col-50 right">
</article>
</section>
<section id="link-projects" class="projects container">
<div class="flex-row">
<div class="col-33">
<article class="services-box">
</article>
</div>
<div class="col-33">
<article class="services-box">
</article>
</div>
<div class="col-33">
<article class="services-box">
</article>
</div>
</div>
</section>
<section id="link-contacts" class="contacts container">
</section>
</main>
<!--FOOTER-->
<footer>
<address>
<p style="text-align: center;">LOREM LOREM LOREM LOREM LOREM</p>
</address>
</footer>
答案 0 :(得分:0)
一种选择是将您的容器变成垂直的flexbox,并在页脚上设置margin-top: auto
,将其推到flex容器的底部。您还需要在容器上设置height: 100%
,以使其充满整个页面
* {
margin: 0;
padding: 0;
}
html,
body {
height: 100%;
}
body {
width: 100%;
}
.nav {
background: green;
height: 50px;
}
.wrapper {
max-width: 500px;
margin: 0 auto;
display: flex;
flex-direction: column;
height: 100%;
}
.content {
background: yellow;
margin-top: 10px;
height: 100px;
}
.footer {
background: red;
height: 50px;
width: 100%;
position: relative;
margin-top: auto;
bottom: 0;
left: 0;
}
<body>
<div class="nav"></div>
<div class="wrapper">
<div class="content"></div>
<div class="content"></div>
<div class="content"></div>
<div class="content"></div>
<div class="content"></div>
<div class="content"></div>
<div class="footer"></div>
</div>
</body>
答案 1 :(得分:0)
只需将页脚移到包装纸外面即可。
* {
margin: 0;
padding: 0;
}
html,
body {
height: 100%;
}
body {
width: 100%;
}
.nav {
background: green;
height: 50px;
}
.wrapper {
max-width: 500px;
margin: 0 auto;
}
.content {
background: yellow;
margin-top: 10px;
height: 100px;
}
.footer {
background: red;
height: 50px;
width: 100%;
position: relative;
bottom: 0;
left: 0;
margin-top: 10px;
}
<div class="nav"></div>
<div class="wrapper">
<div class="content"></div>
<div class="content"></div>
<div class="content"></div>
<div class="content"></div>
<div class="content"></div>
<div class="content"></div>
</div>
<div class="footer"></div>