How come my flex-box navigation bar is not collapsing as I shrink the browser window size?

I'm currently experimenting with FlexBox to enhance the design of my website, specifically focusing on creating a responsive and collapsible navigation bar for mobile users. I'm encountering issues with the flex commands in the .nbar class not working as expected. How can I go about solving this problem?

*{
  margin:0;
  font-family: 'Roboto', sans-serif;
}
.wrapper{
  width:100%;
  min-width: 960px;
  margin:0 auto;
  /*display:flex;
  align-items: flex-end;
  this is just for the night vision button to position better
  */
}
.parent{
  display:flex;
  flex-wrap: wrap;
  /*these two at the bottomr are optional to
  center them on the page
  max-width: 960px;
  margin:0 auto;*/
  max-width: 960px;
  margin: auto;
}

/*WE MISSED THE .ONE SELECTOR*/
.one{
  flex-grow: 1;
}
.title{
  text-align: center;
  position:relative;
  font-size: 50px;
  top:20px;
}

.header{
  height:100px;
  width:100%;
  order:0;
  border-bottom: 1px solid rgb(0,0,0);
}
.nav{
  width:100%;
  /*min-width: 900px;*/
  height:40px;
  border-bottom: 1px solid rgb(0,0,0);
  order:1;
}
.banner{
  width:100%;
  min-width: 960px;
  height:500px;
  color:white;
  background-color: rgb(0,0,0);
  order:3;
}
.boxOne{
  width:45%;
  min-width: 200px;
  height:300px;
  border-right: 1px solid rgb(0,0,0);
  order:4;
  padding: 5px;
  padding-left: 10px;
  padding-right: 10px;
  padding-top: 10px;
  border-left: 1px solid rgb(120,120,120);
  text-align: justify;
}
.boxTwo{
  width:45%;
  min-width: 200px;
  height:300px;
  order:4;
  padding: 5px;
  padding-left: 10px;
  padding-right: 10px;
  padding-top: 10px;
  border-right: 1px solid rgb(120,120,120);
}
.footer{
  width:100%;
  height:100px;
  border-top: 1px solid rgb(0,0,0);
  border-bottom: 1px solid rgb(0,0,0);
  border-right: 1px solid rgb(120,120,120);
  border-left: 1px solid rgb(120,120,120);
  order:5;
}
.nbar{
display:flex;
flex-wrap: wrap;
align-items: stretch;
flex-flow: wrap;
}
  .two{
    flex-grow: 0;
  }
      .home {
        order:1;
      }
      .services {
        order:2;
      }
      .testimonials {
        order:3;
      }
      .portfolio {
        order:4;
      }
      .contact {
        order:5;
      }
li {
  display:inline-flex;
  padding:10px 40px 10px 60px;
  font-size: 15px;
}
a:link {
    text-decoration: none;
    color:black;
}

a:visited {
    text-decoration: none;
    color:black;
}
a:hover {
  text-decoration: underline;
}
.disc{
  padding-left: 5px;
  padding-top: 5px;
  font-size: 10px;
  color: rgb(150,150,150);
}
.people{
  overflow: hidden;
  height:500px;
  width:960px;
}
/*.popup {
  background-color: white;
  height: 20px;
  width:90px;
  border: 1px solid rgb(255, 0, 0);
  position:fixed;
  bottom:0;
}*/
<!DOCTYPE html>
<html>
<!-- dockmann -->
<head>
  <link href="https://fonts.googleapis.com/css?family=Roboto:300" rel="stylesheet">
  <link rel="stylesheet" type="text/css" href="style.css" />
  <script src="jquery-3.1.1.min.js"></script>
  <script type="text/javascript" src="script.js"></script>
</head>
<body>
  <div class="wrapper">
    <div class="parent">
      <div class="one header">
        <p class="title">DOCKMANN</p>
      </div>
      <!-- end header -->
      <div class="one nav">
        <ul class="nbar">
          <li class="two home">
            <a href="www.dockmann.com">HOME</a>
          </li>
          <li class="two services">
            SERVICES
          </li>
          <li class="two testimonials">
            TESTIMONIALS
          </li>
          <li class="two portfolio">
            PORTFOLIO
          </li>
          <li class="two contact">
            CONTACT
          </li>
        </ul>
      </div>
      <!-- end nav -->
      <div class="one banner">
        <img class="people" src="image/macdesk.jpg" />
      </div>
      <!-- end banner -->
      <div class="one boxOne">
        <h2>Who we are...</h2>
        <br />
        Filler
      </div>
      <!-- end boxOne -->
      <div class="one boxTwo">
        boxTwo
      </div>
      <!-- end boxTwo -->
      <div class="one footer">
      <p class="disc">
      filler
      </p>
      </div>
      <!-- end footer -->

    </div>

    <!-- <button class="popup">
      Night Vision!
    </div> -->
  </div>

</body>
</html>

Answer №1

It appears that the issue is resolved by removing the min-width property from the .wrapper class and eliminating the min-height property from the navigation bar (.nav),

