Tips for shifting text from the first column to the second column after completing the content in the first

Is there a way to continue text in the second column after filling up the first column vertically? I experimented with white space but it didn't work. Any suggestions?

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e5878a8a919691978495a5d1cbd3cbd4">[email protected]</a>/dist/css/bootstrap.min.css">
</head>
<body>
<div class="container-fluid">
  <div class="row w-50">
    <div class="col bg-light ml-5">
      <div>
        <p>a</p>
        <p>b</p>
        <p>c</p>
        <p>d</p>
        <p>e</p>
        <p>f</p>
        <p>g</p>
      </div>
    </div>
    <div class="col bg-secondary"></div>
  </div>
</div>

</body>
</html>
.col{
        height: 200px;
    }

This is what the current output looks like https://i.sstatic.net/zsjPV.png

This is how we want the output to look like https://i.sstatic.net/ccUZS.png

Answer №1

The simplest method to achieve this is by using the column-count property along with column-fill: auto. Unfortunately, there is no documentation indicating that Bootstrap has implemented this feature themselves.

div {
  column-count: 2;
  column-fill: auto;
  height: 200px;
}
<div>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. 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.</div>

Answer №2

If you're looking for a more versatile approach, consider using the "flex" property.
Simply add "display:flex; flex-direction:column" to the container div and utilize the "flex-wrap:wrap" attribute (similar to "wrap text" in Excel).

    .flex-container{
        display:flex;
        flex-direction:column;
        flex-wrap:wrap;
        height:200px
    }
<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="eb8984849f989f998a9babdfc5ddc5da">[email protected]</a>/dist/css/bootstrap.min.css">
</head>
<body>
<div class="container-fluid">
  <div class="row w-50">
    <div class="col bg-light ml-5">
      <div class="flex-container">
        <p>a</p>
        <p>b</p>
        <p>c</p>
        <p>d</p>
        <p>e</p>
        <p>f</p>
        <p>g</p>
      </div>
    </div>
    <div class="col bg-secondary"></div>
  </div>
</div>

</body>
</html>

Answer №3

I gave this a shot and it actually does the job.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<style>
  .col50 {
    display: inline-block;
    vertical-align: top;
    width: 48.2%;
    margin: 0;
  }
</style>
<script>
  $(document).ready(function() {
    var columns = 2;
    var size = $("#data > p").size();
    var half = size / columns;
    $(".col50 > p").each(function(index) {
      if (index >= half) {
        $(this).appendTo(".col50:eq(1)");
      }
    });
  });
</script>
<div id="data" class="col50">
  <!-- data Start -->
  <p>This is text 1. </p>
  <p>This is text 2. </p>
  <p>This is text 3. </p>
  <p>This is text 4. </p>
  <p>This is text 5. </p>
  <p>This is text 6. </p>
  <p>This is text 7. </p>
  <p>This is text 8. </p>
  <p>This is text 9. </p>
  <p>This is text 10. </p>
  <p>This is text 11. </p>
  <p>This is text 12. </p>
  <p>This is text 13. </p>
  <p>This is text 14. </p>
  <p>This is text 15. </p>
  <!-- data End-->
</div>
<div class="col50"></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

Troubleshooting: How to Fix Missing Sum Display in HTML Input Fields

I am new to the world of website programming and I am currently working on creating a basic sum equation using two input fields from the client-side. <!DOCTYPE html> <html> <head> </head> ...

Is there a way for me to retrieve the header values of a table when I click on a cell?

I have a project where I am developing an application for booking rooms using Angular 2. One of the requirements is to be able to select a cell in a table and retrieve the values of the vertical and horizontal headers, such as "Room 1" and "9:00". The data ...

Tips for handling external CSS dependencies in a Create React App project

Working on a web application using CRA 3.4.1 along with a component library called PrimeReact 4.1.2. My custom CSS is processed through the PostCSS setup in CRA, which adds prefixed versions for properties like display: flex to ensure IE10 support in the ...

A bar graph fails to display on d3 visualization

I am struggling with rendering my bar graph using activity tracking data. Even though I believe my data structure is correct, the rects are not being displayed on the graph. Unfortunately, I cannot identify the mistake I might have made. The dataset is ava ...

Insert a new store into an existing IndexedDB database that is already open

