What's the best way to utilize Bootstrap 4 flexbox to ensure that a sidebar column menu smoothly transitions into a top column menu when viewed on a mobile device?

I would like the menu to always be displayed as a column, regardless of the screen size. Currently, it switches to a horizontal top layout and then wraps to two rows before becoming a column on smaller screens. I want it to stay as a column at all times and only switch to a top menu when the screen is too small for the sidebar.

Here is the HTML code:

<div class="container h-100">
<div class="row h-100">
    <!-- left sidebar -->
    <div class="col-lg-2 fixed pl-0 py-3 ">

        <ul class="nav flex-md-column ">
            <li class="nav-item">
                <a class="nav-link" href="#">aaaaaaaaaaaaaaa</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#">aaaaaaaaaaaaaaaaaaaaaaa</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#">dddddddddddddddddddddddd</a>
            </li>

        </ul>

    </div>
    <!-- center content -->
    <div class="sc-content col fluid bg-faded ">


        <h4 class="mt-3">Now that Bootstrap 4 has a flexbox grid it's much easier to create a fixed-fluid layout like this one.</h4>
        <p>Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>
        <p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem
            quia voluptas sit aspernatur aut odit aut fugit, sed quia cor magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius
            modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur?</p>
        <p>What will you do with this new awesomeness in Bootstrap 4?</p>

    </div>
   <div class="col-lg-2 fixed py-3">
        <!---leave nothing here, just to make text centered. Alternatively, add a right sidebar later.-->
    </div> 
</div>

Answer №1

Make the most of the flex-column built-in class https://getbootstrap.com/docs/4.0/utilities/flex/#direction

Adjust the direction of flex items in a flex container using direction utilities. Usually, you can skip the horizontal class since the default is row. But there are scenarios where specifying the value explicitly is necessary (like for responsive layouts).

Employ .flex-row for a horizontal direction (default), or .flex-row-reverse to initiate the horizontal direction from the opposite side.

<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container h-100">
<div class="row h-100">
    <!-- left sidebar -->
    <div class="col-lg-2 col-sm-12 fixed pl-0 py-3 ">

        <ul class="nav flex-column ">
            <li class="nav-item">
                <a class="nav-link" href="#">aaaaaaaaaaaaaaa</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#">aaaaaaaaaaaaaaaaaaaaaaa</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#">dddddddddddddddddddddddd</a>
            </li>

        </ul>

    </div>
    <!-- center content -->
    <div class="sc-content col fluid bg-faded ">


        <h4 class="mt-3">With Bootstrap 4's flexbox grid, creating a fixed-fluid layout like this becomes much simpler.</h4>
        <p>Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>
        <p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem
            quia voluptas sit aspernatur aut odit aut fugit, sed quia cor magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius
            modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur?</p>
        <p>How will you make use of this new feature in Bootstrap 4?</p>

    </div>
   <div class="col-lg-2 fixed py-3">
        <!---leave nothing here, just to make text centered. Alternatively, add a right sidebar later.-->
    </div>

You could also utilize col-sm-x classes to expand the navigation, based on my understanding of the other part of the question.

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

How can I center align text after floating ul li elements to the left?

When creating a navigation bar with li elements floated left, the text also floats left. How can I center the text in the navigation bar? I have tried using text-align:center;, but it doesn't center the text on the y-axis. Some suggest using padding t ...

Removing data from database with ajax

I am encountering an issue with deleting records from my database using ajax and jquery. When I click the button, nothing happens. Here is the relevant css code: <button class='delete_p' id_p='<?php echo $post_id; ?>'>x< ...

Resolving the Material-UI NextJS Button Styling Dilemma

I've encountered an issue with the styling of a few buttons in JS. When I apply a styling class using className, the formatting works fine on the initial render but loses its styling on subsequent refreshes. This problem is specific to two individual ...

Empty screen appears when "npm run serve" command is executed following the build process

I am currently utilizing Material-ui. Following the project build with npm run build, I encounter a blank page when running npm run serve. I attempted to set homepage: "./" in the package.json as suggested here, however, it still displays a blank ...

Automatically filling out a Pug form using an Express/Node.js web application

My Node.js web app is created with Express and I am attempting to populate a Jade template after querying MongoDB. The goal is to fill the Jade template with the queried values. One thing that puzzles me is that even when I remove everything within the co ...

Creating a basic tree structure menu on a webpage can be achieved using either PHP or HTML alone, no JavaScript

Looking to develop a basic tree menu using only PHP or HTML, without the use of any JavaScript. Constraints prevent me from including JavaScript in this project. ...

When hovering over .nav-item, the nav-link color remains unchanged

Is there a way to modify the code below to change the color of a navbar item to red when it is hovered over? .nav-item.active .nav-link{ color: blue !important; } .nav-item.hover .nav-link{ color: red !important; } ...

Tips for maximizing bootstrap efficiency by eliminating unnecessary CSS code during rendering

Currently, we are developing an MVP using vue.js and have chosen to incorporate bootstrap for consistent styling of the elements on our single-page app. As we begin to implement the skin/theme into our application, we have encountered an issue with unnece ...

Tips for enabling browser back and forward functionality in a one-page website design

Building on the previous discussion about optimizing a horizontal sliding layout (Most efficient way to do a horizontal sliding layout), I'm curious if it's feasible to enable the back and forward buttons in the browser when implementing a single ...

What is the best method for transferring a value in PHP?

I have two important files: an HTML file and a PHP file. The index.html uses AJAX to send a value to the php script. What I need is for servo.php to write every value it receives from index.html into the /dev/servoblaster file. You can access the files he ...

What is the best way to combine text with a PayPal field variable?

We recently encountered an issue with our standard PayPal Form implementation for online payments. Our form includes a field for customers to input a pickup date/time, using the passthrough variable "invoice" as recommended in the PayPal Docs. Everything w ...

What steps should I take to troubleshoot and fix the issue of data insertion errors in

https://i.sstatic.net/VccFk.jpg I am encountering an issue with a PHP form that is supposed to transfer information to a database after submission. However, every time I press the submit button, I receive an error message. Can anyone help troubleshoot th ...

Display a loading message using jQuery Dialog when the page is loading

I have a button that triggers a jQuery Dialog box to open. $( "#dialog" ).dialog({ autoOpen: false, title: 'Contract', height: 450, width:1100, modal:true, resizable: true }); $( ".btnSend" ).click(function() { var id=$(this).a ...

aligning an icon in the middle of its container

I'm having trouble centering an icon vertically inside its box only. I've tried using vertical-align: middle; but it doesn't seem to be working. I also attempted the line-height method, but the icon has an outer border that stays attached to ...

The act of linking an SVG image from the same SVG file can result in the disappearance

Can anyone help me figure this out? I'm facing a strange issue: <svg aria-hidden="true"> <use xlink:href="/assets/icons/utility-sprite/svg/symbols.svg#down"></use> </svg> <table> <tr> <td> ...

What is the process for implementing transitions using SASS?

When the pointer hovers over it, the transition effect kicks in smoothly. However, it reverts back to its original size abruptly when the mouse pointer is no longer hovering over it. What I aim for is for the cardLink to scale smoothly ...

How can I dynamically alter the color of a table row without using _rowVariant?

I am utilizing a bootstrap-vue table to showcase information retrieved from a JSON file. One piece of information I receive is an integer labeled "Status", and I aim to adjust the row's color based on this variable. For instance, if the Status equals ...

The container is not showing the JSTree as expected

My current project in JavaScript involves integrating a JSTree structure, but I'm encountering an issue where the tree is not showing up or rendering within its specified parent container. Below is the snippet of code I have been using to attempt to d ...

Ways to stop a hyperlink from executing on confirmation cancel using jquery

I'm having trouble with a link that should not perform any action when the cancel button is clicked. I've attempted to use false in the click event and also tried using e.preventDefault, but I'm unsure if I am implementing it correctly. Can ...

Execute a jQuery script within an iframe on a webpage by triggering it with an onclick event from a

I have a homepage with two iframes. One of the iframes contains links: <a href="home.html" target="content" onclick="run.slimmscroll(#anchor1);">Home</a> <a href="home.html" target="content" onclick="run.slimmscroll(#anchor2);">Home</ ...