The responsiveness of Bootstrap 4 col-6 grids does not match that of col-xs-6 grids

I have come across an issue with my code snippet where I am utilizing bootstrap 4 col-6 instead of the deprecated col-xs-6.

The problem arises when resizing the browser window, as the second col-6 does not adjust responsively in terms of vertical positioning.

What steps can be taken to correct this issue?

<div class="container-fluid" style="border: 3px solid red;">
<div class="row">
<div class="col-6">
<img src="https://picsum.photos/id/237/200/300" class="img-responsive" width="200" height="200">
    </div>
<div class="col-6">
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. In vitae turpis massa sed elementum. Placerat orci nulla pellentesque dignissim.</p>
  </div>

</div>
</div>

Answer №1

When you properly incorporate Bootstrap CSS and JS, the col-6 class will function just like col-xs-6.

I noticed that you have not included Bootstrap@4 CSS and JS files. Without these files, no Bootstrap components will work correctly. You can find a template with your example code here.

Starter Template with your HTML (modified).

<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">

    <title>Col-6 issue</title>
  </head>
  <body>
    <div class="container-fluid" style="border: 3px solid red;">
    <div class="row">
    <div class="col-6" style="border: 2px solid yellow;">
        <img src="https://picsum.photos/id/237/200/300" class="img-fluid d-block" />
    </div>
    <div class="col-6" style="border: 2px solid green;">
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. In vitae turpis massa sed elementum. Placerat orci nulla pellentesque dignissim.</p>
  </div>

</div>
</div>

    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1c6c736c6c796e32766f5c2d322d2a322c">[email protected]</a>/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
  </body>
</html>

Utilize the Bootstrap Starter template. Additionally, there is an error in using the responsive image classes. The deprecated img-responsive class in Bootstrap version 4 should be replaced with img-fluid for Responsive Images. Remove the width and height attributes from the img tag for responsive images. Also, consider learning CSS3 flex box by referring to this guide.

This information should aid you in resolving the issue.

Answer №2

By changing col-6 to col-md-6, the parent row will span across the page on larger screens while allowing the columns to stack vertically on smaller screens.

The same effect can be achieved with col-sm-6, depending on the breakpoint you require.

For information on breakpoint sizes, refer to: https://getbootstrap.com/docs/4.0/layout/grid/#grid-options

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">    
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  </head>
  
  <body>
  
<div class="container-fluid" style="border: 3px solid red;">
<div class="row">
<div class="col-md-6">
<img src="https://picsum.photos/id/237/200/300" class="img-responsive" width="200" height="200">
    </div>
<div class="col-md-6">
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. In vitae turpis massa sed elementum. Placerat orci nulla pellentesque dignissim.</p>
  </div>

</div>
</div>

<!-- javascript -->
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
    
    <script></script>
  
  </body>
</html>

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

What is the method for retrieving the input text value contained within a select option?