After opening and passing the onupgradeneeded event in IndexedDB, is there a way to create a new store? My attempted code: var store = db.createObjectStore('blah', {keyPath: "id", autoIncrement:true}); This resulted in the following error mess ...

Challenges encountered in retrieving 'text' with Selenium in Python

After attempting to extract the list data from every drop-down menu on this page, I managed to access the 'li' tag section and retrieve the 'href' data using Selenium Python 3.6. However, I encountered an issue when trying to obtain the ...

Customizing CSS float labels for individual inputs

For my project, I've implemented CSS code to create a floating label effect for form inputs. If you need the original code reference, it can be accessed here. However, since there are multiple examples in the original codebase, I have extracted and m ...

Ensuring Bootstrap Cards (version 4.4.1) Blend Seamlessly with Body Text for a Cohes

https://i.sstatic.net/Dqywt.png I have implemented a card similar to the one displayed on my homepage, but I would like it to be aligned left and take up less horizontal space. Additionally, I want the text to wrap around the card rather than being comple ...

"Stylish navigation bar overlaying a stunning background image in Bootstrap 4.0

Is there a way to ensure that my navbar stays on top of my background image in bootstrap 4.0 without using negative margin top? I want a solution that is easy to work with even if changes are made to the site. HTML: <div class="masthead"> <n ...

Randomly choose one of 5 pages and insert an HTML element at different intervals using JavaScript, jQuery, MySQL, or PHP

Suppose we have the following HTML element: <img src="icon.png"> Our website consists of 5 pages: index.php products.php register.php about.php terms.php How can we randomly place this HTML element on one of the pages, ensuring it stays there for ...

Tips for displaying three divs in one row and three divs in another row

I'm aiming for a design with 3 divs in one row and another 3 in the next, like this But what I currently have is different. Can someone assist me in achieving the desired layout? MY HTML : <div class="category-food"> < ...

Improving iframe functionality in AngularJS

I've been experimenting with AngularJS to dynamically update an iframe whenever a query is triggered. It works like this: a query is made, the embed link is fetched from the database, and then it's used in the iframe alongside the title and video ...

Troubleshooting strange behavior with Silex and Twig CSS caching issues

I'm facing a frustrating issue where changes I make in my CSS file are not reloading properly. The style.css file in PhpStorm appears as: body { background-color: blue; } However, when viewed in Chrome it shows: body { background-color: green; ...

Tips for ensuring that a span element outside of an anchor functions as though it were inside of it

I'm facing a challenge with my markup that I need help solving. Here is the scenario: I have provided a link within an anchor tag, but I want users to be able to click anywhere on the li tag in order to be redirected to the link specified in the ancho ...

The JSON.parse function encountered an unexpected character 'o' in the JSON data at position 1

Hello, I am attempting to parse an API. </div> <div id=test> </div> </body> <script type="text/javascript" src="js/jest1.js"></script> <script> var xhr = new XMLHttpRequest(); xhr.open("GET" ...

Dash that serves as a barrier between two words to avoid them from breaking onto

Is there a way to keep a dash ( - ) from breaking a word when it is at the end of a line? Similar to how &nbsp; prevents a line break between two words. The issue I am facing currently is with a dynamic blog post that includes the word X-Ray. Unfortun ...

Why does my dialog box only open the first time and not the second time?

I have created my own custom dialog box using jQuery and it seems to be working fine initially. However, after closing it once, when I try to open it again nothing appears. Can anyone help me identify what's causing this issue? Below is the source co ...

Executing unique calculations on Kendo UI Grid Columns

For experienced users, this may seem simple, but as a newcomer, I'm struggling with a basic arithmetic task. I want to multiply one of the column values (DealValue) by 0.05 in my Kendo grid setup. Despite looking through the Kendo docs, I couldn' ...

Grid items displaying incorrectly due to text alignment issues

I'm facing an issue where I need to separate text and the money part, and also align the text in a way that when viewed in smaller text sizes, the money part moves to the next line. .outdoor-card { display:flex; flex-wrap: wrap; width: 100%; ...

When the menu mobile is open, I successfully disable scrolling on the body, but I am facing an issue where the desktop page always jumps back to the top

I successfully disabled the scroll on the body, thanks to helpful advice from SO! However, I encountered an issue where the body kept jumping back to the top whenever I opened my mobile menu. If I remove the following code: overflow: hidden;</P </bl ...