Troubleshooting Bootstrap 4 problem with varying sizes of div content


I have encountered a problem with the script below, where the content in a div is of variable size and does not always occupy the entire horizontal space allotted by the col-6 class from one row to the next:

 <div  class="card-body " >
  <div class="row comments_container" id="comments_container">
      <?php foreach ($comments AS $comment){?>
          <div class="callout <?php echo $comment['comment_callout'];?>">
              <div class="row">
                  <div class="col-3"><?php echo '<span class="text-bold">From: </span>'.$comment['comment_author'];?></div>
                  <div class="offset-6 col-3">Sent on: <?php echo $comment['comment_date'];?></div>
              </div>
              <div class="row">
                  <div class="offset-3 col-6 border-primary border-left">
                      <?php
                      if (!empty($comment['comment_parent_author'])){echo 'In response to '.$comment['comment_author'].'.<br/>';}
                      echo '<span class="text-xs">'.$comment['comment_content'].'</span>';
                      ?>
                  </div>
                  <div class="col-3"></div>
              </div>
              <div class="row justify-content-center border-top mt-2 pt-2 border-thick border-primary w-100">
                  <div class="col-1">Approve</div>
                  <div class="col-1">Reply</div>
                  <div class="col-1">Report as Spam</div>
                  <div class="col-1">Delete</div>
              </div>
          </div>
      <?php } ?>
  </div>
</div>

In the screenshot provided below, you can see that when $comment['comment_content'] data varies in size, the div containing the smallest data field does not fully utilize the col-6 class, taking only the size of the smallest data field.

https://i.sstatic.net/8VO30.png

Answer №1

Your class structure could use some improvement, consider the following:

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet" />

<div class="container card-body">
  <div class="row comments_container" id="comments_container">
    <div class="col-3"><span class="text-bold">From: John John</span></div>
    <div class="offset-6 col-3">Sent on: May 31, 2020 </div>
  </div>
  <div class="offset-3 col-6 border-primary border-left">
    <span class="text-xs">Comment</span>
  </div>
  <div class="row justify-content-center border-top mt-2 pt-2 border-thick border-primary w-100">
    <div class="p-1">Approve</div>
    <div class="p-1">Reply</div>
    <div class="p-1">Spam</div>
    <div class="p-1">Trash</div>
  </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

Only output to the console if the data returned from an AJAX request has been

Here is a script that I created: <script type="text/javascript> $('.storage').html(""); setInterval(function(){ $.get('./playcommand.php', function(data) { if($('.storage').html() !== data){ ...

What is the best way to modify a date and time within an <td><input> element using jQuery?

I am looking to automate the updating of the datetime in a <td> tag, but I am struggling with implementing jQuery within tables. I also plan on resetting to the default datetime value if the checkbox is unchecked, although I will attempt to tackle t ...

Tips for preventing images from stretching the width and height of my HTML

I am facing an issue with my SVG files positioned as "absolute" on my page. When they are close to the corners of the page, they end up expanding the width of my Container element (using Material UI React). I have tried setting "maxWidth":"100vw" on the ...

Display a specific section depending on the user's input by utilizing either ng-if or ng-show

I have a scenario where I need to display one of two sections based on user input. If the user selects 'Daily' in the first 'type' input, I want section 1 to appear (Enter start date and hour). For any other type selection, I want secti ...

When a div slides down on page load, the div will slide up when a button is clicked

I am trying to make a div slideDown on page load. The goal is to have the div automatically slideDown after 2 seconds, which contains a responsive image and a button named "z-indexed". However, I am having trouble getting the same div to slideUp when the z ...

Javascript animation functioning for a singular item within a list

As I continue practicing my skills in Javascript and HTML, I stumbled upon this intriguing list known as "item/adapter", similar to what we refer to as adapters in Android. While the process of adding them programmatically to my div is working smoothly, I& ...

Receive information from a form and store it in an array

Struggling to figure out how to convert this into an array. I'm having trouble grasping the concept of taking input from a form and storing it in an array. In my project instructions, it clearly states: Do NOT save the input in variables and then tra ...

How to Create a Hover Drop Down Menu that Disappears When Not Hovered Over

When I hover over the drop down menus on my Navbar, they display perfectly. However, it's impossible to click on the items in the menu because as soon as I move the cursor away from the main nav, it disappears. I've tried adding display:block and ...

Using CSS to showcase div elements with varying dimensions

How can I arrange divs with varying heights to be positioned close together, regardless of their height, and with a specific margin similar to buildings? I am aiming for a layout like the one on this website . I tried using float:left but it only float ...

How to Display Full Lightbox Image on both Tall and Short Height Browsers

Hey there! I'm showcasing my portfolio using lightbox, but I've run into a little issue. When the browser height is full, everything looks great - you can see the entire image, along with the paragraph and buttons. https://i.stack.imgur.com/UCJG ...

jQuery validation for various forms with individual submission buttons

I am working on a single-page application that has multiple forms, such as form_1, form_2, etc., each with its own submit button (submit_1, submit_2, etc.). Each form contains records with checkboxes for taking specific actions and there is also a "select ...

React modal not closing when clicking outside the modal in Bootstrap

I recently utilized a react-bootstrap modal to display notifications in my React project. While the modal functions correctly, I encountered an issue where it would not close when clicking outside of the modal. Here is the code for the modal: import Reac ...

Working with CSS3 transitions in PHPStorm is a breeze

For some reason, my phpstorm does not provide code completion for CSS properties like -webkit-translate, translate, or animation. Has anyone encountered this issue before? Any suggestions on how to fix it? ...

Adjusting Nested Divs based on the Content

One issue I'm facing is that the nested div ('content') isn't adjusting its height based on the actual content, specifically my form. The parent div adjusts its height but the child div doesn't. Any ideas on how to fix this? HTML: ...

Create a bootstrap table with td elements that have no wrap for their content

I am currently developing an application using springboot, thymeleaf, and bootstrap. Here is the snippet of the html code I'm working with: <!doctype html> <html lang="en" xmlns:th="http://www.thymeleaf.org"> <h ...

Capturing and saving detailed hand-drawn artwork in high resolution

Is there a cutting-edge solution available for capturing hand-drawn sketches (from a tablet, touch screen, or iPad-like device) on a website using JavaScript and saving it on the server side? Essentially, I am looking for a mouse drawing canvas with a hig ...

What is the reason that custom styling for a single react component instance does not function properly?

In my current view, I have integrated a react component as shown below: <Jumbotron> Lots of vital information </Jumbotron> I am looking to give this particular instance a unique style, like using a different background image. However, addin ...

Dynamic Hero Banner

As I work on creating a basic website for my football team, I am facing an issue with the text placement in different screen sizes. While the Jumbotron background image resizes perfectly according to the screen size, the text outside of the Jumbotron doesn ...

Problem with full-page navigation sliding in and fading in and out

Upon the user's click on <a href="#slide-nav" class="slide-nav-trigger">, a full-page navigation smoothly slides into view. This animation is triggered by CSS and uses jQuery for event delegation. The Dilemma Instead of abruptly turning on and ...

stepper vue with previous and next buttons

I am trying to create previous and next buttons in Vue, but I am struggling a bit because I am new to learning Vue. I have some methods like this.activeIndex < this.activeIndex - 1 that I need to implement. Can someone help me with how to do this? cons ...