I have encountered an issue in my HTML template where I am unable to retrieve the value within the input field upon submitting, especially if a custom category name was entered. The code includes an HTML <select> and <input> fields: {% for i ...

JQuery is having trouble changing the image source in Internet Explorer and Firefox, but it works fine in Chrome

After creating an image gallery that functions perfectly in Chrome, I noticed it fails to work in Firefox or Internet Explorer. While scouring similar questions for solutions, none seem to address the issue at hand. To showcase the problematic code, I&apo ...

Google Calendar iFrame experiencing overflow issues after rotation on iOS devices

I've managed to successfully embed a Google calendar into a website using an iframe. Everything is scaling properly on various browsers, however, I've encountered an issue with the calendar overflowing vertically when rotating an iPhone from port ...

Exploring nodes with the help of Cheerio JS

In my HTML code, I am using the Snekfetch library to fetch data. Here is a snippet of the code: <div class="entry-content"> <h4>today's date etc etc</h4> <h3>category name 1</h3> <p> <img class=" ...

Is there a way to adjust the size of a video thumbnail to fit within a

Currently, I am developing a system to remotely control home electrical devices via the web. However, I am facing an issue with fitting camera images properly within their container. https://i.sstatic.net/Yct2d.png How can I ensure that the video thumbna ...

Adjusting text to fit alongside an undefined image's width

Let's keep this straightforward. I've got an image that uses the following CSS properties: .img-right { float: right; margin: 0px 0px 10px 20px; } Below the image, there's a caption with these CSS styles: .img-right p { margin-top: 5px; ...

Issues with scrolling and responsiveness in a website caused by jQuery and JavaScript errors

I'm currently working on a portfolio site and using Scrollit.js, jquery-1.10.2.min.js, and a Responsive Grid System to create it. However, things are not going as smoothly as I had hoped. Here is what's happening: ^There seems to be some unexpec ...

The first generation iPad, CSS3 transformations, and the constraints on image processing due to limited RAM

During my exploration of the original iPad on iOS 5.0.1, I stumbled upon some peculiar quirks that appear to be linked to the number of images being loaded into the browser simultaneously. I noticed certain things rendering at half resolution or even lowe ...

Is there a way to adjust the image opacity of a background using Material UI?

Is there a way to adjust the opacity of a background image using Material UI? I attempted to achieve this by utilizing the makeStyles hook in Material UI. Here is an example of my code: import React from 'react'; import {Box,Typography } from &ap ...

Reduce the value in the database when a button is clicked using PHP

I am currently working on a carpooling website and I could really use some assistance. I have implemented a button that, once clicked, should decrease the number of available free spaces in the car by one (meaning the person who clicks it will reserve a ...

What is causing the Font Awesome icons to not display in this HTML code?

Utilizing Font Awesome in HTML is my goal, however, the code snippet provided is not rendering the desired outcome. I have stored the Font Awesome directory within my project folder as well... <?php include '../config/sessionhandling.php'; // ...

Extract content within Python pre tags

A Python code snippet is being used to extract content between PRE tags: s = br.open(base_url+str(string)) u = br.geturl() seq = br.open(u) blat = BeautifulSoup(seq) for res in blat.find('pre').findChildren(): seq = res.string ...

Within the flask framework, I am experiencing an issue where paragraphs are being overwritten. My goal is to find a

Snippet of HTML: <div class="split left" > <div class="centered"> <div class="container"> <p>Hi!</p> </div> <div class="darker"> <p>{{message}}& ...

Arrangement of Div Box

Here is the HTML code that I am currently working with: <div class="item"> <div class="pageheader"> Header </div> <div class="info"> Created on... </div> <div class="image"> I ...

Exploring the Potential of JSP in Form Submissions

Here's a OCWCD question that I encountered: <form action="sendOrder.jsp"> <input type="text" name="creditCard"> <input type="text" name="expirationDate"> <input type="submit"/> </form> The question based on the ...

Store additional data with the visitor ID WEB in Fingerprint JS V3

After browsing through similar questions, I couldn't find a solution that fits my needs. Basically, I have a website where a random emoji is generated and stored in local storage. However, this method is not effective as users can easily delete their ...

What could be causing the border-sizing property with a value of "border-box" to not

I am attempting to animate the width of the div, starting from 0. However, the padding I have set is preventing the div from being less than that padding. I have tried using border-sizing: border-box;, but it has not solved the issue. What could I be doin ...

Limit the number input to only allow values between 0 and 100

I am utilizing the Number input component from MUI, which includes Increment and Decrement buttons for adjusting numbers. Is there a method to limit the input to only accept values ranging from 0 to 100 ? Additionally, how can I decrease the width of the ...

Can I use the mouseover event on an image to display a sibling div?

Hi everyone! I'm fairly new to web development and I could really use some advice. I'm trying to implement a mouseenter event on an img tag to show a sibling div, but I'm encountering some strange behavior. The mouseenter event seems to be w ...

Uneditable border in Bootstrap table

I am currently utilizing Bootstrap table to showcase some basic information, however, I am facing a peculiar problem. Upon using the bootstrap-table stylesheet, the table displays as desired without an outer border. However, upon initializing the styleshe ...