What impact does reducing the window size have on my header?

While working on a website with a navigation bar, I encountered an issue where the navbar was not responsive. When the window size was reduced, the nav bar shifted to an awkward position vertically, as shown in the first image.

The navbar shifts below the image when the window size is decreased: https://i.stack.imgur.com/EB9ov.png

Normal large window size: https://i.stack.imgur.com/BpgKt.png

I have included the HTML and CSS code below for reference. I tried to make the navbar responsive but I'm struggling to get the desired behavior when the window size decreases.

Reference Video link -> https://www.youtube.com/watch?v=TTbYFzAz-Lg

HTML

<!DOCTYPE html>
<html>
    <head>
        <title>
            Responsive Navigation Bar
        </title>
        <link href="style.css" rel="stylesheet" type="text/css">
        <meta name="viewport" content="width=device-width initial-scale=1">
    </head>
    <body>
        <div id="header">
            <div id="logo">
                <img src="Redbull-logo.png">
            </div>
            <ul id="navbar">
                <li><a href="#">Home</a></li>
                <li><a href="#">Service</a></li>
                <li><a href="#">Product</a></li>
                <li><a href="#">Contact</a></li>
                <li><a href="#">About</a></li>
            </ul>
        </div>
    </body>
</html>

CSS

*{
    margin: 0px;
    padding: 0px;
}

body{
    background: skyblue;
}

#header{
    width: 100%;
    height: 80px;
    background: #333;
    box-shadow: 0px 3px 4px gray;
}

#navbar{
    width: 1000px;
    height: 80px;
    float: right;
}

#navbar > li{
    width: 198px;
    list-style: none;
    float: left;
    border-right: 1px solid gray;
    border-left: 1px solid gray;
}

li > a{
    display: block;
    color: white;
    line-height: 80px;
    text-align: center;
    font-family: cursive;
    font-size: 20px;
    text-decoration: none;
} 

li > a:hover,
li > a:focus{
    background-color: skyblue;
    color: #333;
}

#logo{
    width: 200px;
    float: left;
    height: 80px;
    padding-left: 40px; 
}

Answer №1

The issue is that when you reduce the size of the screen, there isn't enough space in the navigation bar for all the links and the image, causing them to move onto two lines. To solve this problem, consider using media queries to adjust certain elements like the image size and font size of the navigation links based on the screen width.

Here's an example of how you can implement this:

@media (max-width: 1080px){
   .navbar-links{
     font-size: 0.8em;
     padding: 0px 5px;
   }

   .navbar-image{
     width: 500px;
   }

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

Applying a consistent script with varying inputs on the same HTML page

Is it possible to create a JavaScript code that can be used across different sections of an HTML document? The goal is for the script to fetch data such as title, runtime, and plot from a specific URL request and insert this information into the appropriat ...

Tips for highlighting text in HTML without using a specific tag

My current project involves customizing a Wordpress plugin, but I've encountered a frustrating obstacle. I'm having trouble removing the three dots that appear at the bottom of the download card. Despite my efforts, I can't seem to find any ...

``Protect your PDF Document by Embedding it with the Option to Disable Printing, Saving, and

Currently, I am facing a challenge to enable users to view a PDF on a webpage without allowing them to download or print the document. Despite attempting different solutions like Iframe, embed, PDF security settings, and Adobe JavaScript, I have not been s ...

How to successfully transfer input data from a dialog to a controller using jQuery and Grails

As a newcomer to Grails and jQuery, I recently created a jQuery dialog following this example: http://jqueryui.com/dialog/#modal-form The goal is to open a dialog, input data, and have it displayed in a dynamic table on the main page. Once all entries are ...

Tips for maintaining selected text while a modal window is active

So I'm currently working on a document writer and I'm utilizing document.execCommand to insert links. What I aim for is the ability for a user to select/highlight text, click a button to add a link to that specific text (via a modal), and then ha ...

Can we execute a function once a mandatory field in a form has been validated successfully?

Looking for a way to execute a function after validating required inputs in a form before submission. Any suggestions? And I'm specifically not using jQuery, but Angular ...

The file reader feature is currently experiencing issues on both Chrome and Internet Explorer browsers

After uploading an image file from my PC, I convert it to a data URL and then use the img element to preview it. Surprisingly, this process works perfectly fine in Firefox. However, when I try to do the same in Chrome or IE, the src attribute of the img el ...

Adjusting font size according to the font style selected

Can conditional font size be determined based on font family using CSS or jQuery? ...

Set boundaries for the width and height of an image in the input field

Looking to restrict the size of an image in an input field using HTML, CSS, and JavaScript/jQuery. Goal is to maintain a perfect square aspect ratio for profile photo uploads (for example, 200x200 or 300x300). ...

Fixed position not being maintained after clicking the button

Looking for some help with a fixed header issue on my website. The header is supposed to stay at the top while scrolling, which works well. However, when I switch to responsive view, click the menu button, and then go back to desktop view, none of the po ...

Activate video in Slick Slider with the click of a button

I am facing an issue with my slider setup, where each slide contains a video as the background along with play/pause buttons. When I try to play the video by clicking the corresponding button on a specific slide, I encounter this problem: if I click the pl ...

Encountering a problem with quintus-all.js and need assistance

I am having an issue with my animation code. Can someone help me troubleshoot it? window.addEventListener('load', function(){ var Q =window.Q= Quintus().include("Sprites, Scenes,2D, Anim").setup({maximize:true}); Q.Sprite.extend(&apos ...

A guide on changing the style of a Layout component in React

Currently, I am utilizing Next.js alongside Material-UI as the framework of choice. Within my project, there is a Layout component that encapsulates the content with Material-UI's <Container>. I desire to customize the style of the Layout compon ...

Issue with Material-UI's DataGrid scrollbar not displaying on the screen

I have a DataGrid set up with at least 20 rows. My goal is to limit its height and allow users to navigate through the remaining rows using the scroll bar within the component. However, I'm facing an issue as the scrollbar for the DataGrid itself is n ...

How can I make my modal box appear after someone clicks on selecting a college?

Can someone help me figure out how to display my modal box after clicking into the selecting list? I've already coded it, but I'm struggling with getting it to show up after the click event. Any assistance is appreciated! In the image provided, ...

Struggling with the installation of SimpLESS

I encountered an issue while attempting to install SimpLESS on my Windows 7 64bit PC. Upon running the installer, I was met with an error message stating: "Could not query info: Invalid HTTP Status Code (403)". Despite my efforts to search for a solution o ...

Stylesheets per module in Angular 2

For my website design, I've decided to adopt a modular structure using sass. To ensure consistency throughout the module, instead of defining stylesheets at the component level, I plan to define them at the module level and import them into each compo ...

Animate CSS Grid to dynamically fill the viewport on top of current grid elements

Please note that I am specifically seeking vanilla JS solutions, as jQuery is not compatible with this project I have a grid structure that is somewhat complex: body { margin: 0; height: 100vh; text-align: center; } .grid-container { ...

Using Query strings in JavaScript: A Quick Guide

I recently completed a calculator project with only two pages. However, I am struggling to figure out how to pass input field values from one page to another. Despite trying multiple methods, nothing seems to be working. Does anyone know how to successful ...

What is the best way to make a linear gradient that spans the entire vertical space that is visible (or shifts to a solid color)?

I'm trying to figure out how to apply a linear gradient to the body element of my webpage. Here's the CSS code I've been using: body { background: linear-gradient(0deg, white, lightgray); } The issue I'm facing is that the gradien ...