gpt4 book ai didi

html - 页脚 float 到页面中间

转载 作者:行者123 更新时间:2023-11-28 19:25:13 25 4
gpt4 key购买 nike

有什么方法可以在页面底部设置页脚吗?页脚应为 100% 宽度,.wrapper 也应为 960px。

我已经试过了:

  1. position: relative; - 粘在 .content 标签之间
  2. position: absolute; - 坚持 .nav
  3. position: fixed; - 可能是一个解决方案,但我并不总是需要它,只是在最后一页的底部。
  4. .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>

https://jsfiddle.net/1adkjLw0/

最佳答案

一个选择是将你的容器变成一个垂直的 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>

关于html - 页脚 float 到页面中间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56386784/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com