*{
  margin:0;
  font-family: 'Roboto', sans-serif;
}
.wrapper{
  width:100%;
  margin:0 auto;
  /*display:flex; align-items: flex-end; this is just for the night vision button to position better */
}
.parent{
  display:flex;
  flex-wrap: wrap;
  /*these two at the bottomr are optional to center them on the page
  max-width: 960px;
  margin:0 auto;*/
  margin: auto;
}

/*WE MISSED THE .ONE SELECTOR*/
.one{
  flex-grow: 1;
}
.title{
  text-align: center;
  position:relative;
  font-size: 50px;
  top:20px;
}

.header{
  height:100px;
  width:100%;
  order:0;
  border-bottom: 1px solid rgb(0,0,0);
}
.nav{
  width:100%;
  /*min-width: 900px;*/
  border-bottom: 1px solid rgb(0,0,0);
  order:1;
}
.banner{
  width:100%;
  min-width: 960px;
  height:500px;
  color:white;
  background-color: rgb(0,0,0);
  order:3;
}
.boxOne{
  width:45%;
  min-width: 200px;
  height:300px;
  border-right: 1px solid rgb(0,0,0);
  order:4;
  padding: 5px;
  padding-left: 10px;
  padding-right: 10px;
  padding-top: 10px;
  border-left: 1px solid rgb(120,120,120);
  text-align: justify;
}
.boxTwo{
  width:45%;
  min-width: 200px;
  height:300px;
  order:4;
  padding: 5px;
  padding-left: 10px;
  padding-right: 10px;
  padding-top: 10px;
  border-right: 1px solid rgb(120,120,120);
}
.footer{
  width:100%;
  height:100px;
  border-top: 1px solid rgb(0,0,0);
  border-bottom: 1px solid rgb(0,0,0);
  border-right: 1px solid rgb(120,120,120);
  border-left: 1px solid rgb(120,120,120);
  order:5;
}
.nbar{
display:flex;
flex-wrap: wrap;
align-items: stretch;
flex-flow: wrap;
}
  .two{
    flex-grow: 0;
  }
      .home {
        order:1;
      }
      .services {
        order:2;
      }
      .testimonials {
        order:3;
      }
      .portfolio {
        order:4;
      }
      .contact {
        order:5;
      }
li {
  display:inline-flex;
  padding:10px 40px 10px 60px;
  font-size: 15px;
}
a:link {
    text-decoration: none;
    color:black;
}

a:visited {
    text-decoration: none;
    color:black;
}
a:hover {
  text-decoration: underline;
}
.disc{
  padding-left: 5px;
  padding-top: 5px;
  font-size: 10px;
  color: rgb(150,150,150);
}
.people{
  overflow: hidden;
  height:500px;
  width:960px;
}
/*.popup {
  background-color: white;
  height: 20px;
  width:90px;
  border: 1px solid rgb(255, 0, 0);
  position:fixed;
  bottom:0;
}*/
<!DOCTYPE html>
<html>
<!-- dockmann -->
<head>
  <link href="https://fonts.googleapis.com/css?family=Roboto:300" rel="stylesheet">
  <link rel="stylesheet" type="text/css" href="style.css" />
  <script src="jquery-3.1.1.min.js"></script>
  <script type="text/javascript" src="script.js"></script>
</head>
<body>
  <div class="wrapper">
    <div class="parent">
      <div class="one header">
        <p class="title">DOCKMANN</p>
      </div>
      <!-- end header -->
      <div class="one nav">
        <ul class="nbar">
          <li class="two home">
            <a href="www.dockmann.com">HOME</a>
          </li>
          <li class="two services">
            SERVICES
          </li>
          <li class="two testimonials">
            TESTIMONIALS
          </li>
          <li class="two portfolio">
            PORTFOLIO
          </li>
          <li class="two contact">
            CONTACT
          </li>
        </ul>
      </div>
      <!-- end nav -->
      <div class="one banner">
        <img class="people" src="image/macdesk.jpg" />
      </div>
      <!-- end banner -->
      <div class="one boxOne">
        <h2>Who we are...</h2>
        <br />
        Filler
      </div>
      <!-- end boxOne -->
      <div class="one boxTwo">
        boxTwo
      </div>
      <!-- end boxTwo -->
      <div class="one footer">
      <p class="disc">
      filler
      </p>
      </div>
      <!-- end footer -->

    </div>

    <!-- <button class="popup">
      Night Vision!
    </div> -->
  </div>

</body>
</html>

Answer №2

My experience has shown that the li tag does not function properly with flex-wrap, causing all 'li's to remain in a single line. To resolve this issue, make the following adjustment:

<ul class='nbar'>
  <li>menu1</li>
  <li>menu2</li>
</ul>

Replace it with:

<div class='nbar'>
  <div>menu1</div>
  <div>menu2</div>
</div>

This solution should work effectively. Additionally, remember to use -webkit- for flex properties as some mobile browsers require this. For example:

display:-webkit-flex;
-webkit-flex-wrap: wrap;

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

Issue with clearTimeout function not functioning properly on keyup event in iFrame

