Issue with Navigation Bar when reducing screen width

I'm currently working on creating a navbar that includes an image logo, title, navigation links, and social links. To achieve this, I've divided the navbar into 4 separate divs. However, I've noticed that when I decrease the screen width using responsive design, a white color appears in the nav bar and expands towards the left as the screen width decreases. Here are some images illustrating the issue:

You can also see the problem in action here: https://i.sstatic.net/xAFJN.png

Here's another visualization of the issue as I decrease the screen width: https://i.sstatic.net/6uFBU.png

/* Reset */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

@font-face {
  font-family: PollerOne;
  src: url('../../fonts/Poller_One/PollerOne-Regular.ttf');
}


/* Styling Navigation Bar */

#navbar {
  display: flex;
  position: relative;
  align-items: center;
  height: 65px;
  width: 100%;
}

#navbar::before {
  content: "";
  position: absolute;
  background-color: #262626;
  height: 65px;
  width: 100%;
  z-index: -2;
}

.navbar {
  color: white;
  margin: 7px 7px;
}


/* Styling Logo */

#logo {
  background-color: black;
  height: 45px;
  width: 45px;
  min-width: 45px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

#logo img {
  filter: invert();
  width: 25px;
}


/* Styling Title */

#title {
  font-family: PollerOne;
  min-width: 160.5px;
  font-size: 1.4rem;
  margin-left: 0px;
}


/* Styling Nav links */

#nav-links {
  margin: 0 auto;
}

#nav-links ul {
  list-style-type: none;
  display: flex;
}

.nav-links {
  font-size: 20px;
  margin: 0 20px;
  /* padding: 5px 10px; */
  position: relative;
  cursor: pointer;
}


/* Animation Under Nav Links */

.nav-links::after {
  content: "";
  position: absolute;
  width: 100%;
  height: 2px;
  bottom: -4px;
  background: linear-gradient(white 0 0) center/0% 100% no-repeat;
  display: block;
}

:hover.nav-links::after {
  animation: pulse 300ms linear;
  animation-fill-mode: forwards;
}

@keyframes pulse {
  to {
    background-size: 100% 100%;
  }
}


/* Styling Social Links */

#social-links {
  margin-left: auto;
  display: flex;
}

.social-links {
  width: 30px;
  height: 30px;
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 5px;
}

.social-links img {
  width: 27px;
  transition: all 200ms ease;
}

.social-links img:hover {
  transform: scale(1.5)
}


/* Utility Class */
<div id="navbar">
  <div id="logo" class="navbar">
    <img src="./img/bag.png" alt="">
  </div>
  <div id="title" class="navbar">Meals Point</div>
  <div id="nav-links" class="navbar">
    <ul>
      <li class="nav-links"><a id="link-1">Home</a></li>
      <li class="nav-links"><a id="link-2">About</a></li>
      <li class="nav-links"><a id="link-3">Services</a></li>
      <li class="nav-links"><a id="link-4">Recipes</a></li>
      <li class="nav-links"><a id="link-5">Contact</a></li>
    </ul>
  </div>
  <div id="social-links" class="navbar">
    <a class="social-links" href="https://www.twitter.com"><img src="./img/twitter.png" id="link-1"></a>
    <a class="social-links" href="https://www.facebook.com"><img src="./img/facebook.png" id="link-2"></a>
    <a class="social-links" href="https://www.instagram.com"><img src="./img/instagram.png" id="link-3"></a>
  </div>
</div>

Answer №1

One way to enhance the appearance of your website is to include the following CSS code to the #navbar element by adding float: left;:

/* CSS Reset */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

@font-face {
  font-family: PollerOne;
  src: url('../../fonts/Poller_One/PollerOne-Regular.ttf');
}

/* Styling for Navigation Bar */

#navbar {
  display: flex;
  position: relative;
  align-items: center;
  height: 65px;
  min-width: 100%;
  float: left;
}

#navbar::before {
  content: "";
  position: absolute;
  background-color: #262626;
  height: 65px;
  min-width: 100%;
  z-index: -2;
}

