I have been working on creating a horizontal menu, but encountered an issue where the nav tag is unable to accommodate all the ul lists within itself

My latest project involves a menu with three separate divs: logo, nav-bar, and right-bar. I decided to use justify-content: space-around to position the elements - the logo on the left, navigation in the center, and right-bar on the right. However, when I applied white-space: nowrap to the links and added margin: 0 10%, my li elements ended up outside of the nav tag. How can I go about fixing this issue?

For reference, here is the link to the codepen: https://codepen.io/kartegi/pen/xxVzPLm?editors=1100

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  text-decoration: none;
  list-style-type: none;
}

.menu {
  display: flex;
  align-items: center;
  justify-content: space-around;
  width: 100%;
  height: 80px;
  background: green;
}

a {
  white-space: nowrap;
  color: #fff;
}

nav {
  background: red;
}

.menu-list {
  display: flex;
  background: #000;
  margin: 0 2.5%;
}

li {
  margin: 0 10%;
}

.right-bar {
  display: flex;
}

.search {
  width: 20px;
  height: 20px;
  background: #000;
}

.language {
  width: 20px;
  height: 20px;
  background: #fff;
}
<div class="menu">
  <div class="logo">
    <a href="">Click me</a>
  </div>
  <nav class="navbar">
    <ul class="menu-list">
      <li><a href="#">About me</a></li>
      <li><a href="#">My compony</a></li>
      <li><a href="#">News</a></li>
      <li><a href="#">Media</a></li>
      <li><a href="#">Contact</a></li>
    </ul>
  </nav>
  <div class="right-bar">
    <div class="search">
    </div>
    <div class="language">
    </div>
  </div>
</div>

Answer №1

Within your ul list, you can find the li element. To make the most of available width for your .navbar, simply add "flex: 1 1 auto;". Next step involves managing the width and spacing of elements.

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  text-decoration: none;
  list-style-type: none;
}

.menu {
  display: flex;
  align-items: center;
  justify-content: space-around;
  width: 100%;
  height: 80px;
  background: green;
}

a {
  white-space: nowrap;
  color: #fff;
}

nav {
  background: red;
}

.menu-list {
  display: flex;
  background: #000;
  margin: 0 2.5%;
}

li {
  margin: 0 10%;
}

.right-bar {
  display: flex;
}

.search {
  width: 20px;
  height: 20px;
  background: #000;
}

.language {
  width: 20px;
  height: 20px;
  background: #fff;
}
.navbar{
  flex: 1 1 auto;
}
<div class="menu">
  <div class="logo">
    <a href="">Click me</a>
  </div>
  <nav class="navbar">
    <ul class="menu-list">
      <li><a href="#">About me</a></li>
      <li><a href="#">My compony</a></li>
      <li><a href="#">News</a></li>
      <li><a href="#">Media</a></li>
      <li><a href="#">Contact</a></li>
    </ul>
  </nav>
  <div class="right-bar">
    <div class="search">
    </div>
    <div class="language">
    </div>
  </div>
</div>

Answer №2

Are you seeking this specific solution?

You may want to experiment with using flex-direction: column; on your .navigation

or alternatively,

consider adding flex-wrap: wrap; to allow elements to wrap within the given area.

Answer №3

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  text-decoration: none;
  list-style-type: none;
}

.menu {
 
  display: flex;
  align-items: center;
  justify-content: space-around;
  height: 80px;
  background: green;
}

a {
  white-space: nowrap;
  color: #fff;
}

nav {
  background: #fff;
}

.menu-list {
  display:flex;
  align-items: space-between;
  background-color: black;
}

li a{
  padding:20px; /* remove margin from li and give padding on anchor tag */
}

.right-bar {
  display: flex;
}

.search {
  height: 20px;
  background: #000;
}

.language {
  background: #fff;
}

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

AngularJS enables you to easily manipulate image width and height using the ng-file-upload feature

Seeking assistance with validating image width and height based on a 1:3 ratio prior to uploading using ng-file-upload. The validation should occur before sending the image to the server. Unsure how to retrieve the dimensions of the selected image for val ...

Utilizing the child element's attribute value in a list to dynamically modify the CSS styling of a div element

I'm struggling with designing a ranking bar that consists of 9 bars. I want the height of the bars to vary, with bar 0 and bar 8 being the longest. However, I am having difficulty manipulating my jQuery selector to change the CSS style of the bars bas ...

What is the method to advance the opposing line in the dynamic chart?

