Incorporate the Bootstrap classes to arrange the divs side by side, ensuring that any surplus space is utilized effectively

Having implemented a layout with two images and two paragraphs side by side, everything seemed to be working fine until I encountered an issue when setting both images' height to 400px. The goal was for the paragraph to adjust its size based on content length within 400px space occupied by the images. Although it displayed correctly in mobile view, desktop view was posing challenges. In the illustration below, consider div 2 and 4 as paragraphs and div 1 and 3 as images.

https://i.sstatic.net/b2xYY.png

The desired outcome is depicted here:

https://i.sstatic.net/S7tLN.png

The objective is for the paragraph to expand to fill 100% of available space if lengthy, along with divs 3 and 4. My current code snippet appears as follows:

<div class="col-11">
    <div style="margin-left:10px;margin-right:10px;">
  {% for news in news %}
  <h1 class="text-center" style="color: black; margin-top:20px; font-size:50px;">{{news.title}}</h1>
  <div class="row g-2">
  <div class="col-12 col-md-6 order-2 order-md-1" style="color: #025; margin-top:20px; font-size:20px;">
    {% if news.para_one %}
    <p>{{news.para_one|safe}}</p>
    {% endif %}
  </div>
  <div class="col-12 col-md-6 order-1 order-md-2">
      {% if news.image %}
    <img src="{{news.image.url}}" alt="" class="img" style="height: 400px; width:650px;">
    {% endif %}
  </div>
  </div>
  <div class="detail" style="color: #025; margin-top:20px; font-size:20px;">
    {% if news.para_two %}
    <p >{{news.para_two|safe}}</p>
    {% endif %}
  </div>
...

CSS:

.col-11{
  margin-left: auto;
  margin-right: auto;
  height: 100%;
  background-color: #fff;
}
.row > .col-md-6:last-child:nth-child(odd) {
  width: 100%;
}
@media screen and (max-width: 600px) {
  .img{
    height: 200px !important;
    width: 100% !important;
  }
}

I have explored a potential solution at , but it doesn't quite meet my requirements. Your assistance in resolving this issue would be greatly appreciated!

Answer №1

To align your image to the right, you can utilize the float property. Instead of writing custom CSS, it is recommended to use Bootstrap's float utilities class. Simply add the class float-lg-end to your image for it to float to the right on larger screens:

<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="63010c0c17101711021323564d534d51">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">

<div class="col-11">
  <div style="margin-left:10px;margin-right:10px;">
    <img src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" class="float-lg-end" style="width: 200px;" />
    <p>Lorem ipsum dolor sit amet, consetetur sa dipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea
      takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores
      et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
  </div>
</div>

View the full page snippet and resize your browser to observe the layout.

Answer №2

To tackle your issue, consider utilizing the float property within the image tag and enclosing it in a paragraph tag. This method effectively wraps text around the image on desktop view and seamlessly adjusts for mobile view without the need for media queries.

For reference, you can access my code here: Codepen link

<div class='divsize'>
    <p><img class='imageright' src="https://images.unsplash.com/photo-1453728013993-6d66e9c9123a?ixid=MnwxMjA3fDB8MHxzZWFyY2h8Mnx8dmlld3xlbnwwfHwwfHw%3D&ixlib=rb-1.2.1&w=1000&q=80"  />
  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas viverra pharetra purus nec aliquet. Quisque et felis sed augue iaculis imperdiet et sit amet odio. Quisque molestie erat et tortor accumsan, nec bibendum tellus interdum. Aliquam tempus nisl quis eros aliquam, eget pretium leo placerat. Duis vel efficitur sem. Aliquam erat volutpat. Fusce ut justo eu ante ultrices consequat. Suspendisse tempus lacus eget efficitur rutrum. Fusce vel tellus tempus, accumsan nisl ut, varius ipsum. Vivamus dui sapien, ultricies dapibus tortor eget, placerat ultrices erat. Praesent massa massa, aliquet non dolor in, rutrum ultricies massa.
.</p>

  </div>

CSS


 .imageright{
   width: 400px ;
   height: 400px ;
   margin: 10px ;
   float: right ;
 }

.divsize{
 min-height:410px
}

Answer №3

Implementing a mobile-first strategy

It appears that you are utilizing a custom media breakpoint (600px) to transition from a mobile to desktop layout. As suggested in a previous response, using class="float-lg-end" would only activate the float property when the viewport width is above 992px.

To address this issue, we propose the following steps:

  1. Apply float: right; and modify the width properties of the img element at the 600px breakpoint.
  2. Include the .clearfix class to the parent container to properly clear the floated content.

Below is an example demonstrating a mobile-first approach...

img {
  width: 100%;
  height: 200px;
  object-fit: cover;
  margin: 10px;
}

@media only screen and (min-width: 600px) {
  img {
    width: 400px;
    float: right;
  }
}
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="690b06061d1a1d1b0819295c4759475b">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">

<div class="col-11">
  
  <div class="m-3 clearfix">
    <img src="https://picsum.photos/400" />
    <p class="px-2">Lorem ipsum dolor sit amet, consetetur sa dipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea
      takimata sanctus est Lorem ipsum dolor sit amet.At vero eos et accusam et justo duo dolores
      et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores
      et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
  </div>
  
  <div class="m-3 clearfix">
    <img src="https://picsum.photos/400" />
    <p class="px-2">Lorem ipsum dolor sit amet, consetetur sa dipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea
      takimata sanctus est Lorem ipsum dolor sit amet.At vero eos et accusam et justo duo dolores
      et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores
      et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
  </div>
  
  
