Experiencing difficulties with the alignment of Bootstrap columns

I'm encountering an issue with displaying 3 Bootstrap columns in the ContentArea. Even though I can locate them using Developer tools, they seem to be positioned at the bottom of the ContentArea, making them not visible. I've attempted adjusting the top attribute and margin-top attribute, but I'm unable to successfully move the columns up into view within the ContentArea.

Could someone please help me identify where I might be going wrong?

$(document).ready(function () {
    $('#menu-toggle').toggleClass('menu-hidden');

    $('#menu-toggle').on('click', function () {
        //alert();
        $('#SidebarWrapper').toggleClass('menu-hidden');
        $('#ContentArea').toggleClass('content-grew');
        $('#SubCategories').toggleClass('slide-left');

    });
});
body {
}
#TheLayoutContainer {
    position:fixed;
    z-index:1000;
    width:100%;
    height:100%;
    border:1px solid black;
    background-color:pink;
    left:0px;
}

#menu-toggle {
    
}

#SidebarWrapper {
    width:200px;
    height:100%;
    margin-top:0;
    margin-left:0;
    position:fixed;
    z-index:2000;
    background-color:black;
    transition:1s;
}

#SidebarWrapper.menu-hidden {
    width:50px;
    transition:1s;
}


#ContentArea {
    position: relative;
    height: 100%;
    background-color: purple;
    z-index: 2000;
    left: 325px;
    margin-top:0px;
    transition:1s;
    padding-right:20px;
}

#ContentArea #SubCategories {
    margin-left:-125px;
    width:125px;
    height:100%;
    border:1px solid #72cad3;
    background-color:#72cad3;
}

#SubCategories.slide-left {
    margin-left:-75px;
    width:125px;
    height:100%;
    border:1px solid #72cad3;
    background-color:#72cad3;
}

#ContentArea.content-grew {
    height: 100%;
    left: 175px;
    transition:1s;
}

#HeaderControlMenu {
    height:45px;
    width:100%;
    background-color:yellow;
    top:0px;
    position:fixed;
    z-index:2000;
    left:0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>

<div class="row">
    <div id="HeaderControlMenu">
        <button id="menu-toggle" class="btn btn-success">Click</button>
    </div>
</div>
<div id="TheLayoutContainer">

    <div id="SidebarWrapper">

    </div>

    <div id="ContentArea">
        <div id="SubCategories">

        </div>
        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
            <div class="col-md-4 col-lg-4 col-sm-4 col-xs-4" style="border:1px solid green">A</div>
            <div class="col-md-4 col-lg-4 col-sm-4 col-xs-4" style="border:1px solid green">B</div>
            <div class="col-md-4 col-lg-4 col-sm-4 col-xs-4" style="border:1px solid green">C</div>
        </div>
    </div>

</div>

Answer №1

Adding onto @Temani Afif's point, it is important to wrap the parent element (the one containing the rows) in a container class.

<div class="container">
<div class="row">
    <div id="HeaderControlMenu">
        <button id="menu-toggle" class="btn btn-success">Click</button>
    </div>
</div>
<div class="row">
<div id="TheLayoutContainer">

    <div id="SidebarWrapper">

    </div>

    <div id="ContentArea">
        <div id="SubCategories">

        </div>
        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
            <div class="col-md-4 col-lg-4 col-sm-4 col-xs-4" style="border:1px solid green">A</div>
            <div class="col-md-4 col-lg-4 col-sm-4 col-xs-4" style="border:1px solid green">B</div>
            <div class="col-md-4 col-lg-4 col-sm-4 col-xs-4" style="border:1px solid green">C</div>
        </div>
    </div>

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

Check out this fiddle for reference.

Here is a link to Bootstrap's documentation on grids.

Answer №2

Since the previous responses failed to address all of the errors in your code, I will provide a comprehensive list in this answer:

  1. Avoid using stand-alone rows in Bootstrap. Instead, utilize a full-width container by using a div with the class .container-fluid. For other cases, nest your rows within a div with the class .container.

  2. Every Bootstrap .row should contain at least one Bootstrap column (.col-*) and all content must be placed inside these columns. Never place content directly within a .row.

  3. Do not use .col-xs-* classes in Bootstrap 4. Replace them with .col-* instead.

  4. For responsiveness, swap out

    col-lg-12 col-md-12 col-sm-12 col-xs-12
    with col-12, as it serves the same purpose in Bootstrap 4 which follows a "mobile-first" approach.

  5. Similarly, replace

    col-md-4 col-lg-4 col-sm-4 col-xs-4
    with col-4 for consistent behavior across devices.

It is worth noting that you can insert content directly into a Bootstrap .container or .container-fluid without using rows and columns, but this might hinder responsiveness in most cases. Exceptions include components like navbars and jumbotrons in Bootstrap.

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

Sidebar collapse using Bootstrap

I have been working on creating a collapsible sidebar that pushes the content on the right, but I'm facing issues with responsiveness. When I display the sidebar, the content is getting compressed instead of pushed. I tried adding flex-shrink-0 to the ...

