Struggling to align the push menu properly within the Bootstrap framework

I am currently utilizing Bootstrap as my UI framework and attempting to create a push menu on the left side of the page. While I have made progress towards achieving this goal, there are some bugs in the system that I am encountering. Specifically, I am having trouble getting the menu to align inline properly. Below is the code for reference:

HTML

<div id="calendar-wrapper">
    <div class="container-fluid">
        <div class="row">

            <div id="resource-bar" class="sidenav col-sm-2">
                <h4>Resource</h4>
                <div class="input-group">
                    <input type="text" placeholder="Search resource"
                           class="form-control resource-filter"/>
                    <span class="input-group-btn">
                            <button class="clear btn btn-default clean-resource btn-danger" type="button">
                                <span class="glyphicon glyphicon-remove"></span>
                            </button>
                        </span>
                </div>

                <div id="popover-content" hidden></div>
            </div>

            <div id="calendar-container" class="col-sm-10">
                <div id="calendar" class="well"></div>
            </div>

        </div>
    </div>
</div>

<br><br><br>
<button type="button" id="show" >Show</button>
<button type="button" id="hide" >Hide</button>

Note that the HTML provided above has been modified for demonstration purposes.

CSS

.sidenav
{
    background-color: azure;
    height: 100%;
    width: 0;
    z-index: 1;
    top: 0;
    left: 0;
    overflow-x: hidden; 
    transition: 0.5s;
}

#calendar-container
{
    background-color: whitesmoke;
    transition: margin-left .5s;
    padding: 16px;
}

JS

$(document).ready(function()
{
    var resourceContainer = $('#resource-bar');
    var calendarContainer = $('#calendar-container');

    $('#show').click(function()
    {
        resourceContainer.css('width', '250px');
        calendarContainer.css('margin-left', '250px');
    });

    $('#hide').click(function()
    {
        resourceContainer.css('width', '0px');
        calendarContainer.css('margin-left', '0px');
    });
})

When the left-side menu is closed, the layout appears as follows:

https://i.stack.imgur.com/gNxi1.png

The issue arises when the "show" button is clicked, causing the menu to appear:

https://i.stack.imgur.com/Ej5sa.png

Bugs noted include:

  1. Upon opening the menu, the divs display in two lines instead of one row
  2. Applying the class col-sm-2 to resource-bar means that the overflow-x: hidden; property does not take effect, resulting in the menu being visible when it should be hidden
  3. The col-sm-2 element does not wrap to a new line when the screen resolution is insufficient in width

If anyone could provide assistance in resolving these issues, it would be greatly appreciated. Thank you. JSFIDDLE.

Answer №1

Adjusted to a different workaround that avoids impacting the bootstrap grid system:

  • In this configuration, the sidebar is set to an absolute position because it's outside the viewport and has a fixed width of 250px; therefore, using the grid system is not required.
  • The visible input will not overflow when the sidebar is displayed.
  • Raised the buttons above the sidebar.
  • It's important to note that the HTML structure has been modified accordingly.

