无法使页脚停留在页面底部

时间:2018-09-11 18:13:10

标签: html css

我已经尝试了几个小时,并在stackoverflow和其他地方查看了有关它的几个主题。但我似乎无法解决。.

    body {
	background-color: #1a3041;
    background-image: radial-gradient(#757580, #1a3041);
	background-repeat: no-repeat;
	background-size: cover;
    }

    html {height:100%}

    .header {
	border-style:solid;
	border-width: 2px;
	border-color: #fa6800;
	background-color: #717171;
	font-family: open sans;
    color: #c1c1c1;
	padding:0px;
	margin:5px;
	margin-top:20px;
	box-shadow: 10px 10px 5px rgba(0, 0, 0, 0.5);
    }

    .header h1{
	display:inline;
	font-size:40px;
	padding-left:10px;
    }

    #slogan {
	display: inline-block;
	font-size:20px;
	font-style:italic;
	float:center;
	line-height: normal;
	vertical-align: center;
	padding-right:10px;
	margin-top:0px;

    }

     #menu {
	display: inline-block;
	font-size:25px;
	font-weight:bold;
	float:right;
	line-height: normal;
	vertical-align: bottom;
	margin-top:10px;

    }

    .main {
	position:absolute;
	background-color:#cdd1d5;
	padding: 10px;
	margin: 25px;
	margin-top:30px;
	margin-bottom: 10px;
	top:70px;
	min-height: calc(100% - 130px - 35px);
	left:0;
	right:0;
	box-shadow: 7px 7px 5px rgba(0, 0, 0, 0.5);
    }

    .footer {
	position: absolute;
	bottom:0px;
	left:5px;
	right:5px;
	height:30px;
	overflow:hidden;
	border-style:solid;
	border-bottom: none;
	border-width: 2px;
	border-color: #fa6800;
	background-color:#333333;
	padding-left:10px;
	vertical-align:top;
	font-size:12px;
	font-family: open sans;
    color: #c1c1c1;
	box-shadow: 10px 10px 5px rgba(0, 0, 0, 0.5);
    }

    a:link{
	text-decoration:none;
    }

    a:link.title, a:visited.title {
	color:#c1c1c1;
    }

    a:link.menu, a:visited.menu, a:link.current, a:visited.current {
	color:#c1c1c1;
	text-decoration:none;
	padding:10px;
    }

    a:link.lastmenu, a:visited.lastmenu, a:link.lastcurrent, a:visited.lastcurrent {
	color:#c1c1c1;
	text-decoration:none;
	padding:10px;
	padding-right:20px;
    }

    a:link:hover.menu{
	background-color:#fa6800;
	padding:10px;
    }

    a:link:hover.lastmenu{
	background-color:#fa6800;
	padding:10px;
	padding-right:20px;
    }

    a:link.current{
	background-color:#333333;
	padding:10px;
    }

    a:link.lastcurrent{
	background-color:#333333;
	padding:10px;
	padding-right:20px;
    }
    <!DOCTYPE html>
    <html lang="en-US">
    <head>
    <meta charset="UTF-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>The Airline Project | Home</title>
    <link rel="stylesheet" type="text/css" media="screen and (max-width:1250px)" href="mainverysmall.css">
    <link rel="stylesheet" type="text/css" media="screen and (max-width:1500px) and (min-width:1250px)" href="mainsmall.css">
    <link rel="stylesheet" type="text/css" media="screen and (min-width:1500px)" href="main.css">
    </head>
    <body>
    <div class="header">
    <h1><a class="title" href="home.html">The Airline Project</a></h1>
    <span id="slogan">Let your dreams fly</span>
    <span id="menu">
    <a class="menu" href="Home.html">Home</a>
    <a class="current" href="TheGame.html">The Game</a>
    <a class="menu" href="TutandTips.html">Tutorials and Tips</a>
    <a class="menu" href="FAQ.html">FAQ</a>
    <a class="menu" href="http://theairlineproject.net/forum/" target="_blank">Forum</a>
    <a class="lastmenu" href="Aboutus.html">About Us</a>
    </span>
    </div>
    <div class="main">
    <p>Test</p>
    <p>Test</p>
    <p>Test</p>
    <p>Test</p>
    <p>Test</p>
    <p>Test</p>
    <p>Test</p>
    <p>Test</p>
    <p>Test</p>
    <p>Test</p>
    <p>Test</p>
    </div>

    <div class="footer">
    <p>footer</p>
    </div>

    </body>
    </html>

