I'm trying to make a small website, and I've figured out how to make a header and footer. The issue is, the header stops on the left side of the page and does not stop on the right. The footer stops in both direction. I want both the header and footer to reach the edges of the page. How do I do this? Additionally, how do I ensure body text is an equal distance from both the header and footer? Thanks!
body {
padding-top: 150px;
/*dear god. save yourself. ALWAYS have padding you actual fool.>*/
padding-bottom: 40px;
}
p {
color: black;
margin-left: 50px;
font-family: Arial, Helvetica, sans-serif;
font-size: medium;
}
.fixed-header {
width: 100%;
position: fixed;
background: black;
color: white;
text-align: center;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
font-size: large;
top: 0;
}
.footer {
bottom: 0;
height: 100px;
width: 100%;
padding-bottom: 0%;
background-color: black;
text-align: center;
line-height: 100px;
/*set line height=height to center text vertically!*/
color: white;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
a:link,
a:visited,
a:hover,
a:active {
text-decoration: none;
}
.container {
width: 100%;
margin: 0;
}
nav a {
color: #fff;
text-decoration: none;
padding: 5px 35px 10px;
display: inline-block;
width: 15%;
height: auto;
}
a {
color: white;
}
<DOCTYPE! html>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<html lang="en-US">
<head>
<link rel="stylesheet" href="css-attempt.css">
<title>Hmm</title>
</head>
<body>
<div >
<h1><a href="index.html">Hmm</a></h1>
<div >
<nav>
<a href="#">About</a>
<a href="#">Resources</a>
<a href="#">Projects</a>
<a href="#">Connect</a>
<a href="#">Donate</a>
</nav>
</div>
</div>
<p> Took way too long to understand why this text wasn't showing up. 6 hours of my life I'm never getting back.</p>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<p> Do you ever feel like a plastic bag?</p>
<div >
<div >This is a footer. It's here because the content ends here.</div>
</div>
</body>
I've tried adjusting padding, margins, and basically everything I could think of, given I have maybe two weeks of experience with coding.
CodePudding user response:
Your body has a margin from the user agent stylesheet. Override this by setting margin to zero for the body.
body {
padding-top: 150px;
/*dear god. save yourself. ALWAYS have padding you actual fool.>*/
padding-bottom: 40px;
margin: 0;
}
p {
color: black;
margin-left: 50px;
font-family: Arial, Helvetica, sans-serif;
font-size: medium;
}
.fixed-header {
width: 100%;
position: fixed;
background: black;
color: white;
text-align: center;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
font-size: large;
top: 0;
}
.footer {
bottom: 0;
height: 100px;
width: 100%;
padding-bottom: 0%;
background-color: black;
text-align: center;
line-height: 100px;
/*set line height=height to center text vertically!*/
color: white;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
a:link,
a:visited,
a:hover,
a:active {
text-decoration: none;
}
.container {
width: 100%;
margin: 0;
}
nav a {
color: #fff;
text-decoration: none;
padding: 5px 35px 10px;
display: inline-block;
width: 15%;
height: auto;
}
a {
color: white;
}
<DOCTYPE! html>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<html lang="en-US">
<head>
<link rel="stylesheet" href="css-attempt.css">
<title>Hmm</title>
</head>
<body>
<div >
<h1><a href="index.html">Hmm</a></h1>
<div >
<nav>
<a href="#">About</a>
<a href="#">Resources</a>
<a href="#">Projects</a>
<a href="#">Connect</a>
<a href="#">Donate</a>
</nav>
</div>
</div>
<p> Took way too long to understand why this text wasn't showing up. 6 hours of my life I'm never getting back.</p>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<p> Do you ever feel like a plastic bag?</p>
<div >
<div >This is a footer. It's here because the content ends here.</div>
</div>
</body>
CodePudding user response:
Here are 2 solutions provided. I believe, that 1st is what you really need, but the second solution is the case with default body margins saved.
body {
padding-top: 150px; /*dear god. save yourself. ALWAYS have padding you actual fool.>*/
padding-bottom: 40px;
margin: 0; /* <- just reset the margins */
}
p {
color:black;
margin-left: 50px;
font-family: Arial, Helvetica, sans-serif;
font-size: medium;
}
.fixed-header {
width: 100%;
position: fixed;
background: black;
color: white;
text-align: center;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
font-size: large;
top: 0;
}
.footer {
bottom: 0;
height: 100px;
width: 100%;
padding-bottom: 0%;
background-color: black;
text-align: center;
line-height: 100px; /*set line height=height to center text vertically!*/
color: white;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
a:link, a:visited, a:hover, a:active {
text-decoration: none;
}
.container {
width: 100%;
margin: 0;
}
nav a {
color: #fff;
text-decoration: none;
padding: 5px 35px 10px;
display: inline-block;
width: 15%;
height:auto;
}
a {
color: white;
}
<DOCTYPE! html>
<html lang="en-US">
<head>
<link rel="stylesheet" href="css-attempt.css">
<title>Hmm</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div >
<div >
<h1><a href="index.html">Hmm</a></h1>
<nav>
<a href="#">About</a>
<a href="#">Resources</a>
<a href="#">Projects</a>
<a href="#">Connect</a>
<a href="#">Donate</a>
</nav>
</div>
</div>
<p> Took way too long to understand why this text wasn't showing up. 6
hours of my life I'm never getting back.</p>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<p> Do you ever feel like a plastic bag?</p>
<div >
<div >This is a footer. It's here because the content ends here.</div>
</div>
</body>
</html>
body {
padding-top: 150px; /*dear god. save yourself. ALWAYS have padding you actual fool.>*/
padding-bottom: 40px;
margin: 10px; /* default margin */
}
p {
color:black;
margin-left: 50px;
font-family: Arial, Helvetica, sans-serif;
font-size: medium;
}
.fixed-header {
width: auto; /* <- the width of 100% equals to the width of the page here, but there is a margin of 10px of the body element from the left*/
position: fixed;
background: black;
color: white;
text-align: center;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
font-size: large;
top: 0;
left: 10px; /* <- */
right: 10px; /* <- */
}
.footer {
bottom: 0;
height: 100px;
width: 100%;
padding-bottom: 0%;
background-color: black;
text-align: center;
line-height: 100px; /*set line height=height to center text vertically!*/
color: white;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
a:link, a:visited, a:hover, a:active {
text-decoration: none;
}
.container {
width: 100%;
margin: 0;
}
nav a {
color: #fff;
text-decoration: none;
padding: 5px 35px 10px;
display: inline-block;
width: 15%;
height:auto;
}
a {
color: white;
}
<DOCTYPE! html>
<html lang="en-US">
<head>
<link rel="stylesheet" href="css-attempt.css">
<title>Hmm</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div >
<div >
<h1><a href="index.html">Hmm</a></h1>
<nav>
<a href="#">About</a>
<a href="#">Resources</a>
<a href="#">Projects</a>
<a href="#">Connect</a>
<a href="#">Donate</a>
</nav>
</div>
</div>
<p> Took way too long to understand why this text wasn't showing up. 6
hours of my life I'm never getting back.</p>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<p> Do you ever feel like a plastic bag?</p>
<div >
<div >This is a footer. It's here because the content ends here.</div>
</div>
</body>
</html>