.navbar {
  color: white;
  margin: 7px 7px;
}

/* Styling for Logo */

#logo {
  background-color: black;
  height: 45px;
  width: 45px;
  min-width: 45px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

#logo img {
  filter: invert();
  width: 25px;
}

/* Styling for Title */

#title {
  font-family: PollerOne;
  min-width: 160.5px;
  font-size: 1.4rem;
  margin-left: 0px;
}

/* Styling for Navigation Links */

#nav-links {
  margin: 0 auto;
}

#nav-links ul {
  list-style-type: none;
  display: flex;
}

.nav-links {
  font-size: 20px;
  margin: 0 20px;
  /* padding: 5px 10px; */
  position: relative;
  cursor: pointer;
}

/* Animation for Navigation Links */

.nav-links::after {
  content: "";
  position: absolute;
  width: 100%;
  height: 2px;
  bottom: -4px;
  background: linear-gradient(white 0 0) center/0% 100% no-repeat;
  display: block;
}

:hover.nav-links::after {
  animation: pulse 300ms linear;
  animation-fill-mode: forwards;
}

@keyframes pulse {
  to {
    background-size: 100% 100%;
  }
}

/* Styling for Social Links */

#social-links {
  margin-left: auto;
  display: flex;
}

.social-links {
  width: 30px;
  height: 30px;
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 5px;
}

.social-links img {
  width: 27px;
  transition: all 200ms ease;
}

.social-links img:hover {
  transform: scale(1.5);
}

/* Utility Class */
<div id="navbar">
  <div id="logo" class="navbar">
    <img src="./img/bag.png" alt="">
  </div>
  <div id="title" class="navbar">Meals Point</div>
  <div id="nav-links" class="navbar">
    <ul>
      <li class="nav-links"><a id="link-1">Home</a></li>
      <li class="nav-links"><a id="link-2">About</a></li>
      <li class="nav-links"><a id="link-3">Services</a></li>
      <li class="nav-links"><a id="link-4">Recipes</a></li>
      <li class="nav-links"><a id="link-5">Contact</a></li>
    </ul>
  </div>
  <div id="social-links" class="navbar">
    <a class="social-links" href="https://www.twitter.com"><img src="./img/twitter.png" id="link-1"></a>
    <a class="social-links" href="https://www.facebook.com"><img src="./img/facebook.png" id="link-2"></a>
    <a class="social-links" href="https://www.instagram.com"><img src="./img/instagram.png" id="link-3"></a>
  </div>
</div>

Answer №2

Experiment by including

  1. To Align on the Left: class = "navbar-nav mr-auto"
  2. To Align on the Right: class = "navbar-nav ml-auto"
  3. To Align at the Center: class = "navbar-nav mx-auto"

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

Stuck with the same icon even after a successful AJAX call

I am currently working on implementing a 'add to my list' function in my web app. The goal is to change the color of an icon when a user clicks on it, after sending the necessary data to the server. Despite successfully sending the data to the s ...

Filter out all elements that come before the comma in the sorted array's output

