Large padding in the main container of Bootstrap 4

Hey there, this is my third and hopefully final question. I'm having some trouble with my page layout that was supposed to look like this initially:

[navbar]                            
[1][2][3]

I was aiming to achieve the following effect when resizing the layout:

[navbar]             
[2][3]         
   [1]

(with the first div under the third one)

However, when I apply the class container mt-3 to the main container that holds all three divs, the layout ends up looking like this:

[navbar]             
[1][2]                                                                          
   [3]

Adjusting the margin-left of the third div doesn't move it up to the top row, instead, it shifts to the left as if it's in a different row class.

When I use the parent-container container mt-3, the layout appears like this:

[navbar]             
[1][2]   [3]

But all the divs become really small, and I can't seem to change the width no matter what I try. I even attempted modifying the bootstrap's "container" class using both pixels and percentages.

Using container-fluid helps a bit, as all the divs become larger (occupying 100% of the page width), but ideally, I'd like them to be at around 90% width. However, the [3] div ends up on the right side, quite far from [2]. Upon resizing the window, the [2] div shifts into the white space between [1] and [3], appearing below [3]. So the layout ends up resembling this:

[navbar]                                       
[2]   [3]          
   [1]         

Here's the CSS code:

.main{
    background-color: red;
    box-shadow: 3px 3px 20px #000000;
    border-radius: 20px;
}

.left{
    background-color: green;
    max-width: 200px;
    border-radius: 20px;
}

.right{
    background-color: blue;
    max-width: 200px;
    border-radius: 20px;    
}   

.parent-container {
    display: flex;
}

.right-content{
    width: 100%;
    text-align: center;
    float: center;
    margin-top: 10px;
}

And here's the HTML code:

<div class="parent-container container mt-3">
    <div class="row">
        <div class="left col-4 col-lg-3 order-last order-lg-first offset-8 offset-lg-0">
            <div class="col-12 text-center" style="margin-bottom: 15px">
                <h3>TITLE LEFT</h3>
            </div>
        </div>
        <div class=" col-8 col-lg-6">
            <div class="container card">
                <div class="card-body">
                    <div class="row">
                        <div class="col-12 text-center">
                            <h2>TITLE CENTER</h2>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-12 text-center">
                                <h3>heading 3</h3>
                                <h6>heading 6</h6>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                    <div class="col-12 mx-auto">
                        <a href="#" class="article-link">
                            <h3>Heading 3</h3>
                            <p>Text</p>
                        </a>
                    </div>
            </div>
            <hr>
    </div>
</div>
        <div class="right col-4 col-lg-3">
            <div class="right-content">
                <h2>TITLE RIGHT</h2>
            </div>
        </div>
</div>

Answer №1

There was an issue with the nesting of the columns. Here is the correct way to structure it (all main columns must be within the main row):

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<style>
.left{
    background-color: green;
    max-width: 200px;
    border-radius: 20px;
}

.right{
    background-color: blue;
    max-width: 200px;
    border-radius: 20px;    
} 
</style>

<div class="parent-container container mt-3">
    <div class="row">
        <div class="left col-4 col-lg-3 order-last order-lg-first offset-8 offset-lg-0">
            <h3>TITLE LEFT</h3>
        </div>
        <div class=" col-8 col-lg-6">
            <div class="container2 card">
                <div class="card-body">
                    <div class="row">
                        <div class="col-12 text-center">
                            <h2>TITLE CENTER</h2>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-12 text-center">
                            <h3>heading 3</h3>
                            <h6>heading 6</h6>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-12 mx-auto">
                    <a href="#" class="article-link">
                        <h3>Heading 3</h3>
                        <p>Text</p>
                    </a>
                </div>
            </div>
            <hr>
        </div>

        <div class="right col-4 col-lg-3">
            <div class="right-content">
                <h2>TITLE RIGHT</h2>
            </div>
        </div>

    </div>
</div>

FYI: The columns are not stacking on smaller screens because they are not set up to do so. To make them stack, you need to change all responsive column classes for the smallest screens (col-*) to col-12.

You'll also need to modify the offset classes since the offset-8 class is applied for all screens smaller than lg, causing an 8-unit offset on the left. Adjust the offset classes accordingly.

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

Changing the appearance of a shadow root element using CSS styling

My CustomField has a FormLayout inside, and I want to change the #layout element within the shadow-root. While it can be done with JavaScript: document.querySelector("#myid > vaadin-form-layout") .shadowRoot .querySelector("#layout" ...

Answer for background picture when reducing magnification

Currently, I am facing the challenge of converting a PSD template to HTML. Specifically, I need guidance on how to handle the background food images (highlighted in red in the image) when zooming out the browser. The total width is 1300px with a container ...