While there may be many similar questions out there, I have yet to find a solution that works for me. Currently, I am developing a WYSIWYG editor and I want it to save when the user performs a keyup action. However, I do not want it to update after every ...

How to customize the color of radio buttons in JFXRadioButton using CSS

I am facing an issue with customizing the styling of JFXRadioButton component from this library : jfoenix.com I want to modify the color of the circle, but the default class is not working. Are there any suggestions or solutions available? (The colors me ...

Is there a way for me to set a default filename when saving an HTML page?

On my webpage, such as www.example.com/NYSE/rates, I want to give the user the option to save the HTML they see on their local disk. When they click "Save as", I would like to automatically set the default filename to be NYSE_rates_09_12_2011.html. This fi ...

Retrieve all data points if both latitude and longitude are present in the XML dataset

XML data to retrieve details <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <results> <result> <Country_Code>IN</Country_Code> <Country_Name>India</Country_Name> <Region_Nam ...

Is there a way to trigger a function with ng-click in my AngularJS directive?

I am struggling to understand how to invoke a function from my directive using ng-click. Here is an example of my HTML: <div> <directive-name data="example"> <button class=btn btn-primary type="submit" ng-click="search()"> ...

I encountered a problem in Javascript where I was unable to get the video.getCurrentTime() function to display the current time of

While everything else in my code is running smoothly with setInterval, there seems to be an issue with video.getCurrentTime() not displaying in the div id = "test" when the video is playing. I've been trying to figure out why this is happening. Here&a ...

Is organizing a table into separate sections helpful?

I'm currently working on a personal project using Material UI, but I have a more general query regarding table implementation. I have designed a layout in Figma that I like, but I am struggling to translate it into code. https://i.sstatic.net/NoWEB.p ...

Can you provide an example of JSON for a MultiStep Form that includes a variety of control types for viewing

Could someone please provide me with JSON examples of multi-step forms that include various types of controls such as radio buttons, checkboxes, dropdown menus, and calendars? I am in need of JSON for both the view and edit forms. Your help would be grea ...

Tips for displaying and hiding content in Angular2

I have a component that toggles the visibility of elements by clicking a button. This is the snippet of my HTML code: <div *ngFor="let history of histories | sortdate: '-dateModified'"> <p><b>{{ history.remarks }}</b& ...

Guidelines for dynamically displaying <router-link> or <a> in Vue based on whether the link is internal or external

<template> <component :is="type === 'internal' ? 'router-link' : 'a'" :to="type === 'internal' ? link : null" :href="type !== 'internal' ? link : null" > <slot /> < ...

Obtain the value of the background image's URL

Is there a way to extract the value of the background-image URL that is set directly in the element tag using inline styling? <a style="background-image: url(https:// ....)"></a> I attempted to retrieve this information using var url = $(thi ...

When selecting an option in the burger menu, the dropdown does not react properly

I am facing an issue with the burger menu where one of the options should trigger a dropdown, but the content is not adjusting properly. The dropdown menu should push the other content downward, but currently, it overlaps. I have included the code for th ...

Clicking to remove added child element

I have written a script that creates an image popup when the site loads. Here is the code: <script type="text/javascript"> function showPopup() { var div = document.createElement('div'); div.className += 'popup'; div.inne ...

What is the best way to define relative paths for content like CSS files?

Whenever I link to a file, I always find myself having to include the entire absolute path like this <link rel="stylesheet" type="text/css" href="F:/XmppOld/XAMPP2/htdocs/MAIN_SITE_LAYOUT/css/stylemainpage.css" /> I want to simplify it to ...

Unknown CSS element discovered: bootstrap, gradient, carousel

I recently created a random quote app using javascript, jQuery, and bootstrap on Codepen. Everything worked perfectly there. However, when I organized the files, pushed them to git, and tried to view the app from Safari, I encountered some warnings and t ...

Customize your website with CSS and Bootstrap: create a transparent navbar-wrapper

Is there a way to make the menu bar background transparent without affecting the transparency of the text on the menu bar? This template is based on Twitter Bootstrap carousel. In this specific line, <div class="navbar navbar-inverse navbar-static-to ...

What is preventing the addition of links to the navigation bar when using a sticky navigation bar?

Currently, I am in the process of developing a blog website using Django. One of the features I have successfully implemented is a sticky navigation bar. However, I am facing a challenge with adding links to the menu on the navigation bar due to existing ...

jQuery live DataAttribute manipulation

Here is the code snippet I am working with: <head runat="server"> <title>Sidebar</title> <link href="css/style.css" rel="stylesheet" /> <script src="scripts/jquery-1.11.1.min.js"></script> <script src ...

Using JavaScript, aim for a specific element by its anchor headline

I'm looking to make some changes to my navigation menu, specifically hiding the home menu item unless the mobile navigation menu is toggled. Is there a way for me to target the "home" anchor title and apply the active class to it when toggled, similar ...

Finding the precise top offset position with jQuery upon scrolling – a step-by-step guide

I need help with detecting the offset top of a TR element when it is clicked. It works fine initially, but once the page is scrolled, the offset().top value changes. How can I resolve this issue? $(function() { $('tr').click(function() { ...