"Implementing a responsive full-screen menu using Bootstrap for optimal user experience

I've implemented navbar-fixed-top and I want my menu items to expand to full width below the navbar when the user clicks on the burger-icon.

The expanded menu should cover the entire height of the screen, and the burger-icon should transform into an X-icon when the menu is open.

This functionality should work seamlessly on all devices.

You can view my development site and refer to the following mockup:

mockup

While I have managed to achieve the full width menu items, I'm looking for assistance in the following areas:

  • How to adjust the height of the expanded menu
  • How to change the burger icon to an X-icon when toggled.

Any suggestions or solutions would be greatly appreciated.

Answer №1

To begin, remove any fixed max-heights assigned to the .navbar-collapse class, as it is currently set to 340px. Instead, set the height of the navigation to 100vh.

.navbar-collapse {
    height: 100vh;
}

By doing this, the navbar will span the entire viewport height.

Next, for the button, consider using a font icon like Font Awesome and target the .collapsed class for the button state to display a different icon.

<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse" aria-expanded="false">
    <i class="icon fa fa-bars"></i>
</button>

Once this is done, replace the bars icon with an X icon to indicate closing.

.navbar-toggle.collapsed .icon:before {
    content: '\f00d';
}

If you prefer to stick with the default Bootstrap bars but want to animate them into an X, you can refer to this fiddle https://jsfiddle.net/gndkmc5y/

Simply assign the top, middle, and bottom classes to the bars to achieve the desired effect.

Answer №2

While Vedran Jaic's response was helpful, I found that it required a bit more tweaking to achieve the desired smooth animation effect. To address this, I added an empty absolute position div ('#navbar-expander') with a height of 100vh inside the navigation bar. This helped to set the height of the navbar during transitions, preventing any stuttering in the animation caused by the relative positioning of elements within the nav. Though there may be alternative methods to set the height, this approach worked for me and I opted to stick with it...

