The sidebar is misaligned, not following the left alignment set by Bootstrap

While experimenting with Bootstrap, I encountered an issue where an element in the sidebar remains at the bottom instead of aligning to the right as intended.

https://i.sstatic.net/LdoS8.jpg

I attempted to float it to the right, but its position didn't change accordingly.

Below is the code snippet for reference:

I'm running out of ideas on how to fix this problem, so any assistance would be greatly appreciated.

HTML:

<!DOCTYPE html>
<html lang="es">

<head>
    <meta charset="utf-8" />
    <title>Learning Bootstrap</title>
    <link rel="stylesheet" href="Bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="styles.css" />
</head>

<body>

    <div class="container border">
        <div class="row">


            <header id="header" class="col-12 bg-primary text-white p-2 pl-5">
                <h1>Learning Bootstrap</h1>
            </header>

            <nav id="menu" class="col-12 bg-secondary text-white">
                <ul class="row w-50">
                    <li class="col">Home</li>
                    <li class="col">Page 1</li>
                    <li class="col">Page 2</li>
                    <li class="col">Page 3</li>
                    <li class="col">Contact</li>
                </ul>
            </nav>

            <section id="content" class="col-12">
                <div class="row">
                    <section id="products" class="col-9 border m-2">
                        <h2>Products</h2>
                        <hr>
                        <div class="items">
                            <div class="row">
                                <div class="item col bg-primary m-2">
                                    Product
                                </div>
                                <div class="item col bg-warning m-2">
                                    Product
                                </div>
                                <div class="item col bg-danger m-2">
                                    Product
                                </div>
                            </div>


                            <div class="row mt-5">
                                <div class="item col bg-primary m-2">
                                    Product
                                </div>
                                <div class="item col bg-warning m-2">
                                    Product
                                </div>
                                <div class="item col bg-danger m-2">
                                    Product
                                </div>
                                <div class="item col bg-success m-2">
                                    Product
                                </div>
                            </div>


                            <div class="row mt-1 justify-content-around">
                                <div class="item col-3 bg-primary">
                                    Product
                                </div>
                                <div class="item col-3 bg-warning">
                                    Product
                                </div>
                                <div class="item col-3 bg-primary">
                                    Product
                                </div>
                            </div>
                        </div>
                    </section>

                    <aside class="col-3 border">
                        <h2>Sidebar</h2>

                        <div class="lateral row bg-light align-items-center">

                            <div class="col-4 bg-primary align-self-start">
                                Element 1
                            </div>
                            <div class="col-4 bg-success align-self-center">
                                Element 2
                            </div>
                            <div class="col-4 bg-warning align-self-end">
                                Element 3
                            </div>
                        </div>
                    </aside>

                </div>
            </section>

            <footer class="col-lg-12 bg-info">
                Bootstrap Master - Cristina Martinez&copy;
            </footer>
        </div>
    </div>

    <script type="text/javascript" src="JQuery/jquery-3.5.1.min.js"></script>
    <script type="text/javascript" src="Bootstrap/js/bootstrap.min.js"></script>
</body>

</html>

If more specific details are needed, please feel free to ask me directly.

Appreciate your support!

Answer №1

The primary div has been styled with a m-2 class, indicating that a margin is applied to the div. To resolve this issue, update your code as follows:

<section id="products" class="col-9">
and
<aside class="col-3">

It is possible that the borders on the div and aside elements are causing them to expand beyond the desired width. Try removing the borders to see if that resolves the problem.

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

Two elements occupy the rest of the vertical space

In the center, there is a div with content inside. I want the top and bottom divs to occupy the remaining space. Similar to this example <div class="container"> <div class="top"> </div> <div class="middle"> C ...

Support for numeric font weights in web browsers

Which browser versions have full support for using numeric values for the font-weight property? This includes Internet Explorer, Firefox, Chrome, Safari, iOS Safari, and Android Browser. While most browsers support the keyword values 'bold' and ...

Top method for removing quotation marks from form input using jquery

Here is a form input that I need to handle: <tr class="formulaRow"> <input type="text" class="ingredient required" name="ingredient"> </tr> Currently, the value from this input is stored as follows: var ingredient = $(".formulaRow").fi ...

Creating a PDF in Python from an HTML / CSS file with images: A step-by-step guide

