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

The text input field is unresponsive and unable to be selected in the mobile layout

I have implemented this <textarea> component within my web application <div class="col-xs-11 lessSpaceBetweenLine"> <textarea class="form-control actionitems" id="actionitems" name="actionitems" rows="2" pl ...

What steps should I take to eliminate the gap in my fixed bottom navbar?

I'm looking to revamp my menu layout by aligning the links with the social media icons and home button on the same line. The links are nested inside a div within the main navbar class (streetworn-demos), while the social media icons and homepage butt ...

Eliminating "www" from the domain name leads to a separate website

I am new to this. The lack of support from mediaTemple and my current hosting provider has been frustrating, so I am turning to stackOverflow for help. My issue is that entering "www" before the domain name or leaving it out leads to different servers. ...

Manipulating links using JQuery: avoiding the binding of new links

I need to update a website with 50 pages that currently doesn't use ajax, making it cumbersome to make edits since changes have to be made on all 50 pages individually. After removing duplicate HTML from all 50 pages, I'm facing some issues: fu ...

MySQL unable to access information entered into form

After creating a new log in / register template using CSS3 and HTML, I now have a more visually appealing form compared to the basic one I had before. To achieve this look, I referenced the following tutorial: http://www.script-tutorials.com/css 3-modal-po ...

How can the spacing between Angular Material's mat-card-content and mat-card-actions be adjusted?

I am creating a mat card layout where there are two separate cards within the main card's content section. However, when I add a button for the actions section of the main card, there is no spacing between these two sections. How can I create a vertic ...

React js web application facing excessive content problem

I am encountering an overflow issue with the styles sheet I'm using on mobile and tablet views, but it works fine on desktop view. Can anyone provide a solution to this problem? I am developing a ReactJS web app hosted on Firebase. When I include fewe ...

sticky placement changes when option is chosen

I'm experimenting with the CSS style called position: sticky and I've encountered an issue. Everything works perfectly until the select element is activated, causing the page to scroll back to the original position of the sticky element. <div ...

The PHP code embedded within the HTML document and triggered by an AJAX request failed to

Here is an example of my ajax call: function insertModal(link) { $.ajax({ url: link, cache: false, dataType: "text", success: function(data) { $("#modalInput").html(data); }, error: function (request, status, error) { ...

Video background is malfunctioning on Firefox and Internet Explorer

Currently, I am facing some issues with the JQuery plugin 'videoBG'. The problem is that when I view the video offline, it works perfectly in all browsers. However, once I go online, the video stops working in FireFox and IE. It seems like the sc ...

Basic media query does not affect div resizing or font changes in Chrome or Internet Explorer

I am facing an issue with a simple media query that is not working as expected in Chrome or IE, but strangely it works fine in FF. I have tried various formulations of the media query without success. Any assistance would be greatly appreciated. Below is ...

Troubleshooting a problem with Select Dropdown in HTML and PHP

Hello, I am encountering an issue with a dropdown box as shown below: function createDropdown( $name, array $options, $selected=null ) { /*** starting the select element ***/ $dropdown = '<select name="'.$name.'" id="'.$name.'" ...

Displaying a submenu upon hovering within its designated CSS region

I'm encountering an issue with my submenu. It's supposed to appear when hovering over the parent menu li, but it also shows up when the mouse hovers over its area. Let's take a look at some images. First screenshot below shows that it works ...

Ensure that the div remains fixed at the bottom even when multiple items are added

Following up on the previous question posted here: Sorting divs alphabetically in its own parent (due to many lists) I have successfully sorted the lists alphabetically, but now I need to ensure that a specific div with a green background (class: last) al ...

Proper HTML style linking with CSS

Describing the file structure within my project: app html index.html css style.css The problem arises when trying to link style.css as follows: <link rel="stylesheet" type="text/css" href="css/style.css"/> S ...

Executing a function with the initial click

Is there a way to run a function only on the first click, without having it run every time? I already have another function running on window.onload, so I can't use that. Both functions work fine independently, but not together. Right now, I'm ca ...

Error with Flask url_for when trying to play a video

I'm currently developing a Flask website and working on analyzing and displaying a video on the webpage. However, when I tried to input the direct path to the video source, it only displayed a black screen. I searched on Google, which suggested using ...

Eliminate excess space around images in Bootstrap

I have an image tag with a padding applied to it. I am using the Bootstrap CSS framework. Currently, there is a white background behind the image that I want to remove and make it partially transparent instead. The image is in PNG format, so I suspect the ...

Tips for eliminating annoying white space on petite gadgets with css programming?

Having an issue with my static html page where I am seeing white space on the right side when checking responsiveness. I have tried multiple solutions found here on stack overflow, including adding the following code: I attempted to add this inline: html ...

Guide to modifying the behavior of a dynamic dropdown menu

Jquery: $('body').on('change', '.combo', function() { var selectedValue = $(this).val(); if ($(this).find('option').size() > 2) { var newComboBox = $(this).clone(); var thisComboBoxIndex ...