<div id='navbar' class="collapse navbar-collapse">
    <div class='navbar-expander'></div>
    <ul class="nav navbar-nav navbar-left">
            {{# each navLinks}}
            <li {{#ifeq ../section key}}class="active"{{else}}{{/ifeq}}>
                <a href="{{ href }}">{{ label }}</a>
            </li>
        {{/each}}
    </ul>
</div>

Subsequently, I adjusted the classes, incorporating Bootstrap transitions that would be added or removed as necessary (the following snippet exhibits the fullscreen nav exclusively on extra small devices, but the media query can be eliminated to apply it across all devices):

.navbar-expander{
    position: absolute;
    top:0px;
    left:0px;
    width: 100%;
    height:100vh;
    display:none;
}


@media screen and (max-width: $screen-sm-min) {

    .navbar-collapse, 
    .navbar-collapse.collapse,
    .navbar-collapse.in, 
    .navbar-collapse.collapsing{
        max-height: 100vh;  
    }
    .navbar-collapse.in{
        height: 100vh;
    }   

    .navbar-expander{
        display:block;
    }
}

Regarding the icon alteration, I found the snippets in the following link to be particularly effective, so I wanted to share them:

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

Using Selenium's findElement method along with By.cssSelector to locate elements with multiple classes

I'm a beginner with selenium. Can someone explain how to locate an element that has multiple classes and values? <div class="md-tile-text--primary md-text">Getting Started</div> using the findElement method By .css Selector. ...

Do you want your image to appear visually pleasing on all screen sizes?

Currently, I am working on a mobile website and encountering an issue with the image banner. For tablets, it should look like this: However, when viewed on mobile, it needs to appear as follows: This is the code I have implemented so far: <div class ...

Tips on changing the text alignment in ant design's Select with search field component within a Form item to support various languages

Is there a way to dynamically change the text direction in a search field based on the language being typed by the user? For example, switch the direction to rtl when typing in Arabic and to ltr while typing in English. I need to achieve this functionalit ...

Issue with adding HTML content to bootstrap modal not functioning as expected

Having trouble displaying an image in a bootstrap modal by using data- attribute within a php foreach loop. The image doesn't seem to appear in the target div. Here's my code snippet: <script> $(document).ready(function(){ $( ".subscri ...

Tips for creating a responsive floating page div

Hey there, I'm still fairly new to web development and have a question regarding a registration page that is displayed as a floating div above the main page. How can I ensure that this div is centered in a responsive way? The pages are separated and ...

How can I implement horizontal scrolling on a material-ui table containing numerous columns?

As I work with the React Material-UI framework, I am using this table example as a guide. However, I am facing an issue where my table becomes overcrowded when I have numerous columns, causing the content to be cut off. I recently came across the material ...

Prevent elements from overlapping within a flexbox container

I've encountered an issue with resizing the window causing the logos to overlap the portrait image. Is there a way to fix the logos relative to the portrait? Below is the code: /* Defaults for Main Part of Pages */ body, div, h1, p { margin: 0; ...

Recalling the position of the uploaded image within a v-for loop

I am struggling to solve this issue. Currently, I am utilizing Vue.js in an attempt to construct a dashboard where users can upload up to five images of visitors who are authorized to access a specific service provided by the user. Below is the code snip ...

Retrieving inline CSS value using jQuery

How do I retrieve the inline-css value of the second child within div #one using jQuery. <li id="one"> <h2>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Mollitia, velit!</h2> <div style="width: 1425px; height: 1080px ...

Utilizing props to define the background-color of the '&:hover' state

I'm adapting Material UI's Chip component to accept custom values for the colors prop, rather than being limited to "primary" and "secondary". Additionally, I want the chip to exhibit a hover effect when clicked, transitioning to a different colo ...

Arranging two stretchable div elements side by side

I'm currently working on a web page layout where I want two divs to be flexible and adjust their size as the browser window is resized. However, I've encountered an issue where instead of shrinking, the line breaks between the two divs when the w ...

Guide to adjusting the number of bounces using jQuery's User Interface (UI)

Check out my code on CodePen: http://codepen.io/Chiz/pen/jbwPLO (click anywhere in the blank area) I'm trying to figure out how to adjust the number of bounces a div makes before stopping. For example, I want the div to bounce 10 times and also chang ...

Only scroll the div if it is not within the visible window

I've been looking at this snippet: The sidebar division is what I'm focusing on right now. I want the div to scroll along as I scroll down the page, but I need it to stop scrolling when its bottom is in view. The same should apply when scrollin ...

Identifying a change in the source location of an iframe element

I am working with an iframe object that is currently set to a specific page's URL. Here is an example: <iframe src="http://en.wikipedia.org/wiki/Special:Random"></iframe> My goal is to display an alert whenever the location of the iframe ...

The progress indicator fails to activate during the first step

As a beginner in coding, I wanted to incorporate a progress bar on my website. However, I encountered an issue where when I try to make step 1 "active", it's actually step 2 that becomes active, and the same pattern continues for subsequent steps. ...

Implementing Jquery Table Selection with Custom CSS Class

When I attempted to use the selectable feature on a table with a CSS class applied, the selection did not work. However, when I removed the CSS class, the selection worked perfectly fine. I suspect that the issue lies within the CSS definition, but I' ...

Designing Progress Bars with CSS3

I'm currently working on enhancing the appearance of the progress bars across my website, all of which are built using jQuery UI. My goal is to achieve a design similar to the one shown below (featuring a stylish bevel effect and a visually appealing ...

What are the best strategies for ensuring this website is fully optimized for all devices

Hi there, I've been struggling to make the header on my website responsive, but it doesn't appear to be functioning properly. Any assistance would be greatly appreciated. <!DOCTYPE html> <html lang="en"> <head> <meta name="v ...

Issue with ng-cloak not resolving flicker on button in Chromium; strangely, ng-cloak CSS doesn't apply as expected

Here is a snippet of my HTML code: <button type="button" class="btn btn-primary ng-cloak" ng-click="ctrl.add(ctrl.userProfile.username)" ng-hide="ctrl.userProfile.added">Add</button> The code above is a part of the larger HTML document shown ...

Skrollr immediate pop-up notification

Can anyone help me figure out how to make text appear suddenly and then disappear using skrollr? I've been able to get it to fade in and out, but I want it to just show up without any transition. Here's the code I have so far: <div id="style" ...