</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

Form submission requires a checkbox to be checked

I have been searching for a way to make checkboxes required. Is there a method similar to using required="required"? Currently, I generate my checkboxes in the following manner and would really appreciate any guidance on this topic. It's crucial for m ...

I have developed a web page using asp.net that cannot be resized

Hey there! I'm interested in building a web page that cannot be resized or minimized. Is there a way to do this? Additionally, I've noticed some advertising pages that are fixed on the screen - how can I create something similar? ...

Utilize ng-repeat to iterate over two arrays

Two arrays are at my disposal here. The first array contains option content, while the second array consists of option tags (i.e., A, B, C, D). How can I structure the layout for the 'input type="radio"' using ng-repeat? To start off, I am attem ...

Designing a slider to display a collection of images

I am currently working on a slider project using HTML, javascript, and CSS. I'm facing an issue where only the first two images (li) are being displayed and it's not transitioning to the other (li) elements. Below is the HTML code snippet: <se ...

Attempting to incorporate Font-Awesome Icons into the navigation bar tabs

As a newcomer to React, I've been attempting to incorporate Font Awesome icons into my secondary navigation bar. Despite using switch-case statements to iterate through each element, all the icons ended up looking the same, indicating that only the de ...

Tracking User Visits in Codeigniter

Below is the code breakdown: (Step by step) Place counter.txt in APPPATH . 'logs/counter.txt' Set up counter_helper.php in APPPATH . 'helpers/counter_helper.php'; Autoload the newly created helper in APPPATH . 'config/autoload.p ...

When using WYSIWYG editors, be on the lookout for empty paragraphs and incorrect code in CSS, JavaScript, and

I am currently in the process of redesigning a website for a client. The site is already built using Joomla 1.7, but I am facing an issue with the articles section that was created by the client using a WYSIWYG editor. The problem lies in the messy code st ...

Tips for optimizing HTML5 markup elements to render effectively in Internet Explorer

How can I ensure that HTML5 markup elements such as <header>, <section>, and <footer> are displayed properly in Internet Explorer? I've noticed that when I apply CSS to these elements, the styling doesn't always work as expecte ...

Enhance the collapsible feature in Vue.js by integrating Bootstrap and anim

In the process of creating a side bar menu with collapse show/hide functionality, I am encountering some issues. The current CSS implementation is making the collapse action appear abrupt and unnatural. I am looking to achieve a smooth sliding transition ...

What is the best way to incorporate Bootstrap 5 into a content script without causing any conflicts with the existing CSS of the website? (Chrome Extension)

In the process of integrating the Bootstrap 5 library into a Chrome extension, I have encountered an issue where the CSS and JS files conflict with the main CSS file on certain websites. To address this, I have included the Bootstrap 5 (CSS and JS) files i ...

Unable to utilize external JavaScript files in Angular 8

I've been working on integrating an HTML template into my Angular project and for the most part, everything is going smoothly. However, I've encountered an issue where my JS plugins are not loading properly. I have double-checked the file paths i ...

Encountering an issue in Angular 8 where a class is not being added after the page loads, resulting in an

Looking to dynamically add a class to a div element using Angular? I have a condition isTrue, and am utilizing the angular function ngAfterViewInit() to add the class hideOnLoad after the page loads when isTrue becomes true. Instead of traditional javascri ...

Container filled with a table element

My challenge involves a container grid with 3 div flex subelements. The first is the fixed header, the second is the body, and the third is the fixed footer. Within the body, there is a table. What I want to achieve is that when I resize the window, the ta ...

Styles created using makeStyles in MUI are no longer working properly following an update to both MUI and React versions

Implementing the MUI Dropdown in a components library. When testing the library in Storybook, everything functions properly. However, when integrating the component into a separate React project, the layout becomes distorted. The Dropdown label is posit ...

Creating a notification feature for an HTML application

I am in the process of creating an HTML app through intel XDK. While I understand that using HTML to build apps is not as common, it is the language I am most familiar with, along with CSS. One feature I would like to include in my app is a weekly notific ...

PHP Lightweight HTML Content Scraper

I have been experimenting with a basic web crawler and here is the simple HTML code I used for learning purposes: input.php <ul id="nav"> <li> <a href="www.google.com">Google</a> <ul> <li&g ...

Angular: monitoring changes in HTML content within a Component or Directive

I have a situation where I am retrieving HTML content from a REST endpoint using a directive and inserting it into a div element using [innerHTML]. Once this HTML content is rendered, I would like to manipulate it by calling a global function. My approach ...

How can I keep a fixed position element from shifting to the left when resizing the window?

Is there a solution to prevent the logo element from shifting to the left when resizing the window, despite its fixed position? #logo { top:20px; left:50%; margin-left:-177.6px; width:355.2px; height:148.8px; ...

Can a PHP variable be passed along with a div ID in any way?

I am attempting to transfer a PHP value through the "href" attribute from one div to another. While we can achieve this between pages, like so: <a href="somepage.php?id=<?php echo $id;?>"></a> Is there a way to accomplish this using an ...

Can multiple shadow hosts utilize a common shadow DOM?

As I navigate the world of Web Components, I find myself still grappling with a full understanding of its capabilities. One thing that stands out to me is the numerous advantages it offers. A burning question in my mind is whether it's feasible to sh ...