Adjust the position of divs in a row when there is overflow

I have a website with dynamic div boxes, and I want to organize them into rows with 4 boxes each using Bootstrap. It's working fine, but the issue arises when the text in a box is too long and creates a new line. Instead of moving down to accommodate the longer text, the box next to it moves to the right. Here is the HTML code:

<div class="row">
<div ng-repeat=""class="col-sm-3 album-art"> //loop to create the boxes
    <div class="thumb">
        <div class="box">
            <span class="play" ng-click="">&#9658</span>
            <div class="overlay"></div>
        </div>
        <img src= height="200" width="200">
        <p>text</p>
        <p><i>text</i></p>
    </div>
</div>

And here is the CSS code I'm using:

.album-art{
    padding-bottom: 20px;
    padding-top: 20px;
    margin-bottom: 10px;
}

.thumb {
    position: relative;
}
.thumb .box {
    position: absolute;
    top: 0;
    display: block;
    width: 200px;
    height: 200px;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
}

Essentially, I need the row below the one with overflowing text to move down instead of pushing elements to the right. The issue seems to be related to the "album-art" class. Even after removing other classes, the problem persists.

Thank you for your assistance.

EDIT: Added images for clarification:

When everything looks normal:

But becomes an issue with longer text:

EDIT2: Created an example on jsfiddle.net/qgo7a701. You may need to expand the result area to the left to see 4 squares per row.

Answer №1

Your question is a bit unclear to me, but in bootstrap, the row is divided into 12 cells, allowing you to define divs within the row with different sizes. You can achieve this using the col-[xl,lg,md,sm,xs]-[1 to 12] classes. For more information, you can refer to this link: http://getbootstrap.com/examples/grid/

Regarding your example below, I have attempted to create two rows with two boxes each and only broke the text to prevent it from overflowing into the next div:

.album-art{
            padding-bottom: 20px;
            padding-top: 20px;
            margin-bottom: 10px;
        }

        p{
               word-break: break-all;
        }
        .thumb {
            position: relative;
        }
        .thumb .box {
            position: absolute;
            top: 0;
            display: block;
            width: 200px;
            height: 200px;
            text-align: center;
            text-decoration: none;
            cursor: pointer;
        }
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<div class="row">
<div ng-repeat=""class="col-sm-3 album-art">

    //loop to create the boxes
    <div class="thumb">
        <div class="box">
            <span class="play" ng-click="">&#9658</span>
            <div class="overlay">

            </div>
        </div>
        <img src= height="200" width="200"/>
        <p style="">text helooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo...</p>
        <p><i>text</i></p>
    </div>

</div>

    <div ng-repeat=""class="col-sm-3 album-art">

    //loop to create the boxes
    <div class="thumb">
        <div class="box">
            <span class="play" ng-click="">&#9658</span>
            <div class="overlay">

            </div>
        </div>
        <img src= height="200" width="200"/>
        <p style="">text heloooooooooooooooooooooooooooooooooo...</p>
        <p><i>text ffffffffffffffffffffffffff...ddddddddddddddssssssssssss...ddddddddddddddddddddddd...fffffff</i></p>
    </div>

</div>

</div>



<div class="row">
<div ng-repeat=""class="col-sm-3 album-art">

    //loop to create the boxes
    <div class="thumb">
        <div class="box">
            <span class="play" ng-click="">&#9658</span>
            <div class="overlay">

            </div>
        </div>
        <img src= height="200" width="200"/>
        <p style="">text heloooooooooooooooooooooooooooooooooooooooooooooooooooo...lt;/p>
        <p><i>text</i></p>
    </div>

</div>

    <div ng-repeat=""class="col-sm-3 album-art">

    //loop to create the boxes
    <div class="thumb">
        <div class="box">
            <span class="play" ng-click="">&#9658</span>
            <div class="overlay">

            </div>
        </div>
        <img src= height="200" width="200"/>
        <p style="">text helooooooooooooooooooooooooooooooooooooooooooo...lt;/p>
        <p><i>text</i></p>
    </div>

</div>

</div>

Answer №2

After testing your code, I found that it is indeed working as intended. By using 1 row for the entire collection of columns, they behave correctly. To modify this behavior and group the columns differently, you can follow these steps:

