My column in Bootstrap 4 is not aligning properly on mobile devices

Currently, I am using Bootstrap 4 and seeking your assistance. My goal is to create a two-column grid layout with a row that rearranges on mobile devices:

This is my current approach:

<div class="row">
            <div class="col-md-10 offset-md-1 col-sm-10 offset-sm-1">
                <div class="col-md-6 col-sm-12">
                    <img src="my source" alt="My alt" />
                </div>
                <div class="col-md-6 col-sm-12">
                    <h2>My title</h2>
                    <p>My text</p>
                </div>
            </div>
        </div>

This method worked perfectly in Bootstrap 3 but unfortunately does not work in V4.

I am aiming for something like this:

.row>div{
  width: 49.7%;
  display: inline-block;
}
@media screen and (max-width: 991px){
  .row>div{
    width: 100%;
    display: block;
  } 
}
<div class="row">
  <div id="first_column">My first column</div>
  <div id="second_column">My second column</div>
</div>

Any advice on how I can achieve this? Thank you for your help!

Answer №1

Almost there! The unnecessary div has been removed:

<div class="col-md-10 offset-md-1 col-sm-10 offset-sm-1">

This should be the correct code snippet you're after:

<div class="row">
   <div class="col-sm-12 col-md-6">
      <img src="my source" alt="My alt" />
   </div>
   <div class="col-sm-12 col-md-6">
      <h2>My title</h2>
      <p>My text</p>
   </div>
</div>

This code snippet is compatible with Bootstrap 4.

Check it out here: https://jsfiddle.net/5d2n72r4/

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

Navigating between various links using the tab key can result in complications with pseudo-elements when using

When using Chrome, try clicking in the results pane and then hit tab to focus on this first link: http://jsfiddle.net/2q6c7c36/2/ Have you noticed how the contents of .box seem to "jump up" outside of its border? It seems that this issue is related to th ...

Is there a way to transfer all the selected items to PHP using AJAX?

I am looking for a way to send all the checked items into PHP using AJAX. I want to include the checkbox ID and inner text in the information that is sent. For example, if I check box1 and box2, I want the relevant information to be saved in Data and then ...

Developing a vanilla JavaScript web component with distinct HTML and JavaScript files

As I delve into creating vanilla JS web-components, I am exploring methods to keep the template HTML separate from the JS file, ideally in a distinct HTML file. I have examined various implementations of native JS web-component setups found notably here, ...

A guide on restricting overflow in React Spring Parallax 'pages'

Currently, I have integrated React Spring Parallax () into my project found at this link: https://codesandbox.io/s/parallax-sticky-scroll-2zd58?file=/src/App.js Upon clicking the button to navigate to the next section, it is noticeable that the image over ...

"Trouble with changing the active color of the dropdown button in a Bootstrap

Take a look at my navbar image below. When the home page is active, it is simply underlined. https://i.sstatic.net/e2Au3.png Another picture of my navbar shows an issue with the dropdown menu being highlighted in a different color when active. I've t ...

table that can be scrolled horizontally

I am facing an issue similar to the one discussed in this thread about responsive design for html wide table. In essence, my problem involves a table that is wider than the container div, which has ten columns in width (using bootstrap). The challenge aris ...

Creating a Select Directory feature with React - A Step-by-Step Guide

I am in need of uploading all files from a folder to the server. I have been attempting to use a Select Directory window instead of selecting individual files. The standard method: <input type="file" webkitdirectory directory/> has not worked for ...

Ways to style the bottom border of an input with CSS

Currently, I am trying to change the color of an input border bottom when the input is not in focus. Below is my HTML code: <input type="number" id="nc" name="days" class="numero" placeholder="" min="0"><br /> Here is the CSS code I have trie ...

Struggling with getting a page-break to properly function within a Bootstrap modal

I have a Bootstrap (v4) Modal that consists of multiple sections, and I am trying to print the content of the modal-body with each section starting on a new page. To achieve this, I have included the following CSS: section { page-break-after: always; ...

The absence of the pyramid in the WEB GL canvas is noticeable

I encountered an issue while attempting to generate two shapes on the canvas: an octagon and a pyramid. The octagon displays correctly, but the pyramid does not appear as expected. Below is the code snippet related to the creation of the pyramid: pyramidP ...

Tips for Selenium: Automatically Save PDFs from Webpages without a Download Button

1.) How can I download Article PDF files from multiple web pages to a local folder on my computer using Selenium if there is no "Download PDF" button available? 2.) I thought about using keyboard keys for printing such as "Control - P", but none of the ke ...

Tips for creating a mobile-friendly website with Twitter Bootstrap

Having an issue with my site on mobile devices while using Twitter Bootstrap. The header is not displaying correctly when I resize the window, it appears like this: It should look consistent across all devices as shown below: Below is my HTML code: ...

How can Typescript elevate your use of the IFrame API?

Here is a code snippet that performs the following actions: let doc = this.iframe.contentDocument || this.iframe.contentWindow; let content = `...` doc!.open(); doc!.write(content); doc!.close(); Despite this, the Typescript linter thr ...

The footer is refusing to show up at the bottom of the page

Why is my footer floating in the middle of the page? It's driving me crazy. I really hope it's a quick fix. I've searched online and all the solutions point to having a fixed footer, but I don't want that because it looks bad on smaller ...

What are the best ways to integrate jQuery into a React application?

I am in the process of developing a responsive menu for my react app, but I'm facing some challenges as a newcomer to react. In order to achieve the desired functionality, I am trying to incorporate jQuery for menu toggling. However, when I attempt to ...

Hide one div when another is toggled

Once an image is clicked, a div appears using toggle. I want the initial div to disappear when the second one toggles, and tried using the .css function in JavaScript for this purpose. However, it only applies to the first case as it receives information f ...

What is the best way to send file content to a web service (asmx) using an HTML5 FileUpload feature?

Is it possible to send a file from an HTML5 file upload to an ASMX webservice using jQuery $.ajax and if so, what should be the data type for deserializing the uploaded file in the webservice? Here is the HTML code snippet: <input type="file" name="fi ...

Ionic 2: Apply a New Class to Selected Item and Remove Class from Others

I have a collection of buttons that, upon being clicked, should have a class added to change their color. Before adding the class to the clicked button, I want to ensure that any previously selected button has the class removed. CSS .selected-date-item { ...

Customize CSS styles based on Angular material stepper orientation

Is it possible to change the CSS style of an angular material stepper based on its orientation? For instance, can we set a red background when the stepper is displayed vertically and a blue background when horizontal? ...

Error in Django: missing one positional argument 'request' when calling load_stations() function

While attempting to create dependent dropdowns, I encountered an error during compilation. The specific error message that appeared was: File "C:\...\operations\urls.py", line 13, in <module> path('ajax/load-stations/', ...