所以我有两个问题: -我的页脚不停留在页面底部 -我的“主要”内容div不会在页脚之前停止,就像窗口太小一样。 (它一直持续到页面末尾)

我已经阅读了很多应该解决的内容,但是大多数情况下它是行不通的。 例如,将页脚设置为相对,则将其粘贴在菜单下。将内容设置为相对内容会将其粘贴到页面的中间...

4 个答案:

答案 0 :(得分:2)

在CSS的.footer下,将position: absolute更改为position: fixed

示例:https://jsfiddle.net/6adfc7bs/

答案 1 :(得分:2)

只需从.menu和.footer类样式中删除“绝对位置”。您会得到理想的结果。 :)

<!DOCTYPE html>
    <html lang="en-US">
    <head>
    <meta charset="UTF-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>The Airline Project | Home</title>
    <link rel="stylesheet" type="text/css" media="screen and (max-width:1250px)" href="mainverysmall.css">
    <link rel="stylesheet" type="text/css" media="screen and (max-width:1500px) and (min-width:1250px)" href="mainsmall.css">
    <link rel="stylesheet" type="text/css" media="screen and (min-width:1500px)" href="main.css">
    </head>
    <body>
    <div class="header">
    <h1><a class="title" href="home.html">The Airline Project</a></h1>
    <span id="slogan">Let your dreams fly</span>
    <span id="menu">
    <a class="menu" href="Home.html">Home</a>
    <a class="current" href="TheGame.html">The Game</a>
    <a class="menu" href="TutandTips.html">Tutorials and Tips</a>
    <a class="menu" href="FAQ.html">FAQ</a>
    <a class="menu" href="http://theairlineproject.net/forum/" target="_blank">Forum</a>
    <a class="lastmenu" href="Aboutus.html">About Us</a>
    </span>
    </div>
    <div class="main">
    <p>Test</p>
    <p>Test</p>
    <p>Test</p>
    <p>Test</p>
    <p>Test</p>
    <p>Test</p>
    <p>Test</p>
    <p>Test</p>
    <p>Test</p>
    <p>Test</p>
    <p>Test</p>
    </div>

    <div class="footer">
    <p>footer</p>
    </div>

    </body>
    </html>
--vdev=net_tap0

答案 2 :(得分:0)

为实现此目的,您需要更改html。 您需要将页脚放在最后一个div的内部,如下所示。

   <!DOCTYPE html>
    <html lang="en-US">
    <head>
         <meta charset="UTF-8"> 
         <meta name="viewport" content="width=device-width, initial-scale=1">
         <title>The Airline Project | Home</title>
         <link rel="stylesheet" type="text/css" media="screen and (max-width:1250px)" href="mainverysmall.css">
         <link rel="stylesheet" type="text/css" media="screen and (max-width:1500px) and (min-width:1250px)" href="mainsmall.css">
         <link rel="stylesheet" type="text/css" media="screen and (min-width:1500px)" href="main.css">
    </head>
    <body>
         <div class="header">
              <h1><a class="title" href="home.html">The Airline Project</a></h1>
              <span id="slogan">Let your dreams fly</span>
              <span id="menu">
                   <a class="menu" href="Home.html">Home</a>
                   <a class="current" href="TheGame.html">The Game</a>
                   <a class="menu" href="TutandTips.html">Tutorials and Tips</a>
                   <a class="menu" href="FAQ.html">FAQ</a>
                   <a class="menu" href="http://theairlineproject.net/forum/" target="_blank">Forum</a>
                   <a class="lastmenu" href="Aboutus.html">About Us</a>
              </span>

    </div>
    <div class="main">
         <p>Test</p>
         <p>Test</p>
         <p>Test</p>
         <p>Test</p>
         <p>Test</p>
         <p>Test</p>
         <p>Test</p>
         <p>Test</p>
         <p>Test</p>
         <p>Test</p>
         <p>Test</p>
         <div class="footer">
             <p>footer</p>
         </div>
    </div>



    </body>

但是,由于需要更改格式,因此它仍然不能100%正常工作。 我建议看一下引导程序。 这将使这些类型的布局变得更容易,并且已经进行了移动优化。

希望这会有所帮助

答案 3 :(得分:0)

