Aligned to the left margin within a container located inside a 6-column Bootstrap division

I currently have two 6 column bootstrap divs positioned side by side within a row div. Both divs contain an image, with each image spanning half the width of the viewport. In the left column, above the image (set as a background via CSS), I want to place a header and a link within a container.

Issue

The container is not aligning correctly with the left margin of the text (contained in another container) that comes after the two 6 column bootstrap divs. Although I've added a left margin for the container, the alignment gets thrown off when the screen size changes. However, everything appears fine below a resolution breakpoint of 992px when the columns are stacked. Have I missed something or made an error somewhere?

I'm fairly new to this field, so any help would be greatly appreciated!! Here's the code:

#aboutus {
  background-image: url("https://picsum.photos/946/381");
  background-size: cover;
  background-repeat: no-repeat;
  display: flex;
  align-items: center;
}
<div class="row">
  <div id="aboutus" class="col-lg-6">
    <div class="container">
      <h2 style="color: white;">About Us</h2>
      <a class="small" href="#home" style="color: white;">Home</a>
      <i style="color: white;" class="fa fa-angle-right"></i>
    </div>
  </div>
  <div class="col-lg-6">
    <img class="img-fluid w-100" src="https://picsum.photos/946/3...1" alt="">
  </div>
</div>
<div class="container">
  <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. 
     Dignissimos cupiditate ut nobis unde ipsa eius commodi, 
     praesentium eum. Natus, laborum illo est dolorem rem quos 
     ui ipsum nemo fuga. Odio, aut. Esse veniam quia corporis 
     dolor vitae totam.</p>
</div>

Answer №1

For optimal responsiveness on small screens, be sure to utilize the col-* class, and for larger screens, use the col-lg-* class. You can find more information on this by visiting this link.

In my code, I have used col-12 and col-lg-6. This configuration will display two images side by side on larger screens and in a stacked manner on smaller screens.

#aboutus {
  background-color: #e6603f;
  background-size: cover;
  background-repeat: no-repeat;
  display: flex;
  align-items: center;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row m-0">
  <div id="aboutus" class="col-12 col-lg-6">
    <div class="container">
      <h2 style="color: white;">About Us</h2>
      <a class="small" href="#home" style="color: white;">Home</a>
      <i style="color: white;" class="fa fa-angle-right"></i>
    </div>
  </div>
  <div class="col-12 col-lg-6">
    <img class="img-fluid w-100" src="https://picsum.photos/946/381" alt="">
  </div>
</div>

<div class="container">
  <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. 
     Dignissimos cupiditate ut nobis unde ipsa eius commodi, 
     praesentium eum. Natus, laborum illo est dolorem rem quos 
     ui ipsum nemo fuga. Odio, aut. Esse veniam quia corporis 
     dolor vitae totam.</p>
</div>

Answer №2

Replace col-lg-6 with a different responsive size.

In this instance, I opted for col-6 instead. Check out: https://getbootstrap.com/docs/4.0/layout/grid/#grid-options

