Reputation:
I want to make a fixed-header, with the clickable links on the left and our logo on the right.
No issues with floating the text + image to it's corresponding place and to make the header take up the whole width of the screen. Once I make it "fixed" the header's width shrinks to the width of the 3 links I have added.
The width of the header is already set to 100% and I cannot seem to find what the underlying issue is
html {
scroll-behavior: smooth;
}
.clear {
clear: both;
}
header {
width 100%;
height: 100px;
position: fixed;
color: rgb(255, 0, 0);
top: 0;
left: 0;
box-shadow: 0 1px 4px 0 rgba(0, 0, 0, 0.1);
z-index: 999;
}
footer {
height: 30px;
color: black;
text-align: center;
box-shadow: 1px 0 4px 0 rgba(0, 0, 0, 0.1);
}
header ul {
list-style: none;
float: left;
text-transform: uppercase;
font-family: 'Source Sans Pro';
font-weight: bold;
}
header ul li {
float: left;
margin-left: 60px;
line-height: 100px;
}
header ul a {
text-decoration: none;
}
header ul a:hover {
color: rgb(200, 0, 0);
}
.thumb-container {
max-width: calc(960px + 40px);
margin: 110px auto 0 auto;
}
.thumb-container a {
width: calc(960px / 3);
height: calc(960px / 3);
background: aqua;
float: left;
margin: 0 5px 10px 5px;
}
@media screen and (max-width: 1000px) {
.thumb-container {
max-width: 660px;
/* in midden zetten */
background: black;
}
}
@media screen and (max-width: 660px) {
.thumb-container {
max-width: 100%;
/* in midden zetten */
background: black;
}
.thumb-container a {
width: 100%;
/* maakt containers volledige breedte*/
margin: 0 0 10px 0;
}
}
<header>
<nav>
<ul>
<li> <a href="index.html"> Home </a></li>
<li> <a href="#"> Benodigdheden </a></li>
<li> <a href="#"> Over ons </a></li>
</ul>
</nav>
<img src="img/" alt="lol">
</header>
<main>
<div class="thumb-container">
<a href="#"> </a>
<a href="#"> </a>
<a href="#"> </a>
<a href="#"> </a>
<a href="#"> </a>
<a href="#"> </a>
<div class="clear"></div>
</div>
</main>
<footer> Test footer text</footer>
Upvotes: 0
Views: 49
Reputation: 1092
Try this
body {margin:0;}
.navbar {
overflow: hidden;
background-color: #333;
position: fixed;
top: 0;
width: 100%;
}
.navbar a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.navbar a:hover {
background: #ddd;
color: black;
}
.main {
padding: 16px;
margin-top: 30px;
height: 1500px;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="navbar">
<a href="#home">Home</a>
<a href="#news">Benodigdheden</a>
<a href="#contact">Contact</a>
</div>
<div class="main">
<p>Some text some text some text some text..</p>
<p>Some text some text some text some text..</p>
</div>
</body>
</html>
Upvotes: 1
Reputation: 19118
You can fix that by setting the property right: 0;
. If you look at my example I would recommend you that you remove the float: left;
and use display: flex;
instead. I changed your example to reflect what I mean. Hope this helps.
I recommend you to look at this post and video
html {
scroll-behavior: smooth;
}
* {
box-sizing: border-box;
}
.header {
position: fixed;
top: 0;
right: 0;
left: 0;
display: flex;
align-items: center;
height: 100px;
color: rgb(255, 0, 0);
box-shadow: 0 1px 4px 0 rgba(0, 0, 0, 0.1);
z-index: 2;
background-color: deepskyblue;
}
.header__logo {
width: 4rem;
height: 2rem;
margin-left: auto;
background-color: aqua;
}
.navigation-links {
display: flex;
list-style: none;
text-transform: uppercase;
font-family: 'Source Sans Pro';
font-weight: bold;
}
.navigation-links__link {
margin-left: 60px;
line-height: 100px;
}
.navigation-links__link a {
display: block;
text-decoration: none;
}
.navigation-links__link a:hover {
color: rgb(200, 0, 0);
}
footer {
height: 30px;
color: black;
text-align: center;
box-shadow: 1px 0 4px 0 rgba(0, 0, 0, 0.1);
}
.thumb-container {
display: flex;
flex-wrap: wrap;
max-width: calc(960px + 40px);
margin: 110px auto 0 auto;
}
.thumb-container a {
width: calc(960px / 3);
height: calc(960px / 3);
background: aqua;
margin: 0 5px 10px 5px;
}
@media screen and (max-width: 1000px) {
.thumb-container {
max-width: 660px;
/* in midden zetten */
background: black;
}
}
@media screen and (max-width: 660px) {
.thumb-container {
max-width: 100%;
/* in midden zetten */
background: black;
}
.thumb-container a {
width: 100%;
/* maakt containers volledige breedte*/
margin: 0 0 10px 0;
}
}
<header class="header">
<nav class="navigation">
<ul class="navigation-links">
<li class="navigation-links__link"> <a href="index.html"> Home </a></li>
<li class="navigation-links__link"> <a href="#"> Benodigdheden </a></li>
<li class="navigation-links__link"> <a href="#"> Over ons </a></li>
</ul>
</nav>
<!--<img src="img/" alt="lol" class="header__logo">-->
<div class="header__logo"></div>
</header>
<main>
<div class="thumb-container">
<a href="#"> </a>
<a href="#"> </a>
<a href="#"> </a>
<a href="#"> </a>
<a href="#"> </a>
<a href="#"> </a>
</div>
</main>
<footer> Test footer text</footer>
Upvotes: 0
Reputation: 1651
You are missing a ":" when setting your width!
It should be width: 100%;
not width 100%;
html {
scroll-behavior: smooth;
}
.clear {
clear: both;
}
header {
width: 100%;
height: 100px;
position: fixed;
color: rgb(255, 0, 0);
top: 0;
left: 0;
box-shadow: 0 1px 4px 0 rgba(0, 0, 0, 0.1);
z-index: 999;
}
footer {
height: 30px;
color: black;
text-align: center;
box-shadow: 1px 0 4px 0 rgba(0, 0, 0, 0.1);
}
header ul {
list-style: none;
float: left;
text-transform: uppercase;
font-family: 'Source Sans Pro';
font-weight: bold;
}
header ul li {
float: left;
margin-left: 60px;
line-height: 100px;
}
header ul a {
text-decoration: none;
}
header ul a:hover {
color: rgb(200, 0, 0);
}
.thumb-container {
max-width: calc(960px + 40px);
margin: 110px auto 0 auto;
}
.thumb-container a {
width: calc(960px / 3);
height: calc(960px / 3);
background: aqua;
float: left;
margin: 0 5px 10px 5px;
}
@media screen and (max-width: 1000px) {
.thumb-container {
max-width: 660px;
/* in midden zetten */
background: black;
}
}
@media screen and (max-width: 660px) {
.thumb-container {
max-width: 100%;
/* in midden zetten */
background: black;
}
.thumb-container a {
width: 100%;
/* maakt containers volledige breedte*/
margin: 0 0 10px 0;
}
}
<header>
<nav>
<ul>
<li> <a href="index.html"> Home </a></li>
<li> <a href="#"> Benodigdheden </a></li>
<li> <a href="#"> Over ons </a></li>
</ul>
</nav>
<img src="img/" alt="lol">
</header>
<main>
<div class="thumb-container">
<a href="#"> </a>
<a href="#"> </a>
<a href="#"> </a>
<a href="#"> </a>
<a href="#"> </a>
<a href="#"> </a>
<div class="clear"></div>
</div>
</main>
<footer> Test footer text</footer>
Upvotes: 0