(Continuation: - Add div class="col-sm-12" style="display: table" and close it after every set of 4 "col-sm-3 divs". Create another similar group for the remaining "col-sm-3 divs". Remember to enclose everything within a div class="row". (I personally would have used two rows for every 4 "col-sm-3 divs", but that's up to you). - Convert the "style" attribute into a CSS class, include it in your stylesheet, and add the class to the respective divs. That's it.

.album-art {
  padding-bottom: 20px;
  padding-top: 20px;
  margin-bottom: 10px;
}
.thumb {
  position: relative;
}
.thumb .box {
  position: absolute;
  top: 0;
  display: block;
  width: 200px;
  height: 200px;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}
<!DOCTYPE html>
<html>

<head>
  <title>Untitled Document</title>
  <meta charset="UTF-8">
  <meta name="description" content="">
  <meta name="keywords" content="">
  <script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
  <link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" type="text/css" rel="stylesheet">
  <style>
    .album-art {
      padding-bottom: 20px;
      padding-top: 20px;
      margin-bottom: 10px;
    }
    .thumb {
      position: relative;
    }
    .thumb .box {
      position: absolute;
      top: 0;
      display: block;
      width: 200px;
      height: 200px;
      text-align: center;
      text-decoration: none;
      cursor: pointer;
    }
  </style>
</head>

<body>
  <div class="row">
    <div class="col-sm-12" style="display: table;">
      <div class="col-sm-3" style="padding-bottom: 20px; padding-top: 20px">
        <div class="thumb">
          <div class="box">
            <span class="play"></span>
            <div class="overlay"></div>
          </div>
          <img src="#" height="50" width="50" />
          <p style="color: black">tedddddddxxxx ewhuiofhew hfiuhiufw shidfshksdhxfffffffffffffxxxxxddddddxt</p>
        </div>
      </div>
      ...
    </div>
    ...
  </div>
</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

When selecting a new tab in HTML, the current page position remains unchanged. However, I would like the page to automatically scroll to the

In the design of my website, I have incorporated buttons that are linked to various pages using navigation tabs. However, when these buttons are clicked, the view maintains its position on the new page (e.g., halfway scrolled through the page). Instead o ...

Employing IF conditions within a form to refine options

I am looking to streamline the options in my form based on the car and transmission selected. I have set up the form, but I am struggling with the JavaScript code. I need help figuring out how to only display certain color options when Car 1 is chosen alon ...

Locate a list item within an unordered list and proceed with a comparison

Looking for a way to target an li within a specific ul that has a data-rank higher than the others, and apply different styling to it in comparison to its sibling li. Is there a smart approach to achieve this using regular CSS or styled components? <ul ...

Using HTML and JavaScript to add variables into the URL within the window.location

I have been struggling to incorporate longitude and latitude into the URL. Despite researching various topics online, I have not found a solution that works for me. Below is the HTML code that showcases the issue. When you click the "Show Position" button ...

Click here to navigate to the same or a different page using an anchor

I'm currently implementing this code: $(function() { $('a[href*=#]:not([href=#])').click(function() { if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostna ...

Disregard validation of the view if the element includes the attributes `display: none`

Displayed below is an HTML text input that is designed to toggle visibility using jQuery's slideUp and slideDown functions, which change the display attribute to none with animation. My current challenge is that I do not want to validate the element w ...

Display selected divs with dropdown box but show all divs when no option is chosen

I came across a helpful code on this website while working on my own website. After customizing it to my liking, I encountered some issues. My main goal is to have all divs displayed when no value is selected from the dropdown box. Below is the code that I ...

What are the steps for forming a combined row within a table?

I have a table in the following format: +----------+----------+ | record 1 | record 2 | +----------+----------+ | record 3 | record 4 | +----------+----------+ | record 5 | record 6 | +----------+----------+ Now, I would like to insert an integrated row ...

Integrated Navigation Bar and Header

I'm struggling to figure out a way to integrate my navigation bar and header title. Essentially, I want the text of my header to overlap with or be part of my navigation bar, while also ensuring that both elements remain fixed at the top of the page w ...

What is the method for displaying specific text lines in italic format within the TextArea Tag in SAP Fiori Apps?

I need to format specific text lines in the "TextArea" tag of my SAP Fiori App in italic. The data for my text area is retrieved from a SAP OData Service as an Array. I am currently displaying the data using a loop and setting it as follows in my Java ...

Attempting to secure a successful arrangement using a quiz system

My goal is to create a quiz system, but the output currently looks like this: Question1 Answer1 Question1 Answer2 It should actually look like this: Question1 Answer1 Answer2 ... and so on Any suggestions on how I can correct this issue? Here's t ...

the image srcset fails to resize when the viewport decreases

I'm starting to think that maybe I don't fully understand the srcset attribute. Take a look at this HTML snippet: <img srcset=" /path/to/image1 343w, /path/to/image2 768w, /path/to/image3 304w" sizes=" ...

Can a JavaScript function spontaneously run without being called upon?

<a onclick="determineCountry(data)" class="installbtn">Install</a> My goal is to have the user redirected to one of three sites based on their location when they click the button above. However, there seems to be an issue with the script below ...

The footer is floating somewhere in the middle of the page, not at the bottom

Currently working on a webpage with the Twitter Bootstrap Framework. The footer is supposed to be at the bottom of each page with lots of content, but on one sub-page it's appearing in the middle instead: http://gyazo.com/45232ab25cdeb7705f9775a969051 ...

What is the best way to position a div as a footer within a larger main div?

I am aiming to create a div with simple header, content, and footer sections. Here is the design I am trying to achieve: https://i.stack.imgur.com/QfnGa.png You can check out my code on jsfiddle. I'm having trouble understanding how the relative lay ...

Restricting the amount of text that can be applied to an HTML5 canvas

Currently, I am in the process of developing a tree structure engine using an HTML5 canvas. In this engine, each tree node is connected to a database and has a unique name along with various other values. To represent these nodes visually, I have assigned ...

Creating a dynamic feature in React where multiple icons change color individually when hovered over, all implemented

I'm looking to customize the icons in my footer by changing their colors when users hover over them. I have already created a CSS class with the necessary hover effects, but now I want to pass a parameter in my JSX file that specifies which color shou ...

Converting a JS string into HTML markup

I recently developed a basic web application to manage telnet connections with routers using Node.js, Express, and WebSockets. After establishing a connection, the terminal stream is transmitted through a websocket as UTF-8 strings. However, my current is ...

PhantomJS does not recognize external CSS on the page

Currently, I have Phantom running on a Node server to generate pages from data and render them as PDFs. Despite the pages rendering correctly as PDFs, I am facing an issue where the external CSS file is not being taken into account. Below is a simplified ...

AngularJs fails to apply style to dynamic content in IE8 when using HTML5

Currently, I am in the process of developing a website with AngularJs and utilizing numerous JS scripts to address compatibility issues with Internet Explorer. I have organized the data in JSON format, and each page is designed to fetch and display differ ...