$(document).ready(function() {
  var resourceContainer = $('#resource-bar');
  var calendarContainer = $('#calendar-container');
  $('#show').click(function() {
    resourceContainer.css('width', '250px');
    calendarContainer.css('margin-left', '250px');
  });
  $('#hide').click(function() {
    resourceContainer.css('width', '0px');
    calendarContainer.css('margin-left', '0px');
  });
})
div.sidenav {
  background-color: azure;
  height: 100%;
  width: 0;
  z-index: 1;
  top: 0;
  left: 0;
  overflow-x: hidden;
  transition: 0.5s;
  /* added absolute to sidenav since it will have fixed width anyways */
  position: absolute;
}
#calendar-container {
  background-color: whitesmoke;
  transition: margin-left .5s;
  padding: 16px;
  /* this is just to vertically align with sidebar input */
  padding-top: 36px;
}
button {
  position: relative;
  z-index: 2;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div id="calendar-wrapper">
  <div class="container-fluid">
    <div class="row">
      <div id="calendar-container" class="col-sm-12">
        <div id="calendar" class="well"></div>
      </div>
      <div id="resource-bar" class="sidenav">
        <h4>Resource</h4>
        <div class="input-group">
          <input type="text" placeholder="Search resource" class="form-control resource-filter" />
          <span class="input-group-btn">
            <button class="clear btn btn-default clean-resource btn-danger" type="button">
              <span class="glyphicon glyphicon-remove"></span>
            </button>
          </span>
        </div>
        <div id="popover-content" hidden></div>
      </div>
    </div>
  </div>
</div>
<br>
<br>
<br>
<button type="button" id="highlight">Highlight</button>
<button type="button" id="conceal">Conceal</button>

https://i.stack.imgur.com/yLOOv.png

https://i.stack.imgur.com/h1usH.png

Answer №2

The issue you are experiencing is due to a conflict between Bootstrap and your custom JavaScript-generated styles. While you seem familiar with the Bootstrap Grid layout, it's important to remember that there are 12 columns in a row according to . Each column has a defined width and margins, so filling all 12 columns might cause alignment issues.

To resolve this without affecting other styling, consider resizing the column and adjusting the margins. You can view an example here: https://jsfiddle.net/Zeenglishking/DTcHh/28837/

    <div id="calendar-container" class="col-sm-8">
                <div id="calendar" class="well"></div>
            </div>


  $('#show').click(function()
  {
    resourceContainer.css('width', '250px');
    calendarContainer.css('margin-left', '50px');
  });

If you notice the menu remains visible even when closed, it's likely due to Bootstrap styling. You can override these styles using "!important". More information on style overriding can be found at https://css-tricks.com/snippets/css/style-override-technique/.

In addition, for a responsive design, use 'col-xs-**' alongside smaller size columns such as col-xs-1 and col-xs-4. This will ensure proper display on various viewport sizes. For more details, visit http://getbootstrap.com/css/#grid-options.

It's essential to understand Bootstrap thoroughly before making adjustments to avoid conflicts with other elements. Blindly applying fixes can lead to further complications in your code.

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 function type '(state: State, action: AuthActionsUnion) => State' cannot be assigned to the argument

I have encountered a persistent error in my main.module.ts. The code snippet triggering the error is as follows: @NgModule({ declarations: [ PressComponent, LegalComponent, InviteComponent ], providers: [ AuthService ], imports: ...

Error found in jQuery validation - TypeError: undefined

I am currently working on implementing the jQuery validation functionality into my form, following the default example provided on the official jQuery validation page. However, I have encountered an error that reads: Uncaught TypeError: undefined is not a ...

Show using foreach, with a modification of the spacing between rows and columns

For my project, I need to display the same image 24 times with a 3x8 matrix on an A4 size page using a foreach method. The issue I'm encountering is that I have to manually add space between each row and column, but it cannot cause the page to break. ...

Transferring a dynamic HTML file created using R's animation package onto a WordPress platform

After using the animation package in R to create an HTML file, I'm facing some challenges uploading it to my WordPress blog. It appears that additional js or css files may be required for proper functionality, but I'm uncertain about the process. ...

Retrieve the information from a fetch call and save it for later use

Greetings to the wonderful StackOverFlow community. As a beginner in web development, I have countless questions swirling in my mind. The focal point of my query is regarding a fetch request in JavaScript. I am struggling to extract the data (userId) fr ...

How to Programmatically Assign Bootstrap Class to an Element Using Angular 2

I am working on a page with several input boxes that need to be flagged for certain criteria. <div class="form-group"> <label class="d-block">Allowance Type</label> <div class="input-group"> ...

Issues with screen scrolling becoming stuck in React and Material UI

Currently facing an unusual issue where scrolling on my mobile website becomes sticky, with intermittent responsiveness to touch. Struggling to identify the root cause as there are no console errors detected. Provided below is a snippet of code for a subse ...

Utilizing React-Router-Redux alongside the powerful features of React-Bootstrap

I've been struggling with this issue for some time now! My goal is to create a 'main app container' that consistently displays the logo, navigation... I plan on using react-bootstrap to enhance its appearance. Currently, I'm encounter ...

Make the image take up the entire screen in HTML

My goal is to display an image that fills the entire screen. Here's how my HTML code looks: <!DOCTYPE html> <html lang="de"> <head> <meta charset="utf-8" /> <title></title> </head> ...

Limit the input to a maximum number of characters

I am in need of input boxes that only accept hexadecimal characters and I also want to set a maximum length for the input. Although I have successfully implemented accepting hex characters only, I am facing an issue when pasting a string - the invalid cha ...

Steps for deactivating tab stops on the primary webpage in the presence of a snackbar

On my web page, there are multiple drop-down menus, input fields, and buttons that can be interacted with using both the tab key and mouse. After entering certain data, I trigger a snackbar (source: https://www.w3schools.com/howto/howto_js_snackbar.asp) t ...

Creating an AJAX URL in an external JavaScript file within a Django project

How can I verify if a student user's email exists in the database using keyup event in a registration form, and prevent form submission if the email is already registered? Below are the relevant files for achieving this: urls.py urlpatterns = [ ...

Position flex-box items to align with the baseline of the final line of text within a block

I am attempting to replicate the layout shown in the final example of the image linked below using flexbox. It seems that the align-items: baseline; property works perfectly when the blocks contain only one line of text. However, when the left and right ...

Discover the method for extracting the complete URL value individually using jQuery

My system involves a user clicking on a link that contains two separate IDs from the database, separated by a forward slash (/). I want to create a variable in jQuery that allows me to access both IDs. Currently, I can easily access the first ID using the ...

Could someone assist me in resolving the issue of receiving empty emails from my online form submission?

Every day, I receive 6 blank emails from my contact form at the same time. Even though the form on the website is filled out correctly and all the information goes through, I still get these mysterious blank emails. I have implemented validation checks in ...

Tips for creating a star program using Angular 2+

Create an Angular 2+ code snippet that will print asterisks (*) in a list on button click. When the button is clicked, it should add one more asterisk to the list each time. For example: Button Click 1 - Output: * Button Click 2 - Output: ** Button Cl ...

The alignment of the JQuery Mobile tabs is off

As I work on developing a Cordova app, I've noticed that the tabs on my Android phone display in an unusual way. Here's what they look like: The image above was created in JSFiddle using JQuery 2.1.0 and JQM 1.4.2 selected with the following co ...

Regain focus after selecting a date with Bootstrap datepicker

When initializing a bootstrap datepicker from eternicode with the parameter autoclose: true, there are two undesired behaviors that occur: After closing the picker, tabbing into the next field causes you to start at the beginning of the document again, w ...

Preventing CSRF attacks using AJAX in a Django application

After some troubleshooting, I discovered the mistake in my HTML code. Simply adding {% csrf_token %} resolved the issue :) Big thanks to everyone who helped! (I followed the JavaScript snippet provided in the initial response but I'm still encounte ...

Preventing Jquery from showing an image when validation fails using PHP or Jquery

I recently implemented an ajax add to cart feature using jQuery. When a button is clicked, data is sent to a PHP page via jQuery, the data is processed and returned as variables, then the item is added to the cart. A confirmation message along with an imag ...