Suppose I have an HTML / CSS webpage containing images, and I am looking to create a PDF using Python - is this feasible? ...

Guide to concealing pop-up with animation when clicking outside

My question is: Clicking on OPEN should open the popup. Clicking on BACK should close the popup. Clicking outside the popup should also close it. Note: Clicking inside the popup when it is open should not close it. The popup should only close on an outs ...

Tips on adding to Jquery html code while maintaining the current CSS styling

My JavaScript function looks like this: function appendAllQna(qnaList, num){ for (var i in qnaList){ var qnaCom = ""; qnaCom += "<div class='scomment scommentLine'>"; if(qnaList[i].sellerYn == "Y"){ ...

Receiving a sleek black overlay with dynamic text upon hovering over an image

I have been searching extensively for a solution to my issue, but I haven't been able to make it work in my application. What I want is to create a black overlay over an image when it is hovered over, with text that resembles a button appearing on top ...

What is the best way to level out the content in the article using CSS and HTML?

Can anyone help me with CSS and HTML? I have a travel blog and I want to include a related post section similar to Time.com in my articles, but I'm facing an issue. What do I need to achieve this? I want to create a section that looks like the relat ...

Creating a JSON data structure from HTML markup

My goal is to generate a json object by extracting data from a specific section of a wiki page (link). In the "Contents" section, I aim to gather all the information and structure it into an object as follows: { Arts : { "Performing Arts" : [{"Music" : [ ...

What is the best way to manage the alignment of elements within their parent containers in my situation?

Attempting to replicate the design of a website by starting with the navigation bar. <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>test</title> <link rel="stylesheet" href="https: ...

Is there a method to use media queries to dynamically switch JavaScript files based on the user's device?

I've been working on optimizing the mobile layout of my website, and while I have successfully implemented a media query with a different stylesheet for mobile devices, I'm struggling to determine if it's feasible to also load a separate Jav ...

What is the best way to perfectly center the navbar-nav class element in a menu using Bootstrap 5?

Currently, I am in the process of developing a backend for a novice website while also revamping the front end. My knowledge of frontend development is limited, so I have opted to utilize Bootstrap 5. One of my tasks involves transferring the menu from the ...

HTML: How come the EventListener isn't refreshing the Button?

I am attempting to create a field that displays the count of selected (highlighted) characters. However, I am encountering an issue where it does not work as intended. Specifically, the line document.getElementById('selectedCountBtn').textContent ...

Navigating JSON data within JavaScript utilizing a for loop

Issue Overview: My challenge involves handling JSON data returned from Python to JavaScript. I aim to iterate through the JSON structure and display the data elements in an HTML table. Code Snippets: 1] JSON received from Python -- {'data_for_user ...

Tips for clearing a text box on an AngularJS page when clicking a link within the page

On my HTML page, I have a search box and various category links. When a user enters text in the search box, I want to display: p in Products | filter {searchedText} If a user clicks on a category link, I want to display: p in Products | filter {categor ...

Include a search button within the search box of the Custom Search Engine

Can anyone help me with adding a search button to my HTML code? I've tried implementing it, but when I try to search something on a website like YouTube, the results show up without displaying my search query. How can I fix this issue and what changes ...

Pictures failing to load within the canvas

I am currently in the process of creating a very basic canvas element. The idea is to allow users to choose between two images and have their selection appear on the canvas when clicked. However, I am facing some challenges with making it work. I have ver ...

Tips for displaying nested JSON arrays in HTML using Ember.js

I'm having trouble displaying the JSON data I get in app.js using HTML. Any suggestions? Here is the code for app.js (I am confident that $.post is returning valid JSON) App.CadeirasRoute = App.AuthenticatedRoute.extend({ model: function() { a ...

Bootstrap Modal fails to display unless fade class is included

I'm feeling lost with this situation. I am working with bootstrap 4 and trying to create a modal without any animation effects. According to the official website, it says to remove the "fade" class for a non-animated modal. So I followed the instructi ...

Display an image with only a portion visible, no canvas, no frame, and no need

My dilemma involves an img with a surrounding box div. http://jsfiddle.net/6d4yC/7/ 1) I am seeking to display only a portion of the image (250x150) without generating a white overlay when it is in its large size. Placing a #box1 div around the image has ...