#aboutus {
  background-color: #e6603f;
  background-size: cover;
  background-repeat: no-repeat;
  display: flex;
  align-items: center;
  background-image:url(https://picsum.photos/946/381);
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
  <div id="aboutus" class=" col-6">
    <div class="container">
      <h2 style="color: white">About Us</h2>
      <a class="small" href="#home" style="color:white">Home</a>
      <i style="color: white" class="fa fa-angle-right">                </i>
    </div>
  </div>
  <div class="col-6">
    <img class="img-fluid w-100" src="https://picsum.photos/946/381" alt="" />
  </div>
</div>

<div class="container">
  <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. 
     Dignissimos cupiditate ut nobis unde ipsa eius commodi, 
     praesentium eum. Natus, laborum illo est dolorem rem quos 
     ui ipsum nemo fuga. Odio, aut. Esse veniam quia corporis 
     dolor vitae totam.</p>
</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

The functionality of Jquery dynamic form is not functioning properly

I attempted to create a dynamic form using Jquery based on the code provided at http://jsfiddle.net/pixelentity/aABLD/24/. I have implemented the HTML file accordingly. However, the form does not work as intended - it displays the HTML page but fails to sh ...

Using HTML5 date input on an android browser

As I develop a web page catering to Android users, I have incorporated a date form control for users to input dates. However, I have noticed that on most devices, the native date selector does not pop up. Interestingly, on certain Samsung devices like the ...

Display or conceal <ul>'s using JavaScript when the mouse enters or leaves

I'm encountering an issue with a basic JavaScript function. The goal is to toggle the dropdown menu on my website when the mouse hovers over or leaves the menu. The problem arises because my script is triggered by the ul tags within my menu, and I ha ...

Changing the content of a DOM element containing nested elements using JavaScript/jQuery

Need some help with a DOM element that looks like this: <span>text</span> <b>some more text</b> even more text here <div>maybe some text here</div> How can I replace text with candy to achieve this result: <span> ...

Adjust the canvas size to perfectly fit within the parent bootstrap cell in a grid layout

I am currently in the process of creating a dashboard using the Bootstrap grid. Some of the cells contain a canvas element, and I am trying to ensure that it matches the size of its parent. My approach involves the following calculations: var parent = can ...

Using Selenium to capture text for later validation and storage in a variable

Using Selenium in Visual Studio. I require assistance with developing two test cases. UPDATED: Extract a serial number from one text field and save it in Variable A. Retrieve another serial number from a different text field and store it in Variable ...

Having difficulty shrinking the excessive gap between the image and text

https://i.sstatic.net/7Wu8J.jpg I have created an app and added inline styling to make the image and text appear next to each other. However, there seems to be some extra space between the image and text, and the text "Demo Analysis Application" is split ...

Issues with Bootstrap sidebar and footer functionality

I need to implement a consistent footer on multiple web pages created with jQuery and bootstrap 3. Following the example provided by Bootstrap, I have written the script below to add the footer: // Default $( document ).ready(function() { $(' ...

Content on the website has vanished into thin air

Attempting to retrieve the content of a webpage located at The source code of this page reveals an element labeled "row_1"... However, when attempting to achieve this in my code: reader = new BufferedReader(new InputStreamReader(connection.getInputStrea ...

Utilizing Material design principles in conjunction with Bootstrap 4

As I work on developing my web application, I originally relied on Bootstrap 4 features. However, I recently decided to incorporate the Material Design library for additional functionality. Unfortunately, this change resulted in some unexpected alteratio ...

Implement dynamic page titles with breadcrumbs in Laravel 8 for a seamless user experience

I am currently utilizing the laravel-breadcrumbs package created by diglactic in conjunction with laravel 8, which is a fork from davejamesmiller/laravel-breadcrumbs. My goal is to incorporate a dynamic page title that aligns with this breadcrumbs package. ...

Skewed div with a stylish background image

Struggling with an issue here. I've managed to skew my div just right, but now I'm trying to get the image to fit without tiling. If anyone can offer some assistance, that would be greatly appreciated. This is what I'm aiming for: https://i ...

Creating a server-side HTML template: A step-by-step guide

I need to create a consistent layout for all of my website pages using Bootstrap. While I already have a layout designed for a single page, I want to apply the same design across all pages. My initial thought was to utilize Jade for this task, but I want t ...

Adjusting the width of columns in a flex layout using Bootstrap 4

On mobile, I am attempting to rearrange some elements in a different order. Currently, this is what I have: https://i.stack.imgur.com/fY3PQ.png Below is the HTML code: <main> <div data-color="yellow"></div> <div class="wrapper"& ...

What is the best way to conceal the blackberry cursor in a web browser?

Is there a way to conceal the blackberry cursor while browsing on the browser? Perhaps through Javascript or CSS? I am attempting to replicate the functionality found in native apps where users can flick through items with their finger. I find this featur ...

What are the advantages of utilizing CSS pseudo-elements "before" and "after" over just using span tags?

After conducting my research, it seems that CSS pseudo-elements ::before and ::after function similarly to nested span tags within a parent element. However, some sources suggest that they can be highly beneficial and even necessary in certain scenarios. ...

Wordpress articles refuse to appear side by side

I've been at it for hours now, trying to solve this issue with no luck. I have a Wordpress loop on my homepage that displays post thumbnails vertically, but I want them to appear in sets of three images before starting a new line. Here's the cod ...

Attempting to incorporate a border underneath the H1 title labeled MY TODO LIST

<html lang="fr"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" conte ...

To make a JavaFX label stand out, simply prepend a vibrant red asterisk at the start of

I'm facing a challenge with my SceneBuilder project. I have developed a scene that consists of several labels, and I want to highlight some of them by adding a red asterisk at the beginning of their text. Unfortunately, I haven't been able to fin ...

The scaling of the viewport does not seem to be functioning properly on the mobile device

As a beginner in website development, I am currently working on a new project that is still in the early stages of development. My goal is to ensure that this website is responsive for mobile devices. I have added the following meta tag <meta name="view ...