Using Jquery fadeIn along with responsive CSS media queries

Issue at Hand: An issue arises with my navigation bar and text block animations. The fading effect applied on the text element causes inline styles to be added, thus disrupting the media query set to hide the text on smaller screens. If you disable the s ...

What exactly is the mechanism behind how the text-overflow property's fade value operates?

I am struggling to add a one line description to each flex-child using the fade() value, but it seems to not be working as expected. .flex-container { display: flex; flex-wrap: wrap; justify-content: center; flex-direction: row; } .flex-child { ...

Is it possible to use an SVG image as a border with a variable height in CSS

Check out this jsfiddle for my current project's nav setup. I want to center the logo in the middle of the nav with three links centered around it. However, I need the design to be responsive across various screen widths. Any advice on how to achieve ...

Issue with calculating positions in the jquery.quicksand plugin

I've been playing around with a website for the past couple of days and I have successfully implemented the jquery.quicksand plugin to organize my portfolio entries. However, I've run into an issue when selecting the 'all' filter. If a ...

I have a desire to use Javascript to control CSS styles

Within the CSS code below, I am seeking to vary the size of a square randomly. This can be achieved using the Math.random() property in Javascript, but I am uncertain how to apply it to define the size in CSS. #square { width: 100px; height: ...

Error message: "Azure deployment encounters Vue CSS dependency missing issue"

I recently built a Vue app following this tutorial but without CRUD functionality: . The app was created using Vue CLI 4.3.1 with vue create. During local development, it runs smoothly with npm run serve and builds without any errors. Now, I'm atte ...

What is the best way to show dropdown list items above the row they are in?

In this HTML snippet, there is a dropdown menu within a row with a height of 3.7rem. Unfortunately, when the dropdown is clicked, the list items are hidden behind the row because the height is not sufficient. I tried giving the dropdown a z-index of 1, but ...

Element with absolute positioning inside a relative parent does not interfere with other elements outside of the parent

I am currently facing a challenge with a simple dialog that is positioned absolutely in the center of the screen. Inside this dialog, there is a dropdown with a relatively positioned parent (I want the dropdown to follow its parent's position without ...

Issues arise with the functionality of Zurb Foundation 5 tabs

Utilizing the tabs feature in ZURB Foundation 5, I've noticed that clicking on a tab changes the hash in the URL. However, I actually want to prevent this behavior as I rely on the hash for managing page loads. Although I attempted to use preventDef ...

Is it possible to use a shell script to replace the external CSS file link in an HTML file with the actual content of the CSS file

Seeking a solution for replacing external CSS and JS file links in an HTML document with the actual content of these files. The current structure of the HTML file is as follows: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C ...

The hamburger menu in Bootstrap collapses along with the navigation items when viewed on a mobile device

How can I resolve the issue of the hamburger menu icon collapsing with the nav-items when clicked? Navbar <header> <div class="container-fluid"> <div class="row"> <div class="col-12 col-sm-12"> ...

What is the method for assigning a maximum value of 300 to a bootstrap progress bar?

I'm in the process of creating a progress bar with a maximum value of 300, but I'm struggling to set it at 300. It currently works for a maximum value of 100, but I want it to be 300. Here's what I've attempted: <div class="mt-3 pr ...

A step-by-step guide on customizing the background color of a Dialog in Angular Material (Version 16)

I've been attempting to modify the background color of my Angular Material Dialog by utilizing the panelClass property in the MatDialogConfig. Unfortunately, I'm encountering a partial success. I am aiming to set the background color as red (jus ...

Ways to ensure all tabs on the Nav bar are evenly distributed across the width of the screen

Hello! I am in the process of creating my first website, and it's going to be a D&D character randomizer. Currently, I'm working on the Nav-bar section and I have four bars that I want to fit across the screen equally, regardless of the scree ...

Should I consider using an UI framework when initiating a React project?

I'm embarking on a new website project and I'm contemplating whether using a React UI Framework is the way to go, or if I should create my own components and grid system from scratch. I've been drawn to projects like ElementalUI's take ...

Tips for utilizing jQuery with Bootstrap 5 popovers

I'm having trouble displaying div content in a popover using jQuery. It was working fine in Bootstrap 3, but now that I've switched to BS-5, it's not working. Here is my code: $('.popper').popover({ placement: 'bottom ...

What is the best way to add animation to a button within a form using CSS?

Creating a Form in index.html: <form id="mc-embedded-subscribe-form" class="validate" name="mc-embedded-subscribe-form" method="post" action="mailing.php"><pre> <fieldset> <div class="mc-field-group"> <div class="input-cont"> ...

Stripping CSS prefixes upon file initialization

When developing my application, I have a process in place where I load CSS files on the back-end using Express.JS and then transmit them to the front-end. However, before sending the CSS code to the front-end, I need to: Identify the user's browser; ...

Variations in CSS display across various browsers

I'm currently facing an issue while learning web development. The expected result only appears when I preview my website on an old version of Internet Explorer, but it doesn't show up correctly when opened on Firefox or Chrome. The code I have i ...