Posting data using the form method="post" in Vue does not seem to be working

My goal is to create a website that allows users to reserve a seat using a specific password and time slot. I've set up a form where users can input the password and their name, then submit the form to make the reservation. However, I'm facing an ...

Is there a way to manually change the field color upon approval in AngularJS?

Within my application that utilizes the MEAN stack, I am using AngularJS as the front-end technology. How can I manually change the color representation of a tolerance value to 159.06 in a table? Check out my Plunker for more details. Please refer to m ...

"Enhance your code editing experience in Eclipse with HTML, CSS, and JavaScript syntax

Hi there! I'm looking for a way to enable syntax highlighting for HTML/CSS/JS in Eclipse. My main focus is on developing in Python using the PyDev package, but currently I am working on creating Cheetah templates which are difficult to read without pr ...

Expanding the Element prototype with TypeScript

Is there a corresponding TypeScript code to achieve the same functionality as the provided JavaScript snippet below? I am looking to extend the prototype of the HTML DOM element, but I'm struggling to write TypeScript code that accomplishes this with ...

Customize the yellow background color of Safari's autofill feature by following these simple

When I open this image in Safari, this is what I see: https://i.stack.imgur.com/KbyGP.png However, this is the code I have: https://i.stack.imgur.com/4wEf0.png References: How to Remove WebKit's Banana-Yellow Autofill Background Remove forced ye ...

Conceal Bootstrap Toast for a day following dismissal

I have implemented Bootstrap 5 toasts to showcase an advertisement on my website. The goal is to make the advertisement disappear for 24 hours once the user closes it. Here's the current code snippet: <div class="position-sticky bottom-0" ...

After submitting the form, the delete button in Bootstrap 4 has transformed into an unusual shape

I have a panel on my page, inside the panel header there is a red delete button. The panel content includes a form with several buttons (the red delete button is not inside the form, but linked to it with the form="abc" attribute). In the image below, whe ...

Creating a spacious text box for an enhanced Ajax search feature

I'm currently working on an AJAX application that allows users to input the name of a movie, and then loads results from the database through jquery using a PHP API. However, I'm facing a challenge in implementing a text box with the following re ...

Transforming ng-bootstrap carousel to utilize div elements instead of images

I am currently utilizing ng-bootstrap and Angular, along with chart.js. I have successfully created two charts that update in real-time with data. My goal is to display these charts within a carousel, allowing users to slide between them. I've been at ...

What are some ways I can make my content come alive on my website using the Tympanus examples

After spending hours searching for a way to add animation to my content, I finally found a technique that seemed promising. Despite following the same steps as outlined in the tutorial I found, I was disappointed to discover that there was no animation o ...

Using HTML and CSS to create interactive icons that change color when clicked, similar to how a link behaves

Have you ever wondered if there's a way to make an icon act like a link when clicked, just like regular text links turning purple? And not just the last one clicked, but every single icon that gets clicked. Trying to use the :visited pseudo was unsucc ...

Javascript menu toggle malfunctioning with sub-menus

I am in the process of creating a responsive menu for a complex website. The horizontal menu transitions into a vertical layout on smaller screens, with javascript used to toggle the sub-menu items open and closed when clicked. One issue I am facing is wit ...

Grow an element starting from its center without being limited by the boundaries of a div

I'm faced with a puzzling issue that I believe has a simple solution, but it seems to be eluding me at the moment. Essentially, I have a div containing an image as its background. Upon clicking this div, I want another circular div (created using bord ...

The hover effects cease before the cursor is even shifted

Can someone explain why the hover effect stops before the mouse is moved off the element? I implemented the hover effect on a before pseudo element. ...

Find images by specific dimensions

A while ago, I received assistance in creating a function that searches for images on Google with specific preset sizes. Now, I am interested in modifying this HTML5 code to allow users to input their desired image size instead of using a preset one. For ...

"The issue with the nested nth-child property is that it only affects the first element it is applied to

Having trouble with the nth-child property. The issue lies with the #subnav element. I'm unsure why nth-child isn't working as expected (supposed to change border color and width). Here's the problem and code snippet : <div class=" ...

Guide on incorporating JSON information into an HTML table

Currently, I am retrieving data that needs to be added to an HTML table once it is received. I have attempted some methods, but I am unable to dynamically add the data after the page has loaded. I aim to accomplish this using either JavaScript or jQuery. ...

Error: Papa is not defined. The file was loaded from the CDN in the header section

I have integrated the cdn hosted lib for PapaParse in my HTML header. However, when I execute my JavaScript file and it reaches the function where I call Papa.unparse(data); It throws an error stating that Papa is undefined. This has left me puzzled as I h ...