您可以通过在CSS中添加粘性值来使用postion属性设置页脚粘性。

body {
	background-color: #1a3041;
    background-image: radial-gradient(#757580, #1a3041);
	background-repeat: no-repeat;
	background-size: cover;
    }

    html {height:100%}

    .header {
	border-style:solid;
	border-width: 2px;
	border-color: #fa6800;
	background-color: #717171;
	font-family: open sans;
    color: #c1c1c1;
	padding:0px;
	margin:5px;
	margin-top:20px;
	box-shadow: 10px 10px 5px rgba(0, 0, 0, 0.5);
    }

    .header h1{
	display:inline;
	font-size:40px;
	padding-left:10px;
    }

    #slogan {
	display: inline-block;
	font-size:20px;
	font-style:italic;
	float:center;
	line-height: normal;
	vertical-align: center;
	padding-right:10px;
	margin-top:0px;

    }

     #menu {
	display: inline-block;
	font-size:25px;
	font-weight:bold;
	float:right;
	line-height: normal;
	vertical-align: bottom;
	margin-top:10px;

    }

    .main {
	background-color:#cdd1d5;
	padding: 10px;
	margin: 25px;
	margin-top:30px;
	margin-bottom: 10px;
	top:70px;
	min-height: calc(100% - 130px - 35px);
	left:0;
	right:0;
	box-shadow: 7px 7px 5px rgba(0, 0, 0, 0.5);
    }

    .footer {
	left:5px;
	right:5px;
	height:30px;
	overflow:hidden;
	border-style:solid;
	border-bottom: none;
	border-width: 2px;
	border-color: #fa6800;
	background-color:#333333;
	padding-left:10px;
	vertical-align:top;
	font-size:12px;
	font-family: open sans;
    color: #c1c1c1;
	box-shadow: 10px 10px 5px rgba(0, 0, 0, 0.5);
  position: sticky;
  bottom: 0;
    }

    a:link{
	text-decoration:none;
    }

    a:link.title, a:visited.title {
	color:#c1c1c1;
    }

    a:link.menu, a:visited.menu, a:link.current, a:visited.current {
	color:#c1c1c1;
	text-decoration:none;
	padding:10px;
    }

    a:link.lastmenu, a:visited.lastmenu, a:link.lastcurrent, a:visited.lastcurrent {
	color:#c1c1c1;
	text-decoration:none;
	padding:10px;
	padding-right:20px;
    }

    a:link:hover.menu{
	background-color:#fa6800;
	padding:10px;
    }

    a:link:hover.lastmenu{
	background-color:#fa6800;
	padding:10px;
	padding-right:20px;
    }

    a:link.current{
	background-color:#333333;
	padding:10px;
    }

    a:link.lastcurrent{
	background-color:#333333;
	padding:10px;
	padding-right:20px;
    }
<!DOCTYPE html>
    <html lang="en-US">
    <head>
    <meta charset="UTF-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>The Airline Project | Home</title>
    <link rel="stylesheet" type="text/css" media="screen and (max-width:1250px)" href="mainverysmall.css">
    <link rel="stylesheet" type="text/css" media="screen and (max-width:1500px) and (min-width:1250px)" href="mainsmall.css">
    <link rel="stylesheet" type="text/css" media="screen and (min-width:1500px)" href="main.css">
    </head>
    <body>
    <div class="header">
    <h1><a class="title" href="home.html">The Airline Project</a></h1>
    <span id="slogan">Let your dreams fly</span>
    <span id="menu">
    <a class="menu" href="Home.html">Home</a>
    <a class="current" href="TheGame.html">The Game</a>
    <a class="menu" href="TutandTips.html">Tutorials and Tips</a>
    <a class="menu" href="FAQ.html">FAQ</a>
    <a class="menu" href="http://theairlineproject.net/forum/" target="_blank">Forum</a>
    <a class="lastmenu" href="Aboutus.html">About Us</a>
    </span>
    </div>
    <div class="main">
    <p>Test</p>
    <p>Test</p>
    <p>Test</p>
    <p>Test</p>
    <p>Test</p>
    <p>Test</p>
    <p>Test</p>
    <p>Test</p>
    <p>Test</p>
    <p>Test</p>
    <p>Test</p>
    </div>

    <div class="footer">
    <p>footer</p>
    </div>

    </body>
    </html>

相关问题