Here is the link to the code for a dynamic graph. I am struggling with keeping the red line updated and moving forward together with the blue line. I cannot figure out why the red line remains static in the dynamic graph. Any suggestions on how to solve t ...

Is it possible to scroll a div on mobile without the need for jQuery plugins?

Upon investigating the initial query, we managed to implement D3js for identifying a scroll event. This allowed us to scroll the div #scroll-content from any location on desktop devices. However, we encountered an issue where this method does not function ...

extract the content of CSS pseudo-elements using Python or Selenium

Currently, I am working on automating a web service using Selenium and Python. My ultimate goal is to extract the text "test" located below. However, I am facing some challenges in figuring out if this is feasible through Selenium or any Python library. & ...

Tips for inserting information into HTML components in JSP

Hey everyone, I'm diving into JSP for the first time and I'm trying to wrap my head around how to display data from an ArrayList in my HTML. Can someone help me out? I'm thinking of doing something like this: <article> <p>< ...

The Vue component that was added dynamically is failing to render

When I have a section of HTML with Vue components inside it, coming from a server, and then insert it on the page by clicking a button, the components are not rendering or showing up. Here is the HTML that gets inserted when the button is clicked: <sec ...

Zebra lines overlooking unseen details

Imagine having a table where rows can be dynamically assigned classes such as .hidden, which hide those rows using CSS. The rows are styled with alternating colors, like this: tr:nth-child(even) { background-color: $light-grey; } But here's the ...

Is it possible to swap two classes with each other using jQuery?

I am trying to implement a tree view with the following code snippet. Within the tree view, there are spans that have either the CollOpen or CollClosed class assigned to them. How can I toggle between these two classes on click for each span? .tree ...

Concealing and Revealing a Div Element in HTML

Every time the page is refreshed, I am encountering a strange issue where I need to double click a button in order to hide a block. Below is the code snippet for reference: <!DOCTYPE html> <html> <head> <meta name="viewport&quo ...

What is the best way to loop through jsoup elements while skipping the initial two results?

Extracting desired data from the following HTML snippet: <div class='col5'> <strong><a href="/stellenangebote/107278-supporter-sap-crm?page=1&amp;query%5Bcity%5D=&amp;query%5Bradius%5D=100&amp;query%5Btext%5D=SOA+SAP" ...

Sending Data in Angular JS

Looking for guidance on Angular JS as a newcomer. I have set up a form on my index.html page, and when the user fills in the details and hits submit, I want it to redirect to a details.html page where all the filled-in information can be displayed. HTML ...

Which JQuery plugins can transform regular <select> dropdowns into more stylish options?

After an extensive search, I was only able to locate one solution at this link. I scoured the entire internet for alternatives. ...

Styling the footer of a webpage using CSS to adapt to different browser

I am currently working on a webpage that includes a footer. The footer is positioned correctly, but I encounter an issue when resizing the browser from bottom to top. For further details, please refer to the image below: Below is the CSS code for my foote ...

Transfer a file from the file:///var/mobile/Applications/ directory to an accessible location for reading in Cordova/PhoneGap

I have a unique 'whitelabel' app that customizes itself for each client by downloading image files from a configuration server. However, I am facing an issue where the images are not displayed and instead showing a "Not allowed to load local reso ...

Invoke a PHP function from a class located in a separate file using an HTML button

I have an HTML input form with a SAVE button at the end. I want the SAVE button to trigger a PHP function written in a separate class file. The PHP code at the beginning of the file nabava_vnos.php that contains the HTML form: <?php // Script for sta ...

Methods like jQuery blink(), strike(), and bold() offer dynamic ways to manipulate

I'm currently tackling an inquiry. The code I crafted seems to be functioning without any issues: (function () { if($('#target:contains("bold")')) { $('#target span:first').css('font-weight','bold ...

Challenges arise when trying to load CSS on an EJS page in conjunction with using res.redirect()

When using Express with EJS, my base route is set as follows: router.get("/", productsData.getProducts); The "productsData" is sourced from my controllers page and the code snippet within that page is as follows: exports.getProducts = (req, res, next) => ...

Implement a delay for updating the style of a button by using the setTimeout function

Is it possible to create a button that, when clicked, changes color to green and then reverts back to its original style after 3 seconds? I am able to change the button color using an onClick event in my script. However, I encounter scope errors when tryi ...

Troubleshooting a Hover Problem in Firefox

Chrome is rendering the following code perfectly fine, but Firefox seems to be having trouble applying the hover effect. HTML <!DOCTYPE html> <html> <head> <link type="text/css" rel="stylesheet" href="stylesheet.css"/> ...