Looking for a solution to modify my code so the output is just "Bothell" without the comma and count part. let As = document.getElementsByTagName('a'); let towns = new Map(); for(let a of As) { let town = a.textContent.split(',') ...

Spacing in CSS between the menu and its submenu elements

My current challenge involves creating space between the menu and the submenu. However, I've noticed that when there is this space, the submenu doesn't function correctly. It only works when the design has no gap between the menu and the submenu. ...

Having an issue with retrieving value from a textfield in JavaScript

<input id="checkOldPassword" type="button" title="Check New Password" value="Check New Password" onclick="checkPassword()" /> <input id="newPassword" type="text" maxlength="8" min="8" /> <script language="javascript"> function checkPassw ...

Nested Divs in CSS

I'm really struggling to get a div to display under another div in the way they usually do. Currently, I am using MaterializeCSS for my layout setup: <div class="container valign-wrapper"> <div class="customClass"></div> &l ...

The tooltip in Bootstrap v2.3.2 is causing words to be cut right in half

The tooltip plugin is set up like this: $("#id").tooltip({ placement: 'top', trigger: 'hover', html: true, container: 'body' }); Is there a way to prevent this from happening? Appreciate any insights. ...

Using a snippet of HTML code from one Angular component in another component

Is it possible to use a specific div element from one Angular component in another component? main component.html <html> <div1> some elements </div1> <div2> some elements </div2> In the child ...

Tips for generating AJAX requests directly from HTML documents

Hey there! I'm fairly new to JavaScript and have a question that might seem silly to some. How exactly can I invoke a function from a Coffeescript file within my HTML code? I'd like to give users the option to choose the language in which they v ...

Error: The Jquery plugin Object #<HTMLDocument> does not have a function called 'observe'

Hello, I recently tried to install the Jquery plugin known as chosen that allows customization of my <select> tag across different browsers. If you're interested, you can find more information about it here. However, after integrating this plugi ...

CSS: Indication that the Text is Extending Beyond its Container

Seeking a solution to indicate overflow of text within its container, as demonstrated in this example. Essentially, a <span> with fixed dimensions. Looking for a visual cue when text exceeds boundaries. Attempted the use of text-overflow:ellipsis;, ...

What are the steps to create a hovering dropdown menu that changes the background window to transparent when hovered over?

Is there a way to create a dropdown menu that changes the background window to transparent when hovered over? Here is an example of what I am looking for: https://i.sstatic.net/FplLm.png The dropdown menu should look like this when hovered over: https: ...

What is the best way to use absolute positioning in React Native to align an element with its grandparent?

I am trying to position a Font Awesome icon in a React Native project using absolute positioning relative to the grandparent element, rather than its direct parent. After some research, I came across the following information on this page: https://reactna ...

When it comes to designing responsive websites, the use of `@

Being new to CSS, I am open to criticism and feedback. @media (max-width: 735px) {... } @media (min-width: 735px) {... } @media (width: 320px) {... } @media (width: 360px) {... } @media (width: 375px) {... } @media (width: 414px) {... } I have tried us ...

Guide on aligning all list items to the left using React Material-UI, incorporating fontAwesome icons, and styling with Tailwind.css

I am trying to align the text of my list items to the left. Here is what I have currently: https://i.stack.imgur.com/a5o5e.png Is there a way to left-align the text in this code snippet? import React from 'react'; import PropTypes from 'p ...

Unable to create circular dots within the Slick Slider widget

While attempting to create a slider with dots, I encountered an issue where the dots appeared as ellipses instead of circles, despite setting the width and height to be the same. For instance, I specified width: 12px; height: 12px; but it resulted in a sha ...

Apply a specific image layout once the drop event occurs

I have a container with 5 image pieces that need to be dropped into another container to complete the image. Once an image is dropped, I want to apply the style "position:absolute" so that it sticks to the previous image in that container. Although I have ...

Is there a way to consistently maintain a specific column size in Bootstrap?

I'm currently working on a website and running into an issue that I can't seem to resolve. The problem lies in the layout of multiple cards with information; they are arranged in columns and when there are more than 4 columns, they switch to a ne ...

Learn how to create a logarithmic scale graph using CanvasJS by fetching data from an AJAX call

window.onload = function() { var dataPoints = []; // fetching the json data from api via AJAX call. var X = []; var Y = []; var data = []; function loadJSON(callback) { var xobj = new XMLHttpRequest(); xobj.overrideMimeType("applicatio ...

Issue with the image posting function in Laravel - why isn't it functioning properly?

Looking for Assistance I've been working on a simple web application using Laravel 6.0 and have encountered an issue with the image post function I developed. Despite not receiving any error messages, the functionality doesn't seem to be work ...

Traverse through an array of pictures and add the data to a Bootstrap placeholder within HTML markup

In my quest to create a function that populates placeholders in my HTML with images from an array, I am encountering a problem. Instead of assigning each image index to its corresponding placeholder index, the entire array of images is being placed in ever ...