When I set my header as "fixed", it automatically adjusts the size of the header box

Looking to create a fixed-header that includes clickable links on the left and our logo on the right.

Encountering an issue when trying to make the header take up the full width of the screen in its fixed position. The header's width seems to shrink to fit the size of the three links added.

The header width is set to 100% already, but I am unable to identify the underlying problem.

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;
    /* Align in center */
    background: black;
  }
}

@media screen and (max-width: 660px) {
  .thumb-container {
    max-width: 100%; 
    /* Align in center */
    background: black;
  }
  .thumb-container a {
    width: 100%; 
    /* Make containers full width */
    margin: 0 0 10px 0;
  }
}
<header>
  <nav>
    <ul>
      <li> <a href="index.html"> Home </a></li>
      <li> <a href="#"> Supplies </a></li>
      <li> <a href="#"> About us </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>

Answer №1

Give this a try

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">Resources</a>
  <a href="#contact">Contact</a>
</div>

<div class="main">
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
  <p>Fusce quis ullamcorper leo. Donec elementum neque a libero fermentum.</p>
</div>

</body>
</html>

Answer №2

The width property is missing a ":" character in your code. Please make the necessary correction.

Answer №3

You have overlooked a minor syntax error when defining the width!

Instead of using width 100%;, it should be 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;
    /* center alignment */
    background: black;
  }
}

@media screen and (max-width: 660px) {
  .thumb-container {
    max-width: 100%;
    /* center alignment */
    background: black;
  }
  .thumb-container a {
    width: 100%;
    /* makes containers full width*/
    margin: 0 0 10px 0;
  }
}
<header>
  <nav>
    <ul>
      <li> <a href="index.html"> Home </a></li>
      <li> <a href="#">  Resources </a></li>
      <li> <a href="#"> About us </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>

Answer №4

To resolve this issue, you can adjust the property to right: 0;. My suggestion would be to eliminate float: left; and utilize display: flex; instead in your example. I have modified your example to demonstrate what I mean. Hopefully, this advice proves helpful.

I also encourage you to explore the following 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;
    /* centered on the page */
    background: black;
  }
}

@media screen and (max-width: 660px) {
  .thumb-container {
    max-width: 100%;
    /* centered on the page */
    background: black;
  }
  .thumb-container a {
    width: 100%;
    /* makes containers full width */
    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>

  <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>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to ensure that the columns are the same height, regardless of the varying content they contain

Visit my CodePen For this particular layout, I need to use only CSS. The columns are structured like so: <div class="col-md-12 no-border no-padding"> <h2 class="heading upper align-center">Headline</h2> <p class="subheading lower ...

Is there a way to get this script running on WordPress?

I'm working with this JavaScript code: $(document).ready(function(){ $("text1").click(function(){ $(this).hide(); }); }); Here's the HTML code: <div class="div1"> <p class="text1">text to appear when the user p ...

Unexpected token . encountered in Javascript: Uncaught Syntax Error. This error message is triggered when

As someone who is completely new to programming, I was given the task of creating a voting website for a class assignment. In order to store data locally, I managed to create variables and implement them using local storage: var eventName = document.getEl ...

Use jQuery to retrieve the response from a JSON request and showcase it on the existing HTML page

Currently, I am working on a project that involves integrating a JSON-based web service from a remote server. The method of this service can be accessed by using specially formatted URLs such as: http://root-url/ws/service-name?request={json-string} The ...

The design does not have the capability to scroll

I am currently working on developing an application using Vaadin and Spring Boot. I have successfully set the background of my app by utilizing the following CSS code within the styles.scss file (inside myTheme as specified by Vaadin): .backgroundImage{ ...

A guide to smoothly transition box-shadow with jQuery's addClass() function

UPDATED I have a div with the class .shadow-circle-lg: <div class="shadow-circle-lg"></div> To add a different border styling to the div, I am using another class called .circle-highlight: .circle-highlight{ box-shadow: 0 0 0 1px rgba(0,0, ...

Developing a dynamic table using HTML and JavaScript

I have a question that might sound silly, but I am trying to retrieve the HTML content from this particular website using JavaScript. The data I'm interested in is located at the center of the page within a dynamic table which does not change the URL ...

The Bootstrap Input-Group with Spinner displays an unusual spinning shape that resembles the letter D

I am encountering an issue with a unique form that sends each line of input as a separate request upon submission. I am looking to add a spinner at the end of each line, but I am facing a problem where instead of a circular spinner, I am getting a spinning ...

Ending the Overlay

I am using an overlay: <div id="overlayer" class="overlayer"> <div id="board" class="board"></div> </div> Here are the CSS properties I have applied to it: #overlayer { position:fixed; display:none; top:0; left:0; width:100%; hei ...

Just finished my first webpage - can't seem to get the footer to stay put!

After spending 3-4 months learning HTML and CSS, I am now working on my first web page. However, I'm facing an issue where the footer is stuck to the slideshow and I can't seem to figure out how to position it at the bottom of the page. Any tips ...

Is there an issue with this html code?

Can you help me troubleshoot this HTML code snippet I have? <html> <head> <script type="text/javascript" language="JavaScript1.3" src="js/euDock.2.0.js"></script> <script type="text/javascript" language="JavaScript1.3" ...

Failure to Connect HTML with Stylesheet

Feeling a bit lost here. I've been attempting to connect my homepage to my stylesheet, but no matter how often I refresh the page, it just won't recognize the link. I'm diligently following the instructions from the guide I have, copying and ...

Effortlessly move and release Internet Explorer

Encountering drag and drop issues in Internet Explorer and Safari, while functioning correctly in Firefox 15 (untested on other versions). Dragging and dropping items between dropzones works in Safari, but sorting does not. In Internet Explorer, nothing wo ...

Discover the row and column of a selected table cell using vanilla JavaScript, no need for jQuery

In my JavaScript code, I am currently working on creating an onclick function that will display the row and column of a specifically clicked cell in a table. I have successfully implemented functionality to return the column number when the cell is click ...

unable to choose an option if more than one radio button is being used

I am having trouble with two radio buttons that are supposed to select the gender of an applicant and the gender of the applicant's child. Both buttons are not functioning properly. Can someone assist me with this issue? Here is the code I am using: ...

Issues with HTML text areas tags not being recognized after submitting a form occur specifically in Internet Explorer

I am encountering an issue with my form. I have a textarea field within the form, and on submit, I am trying to copy the content of a div containing a table into this textarea field. However, when I send this form and the email in IE, the values appear as ...

Choosing the subsequent div after the current one using Jquery

I am currently in the process of creating a drop-down menu button that, when clicked, reveals the previously hidden div underneath it. The code is functioning properly without the use of $(this).next, but it is displaying all divs with the class .menudrop ...

Tips for including a new class in an HTML element

My goal is to add a specific class to an HTML tag, if that tag exists. This is the code I have attempted: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>index</title> <style> ...

Clipped Words & Silhouettes

I'm having trouble ensuring the text in this particular example displays correctly. I am experiencing challenges with the clipping of text and shadows on certain letters, and I'm struggling to identify the root cause as well as the solution. In ...

Issue with mobile.changePage() function not executing as expected

I created a basic code that generates a "Splash screen". For storing my data, I am utilizing localstorage. When I first load it, I retrieve data from a URL and I am able to navigate to different pages using $.mobile.changePage(). However, if the data is a ...