LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-29-2022, 11:47 PM   #1
mfoley
Senior Member
 
Registered: Oct 2008
Location: Columbus, Ohio USA
Distribution: Slackware
Posts: 2,604

Rep: Reputation: 180Reputation: 180
html DIV float problem


I am displaying a series of images in "float: left" DIVs. Normally this renders just fine. If I display 20 or 30 images, they just wrap to the next "line" beneath the previous row. All have text captions in the DIV. The problem occurs when one of the captions wraps to multiple lines. This makes that DIV taller than the rest on that same row. This messes up the next row of images in that they don't resume displaying at the left edge of the screen, but rather start displaying underneath and to the right of the "tall" DIV. For example:
Code:
--------  --------  --------  --------  --------  -------- 
|      |  |      |  |      |  |      |  |      |  |      |
|      |  |      |  |      |  |      |  |      |  |      |
|      |  |      |  |      |  |      |  |      |  |      |
--------  --------  --------  --------  --------  --------

--------  --------  --------  --------  --------  -------- 
|      |  |      |  |      |  |      |  |      |  |      |
|      |  |      |  |      |  |      |  |      |  |      |
|      |  |      |  |      |  |      |  |      |  |      |
--------  --------  --------  |      |  --------  --------
                              --------
                                        --------  -------- 
                                        |      |  |      |
                                        |      |  |      |
                                        |      |  |      | 
                                        --------  --------
How can I get images as shown in the last row to start at the left edge? I can't really put a <div style="clear: both"></div> after each row because I don't know how many DIVs will be on each row.

Last edited by mfoley; 06-29-2022 at 11:54 PM.
 
Old 06-30-2022, 02:20 AM   #2
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
You really need to look at all the rules that apply to your divs and parent element, e.g. with your browser developer tool.

There are solutions to this; one is to make the divs fixed height/width.

Have you searched for solutions? The stack* sites have tons of html/css stuff.

I also think you might want to look closer at flex - it might provide more flexible solutions.
 
Old 06-30-2022, 06:00 AM   #3
mfoley
Senior Member
 
Registered: Oct 2008
Location: Columbus, Ohio USA
Distribution: Slackware
Posts: 2,604

Original Poster
Rep: Reputation: 180Reputation: 180
Quote:
Originally Posted by ondoho View Post
You really need to look at all the rules that apply to your divs and parent element, e.g. with your browser developer tool.

There are solutions to this; one is to make the divs fixed height/width.

Have you searched for solutions? The stack* sites have tons of html/css stuff.

I also think you might want to look closer at flex - it might provide more flexible solutions.
I did try flex-wrap as well as various overflow options. None of that worked. I do make the divs a fixed width, but cannot do so with the height.

What does appear to work is changing the "float: left" to "display: inline-block; vertical-align: top". Part of that (apparent) solution was from a stack* site.
 
Old 06-30-2022, 07:38 AM   #4
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,625

Rep: Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556

Yep, display:inline-block frequently works better than floating.

Also, depending on why that div is longer, setting a fixed height with overflow:auto to get scrollbars can sometimes be a valid solution.

Or using some form of logic to truncate and suffix long captions with "..." with the full text displayed on hover.

 
  


Reply

Tags
div, float, html, left



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] gcc 4.6.3 'invalid operands to binary % ( have 'float' and 'float' ) error curious95 Programming 6 02-22-2013 08:51 AM
How to use a float/double without using float/double keyword? geewhan Linux - Kernel 4 06-17-2012 08:19 AM
[HTML|CSS] Move div with placeholder so that div in row above may overlap brianmcgee Programming 1 06-15-2011 01:08 PM
count digits of a float || convert float to string nadroj Programming 6 07-11-2005 04:52 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration