Adapting content to fit a collapsed navigation sidebar using Bootstrap

Hello there! I'm new to CSS and bootstrap. I have a button that collapses the navigation sidebar, and I want the content of the page to float to the left when the sidebar is collapsed and shrink when it's expanded.

Can anyone please suggest a solution for this issue?

Here is the sample code I'm working with:

<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
    <div class="navbar-header "> 
      <button type="button" class="navbar-toggle visible-lg" data-toggle="collapse" data-target="#navbar-ex1-collapse">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
    <div class="collapse navbar-default navbar-collapse">
    <div  class="pull-left" id="navbar-ex1-collapse">
      <ul class="nav navbar-default navbar-nav side-nav">
        <li class="dropdown">
          <a href="#" class="dropdown-toggle " data-toggle="dropdown" style="background:rgba(59, 89, 152, 0.28);"><i class="fa fa-user"></i> My Profile <b class="caret"></b></a>
          <ul class="dropdown-menu">
            <li ><a class="dropdown-color" href="#" style="background:rgba(59, 89, 152, 0.28);" ><i class="fa fa-user"></i> View Profile</a></li>
            <li><a class="dropdown-color" href="#" style="background:rgba(59, 89, 152, 0.28);"><i class="fa fa-edit"></i> Edit Profile</a></li>
          </ul>
        </li>
        <li><a href="Dashboard.html"><i class="fa fa-dashboard"></i> Dashboard</a></li>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-desktop"></i> Deployment <b class="caret"></b></a>
          <ul class="dropdown-menu">
            <li><a href="#" style="background:rgba(59, 89, 152, 0.28);"><i class="fa fa-edit"></i> Deployment Parameter</a></li>
            <li><a href="#" style="background:rgba(59, 89, 152, 0.28);"><i class="fa fa-bar-chart-o"></i> Package Deployment</a></li>
            <li><a href="#" style="background:rgba(59, 89, 152, 0.28);"><i class="fa fa-bar-chart-o"></i> Release Deployment</a></li>
          </ul>
        </li>           
      </ul>
    </div>
      <ul class="nav navbar-nav navbar-right navbar-user">
        <li class="dropdown user-dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-user"></i> Username <b class="caret"></b></a>
          <ul class="dropdown-menu">
            <li><a href="#"><i class="fa fa-user"></i> View Profile</a></li>
            <li><a href="#"><i class="fa fa-gear"></i> Edit Profile</a></li>
            <li class="divider"></li>
            <li><a href="#"><i class="fa fa-power-off"></i> Log Out</a></li>
          </ul>
        </li>
      </ul>
    </div><!-- /.navbar-collapse -->

 <div class="auto-adjust" id="page-wrapper">

//table goes here

</div>

And here is the custom CSS class I created to adjust the content:

CSS:
 .auto-adjust{
  padding-right: 15px;
  padding-left: 15px;
  margin-right: auto;
  margin-left: auto;
  margin:0;
  float:left;
}

Answer №1

In the world of Twitters Less code, the navbar collapse is initially set by @grid-float-breakpoint (which is defaulted to 768px). You can now utilize CSS media queries to implement your code just before that breakpoint: less

@media (max-width: (@grid-float-breakpoint - 1)) { 
  padding-right: 15px;
  padding-left: 15px;
  margin: 0 auto;
  float:left;
}

The CSS output would look like this:

@media (max-width: 767px) {
  padding-right: 15px;
  padding-left: 15px;
  margin: 0 auto;
  float: left;
}

It's worth noting that leveraging Bootstrap's grid system might be a more efficient approach. Refer to http://getbootstrap.com/css/#grid-media-queries. The xs grid kicks in when the screen width is below 768 pixels. Give this code a shot:

<div class="row">
<div class="col-xs-12 col-sm-6">//table content goes here</div>
<div class="col-xs-12 col-sm-6">//other content</div>
</div>

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

Positioning canvas and navigation bar with CSS styling

I have a fixed position navigation bar at the top, and a canvas. Unfortunately, the top of my canvas is being hidden behind the navigation bar. I do not want to change the canvas position to absolute. I need to position the canvas below the navigation ba ...

Guide on creating a div container that spans the full width of the HTML page with a horizontal scrollbar

I'm facing an issue where the div container is not extending over the entire HTML page with a horizontal scroll bar. Here's a visual representation of my problem: Image Despite using MathJax to display math formulas, the div container does not ...

What is the best way to paste plain text into a Textarea without any formatting?

A challenge I am facing in my project is related to copying and pasting text into a Textarea. When a user copies text, the style of the text is also inserted along with it. However, when the user manually types the text, it gets inserted correctly without ...

Acquiring website form data through the hypertext transfer protocol

Looking to retrieve data from a basic HTML form (see code below) and transmit it to an API () which generates a hash out of the information. Here is the HTML form code: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" ...

Implementation of Django Registration Redux fails to recognize adjustments made to templates

For the past couple of weeks, I've been facing challenges with Django registration redux. Despite incorporating changes such as adding crispy forms and modifying buttons in accordance with the provided documentation, none of these updates reflect on m ...

Is there a way to eliminate browser-saved password suggestions using Material UI textfields?

"Is there a way to prevent browser suggestions in a Textfield within a form tag so that users must manually type their password without autocomplete options?" https://i.sstatic.net/Mub57.png "I attempted to use the 'autocomplete=" ...

struggling to correctly display json api data in javascript onto html

I am receiving a json API response from my JavaScript request. I can successfully print the output to the console and it appears properly formatted like this: { "id": "1", "name": "John" } However, when I try to display it on an HTML page, it looks l ...

Guide on inserting an item into a vertical navigation menu

When it comes to creating a vertical menu, I rely on Bootstrap 5. https://i.sstatic.net/8CWYK.png The issue I'm facing is how to add a black background to the top of the left menu. https://i.sstatic.net/yoEcO.png I am unsure whether I should imple ...

Is there a way to assign an id to a hyperlink when it is clicked in order to trigger specific CSS changes?

I am working on a navigation bar that includes links passing data through GET to display information from the database. The challenge is styling these links with the id 'selected' to show which one is currently active. <a href="./welcome.php? ...

What is the best way to position my div outside of the wrapper while keeping the text inside?

For example: https://i.sstatic.net/UyhOl.png I want the blue text that says "join our discord server" to extend to 100% width when it's placed inside the wrapper. The reason it's inside the wrapper is to ensure the text matches up perfectly with ...

I am unable to modify the suffix located beneath the price of the product

Although I am not well-versed in PHP, I managed to create a code to display parcel descriptions below the price of products. The issue I am facing is that my code is calculating too many decimal places and not displaying the default currency, which should ...

The carousal control icon in Bootstrap 4 is experiencing a configuration issue

I'm experiencing an issue with aligning the carousel controls in my Bootstrap4 slider. Below is the code I have written: .col-md-4 { display: inline-block; margin-left: -10px; } .col-md-4 img { width: 100%; height: auto; } body .carousel ...

Full-screen background with image adhering perfectly - left-aligned button that stays in place

Excuse me if my question seems basic, as I am just starting out in front-end development and may not know all the necessary terms to fully understand existing questions. I currently have a simple html file that consists of a title and three buttons, with ...

What is the best way to dynamically select and deselect radio buttons based on a list of values provided by the controller?

I am currently working on implementing an edit functionality. When the user initially selects a list of radio buttons during the create process, I store them in a table as a CSV string. Now, during the edit functionality, I retrieve this list as a CSV stri ...

Unexpected white space appears at the bottom of the page when rotating the device in iOS Safari

One issue I encountered on my website involves a meta tag: <meta name="viewport" content="width=device-width, initial-scale=1.0"> This, combined with height:100%; on the html and body tags, causes problems when viewed on Safari ...

jQuery UI's .position() function fails to account for the height of a target element that has been modified using jQuery

Hey there, experts! I have a question regarding my HTML code: <div class="full-height"> <h1>Lorem</h1> </div> Currently, I am using jQuery to set the height of div.full-height dynamically like this: $(document).ready(functio ...

Utilizing Bootstrap 4 to create fixed and fluid width side-by-side divs with scrollbars

I want to create a basic dashboard page. I decided to arrange two divs next to each other to serve as the side menu and content. Here is what the layout looks like: https://i.sstatic.net/EATK6.png I encountered an issue where the vertical scrollbar is n ...

Combining numerous base64 decoded PDF files into a single PDF document with the help of ReactJS

I have a scenario where I receive multiple responses in the form of base64 encoded PDFs, which I need to decode and merge into one PDF file. Below is the code snippet for reference: var pdf_base1 = "data:application/pdf;base64,JVBERi0xLjQKJfbk/N8KMSAwIG9 ...

Displaying a Flot chart with full width in a modal window using the Twitter Bootstrap framework and AngularJS

Utilizing Twitter Bootstrap AngularJS for my web app development, I am attempting to incorporate a real-time JQuery Flot chart within a modal window. The chart example I want to emulate can be found here: After copying the code from the provided link and ...

Tips for closing a sidecart by clicking outside of it

I am currently exploring how to implement the functionality of closing my sidecart when I click outside of it. Below is the script I am using: const toggler = document.getElementById('menu-toggle'); const cartWrapper = document.getElementById( ...