473,566 Members | 2,770 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I stack divs vertically?

Motoma
3,237 Recognized Expert Specialist
Hello all!

My end goal is to create an HTML layout that will expand and contract with the window size, while maintaining a variable number of content columns.

In the example below, you will see that if you stretch the browser window until there is two columns, divs on the right stack flush with each other vertically; however, divs on the left also stack flush with the divs on the right, leading do some gaps in the layout. The layout is further exacerbated when the window is expanded to more columns (add more divs to see this happen).

If someone knows of a way that I can get all divs to cutely stack below each other, while maintaining the liquidity of this layout, and accomplishing this all with each container styled uniformly, I would greatly appreciate it.

Thanks in advance,
Motoma.

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> 
  3. <head> 
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
  5. <title>A quick example of my issue</title> 
  6.  
  7. <style type="text/css"> 
  8. body
  9. {
  10.     margin: 0em auto;
  11.     width: 85%;
  12.     background: #204364;
  13.     font-family: verdana;
  14. }
  15.  
  16. div
  17. {
  18.     margin: 0.3em;
  19.     padding: 0.3em;
  20.     float:left;
  21.     width: 25em;
  22.     border: 1px gray dashed;
  23.     background: #ffffff;
  24. </style> 
  25.  
  26. </head> 
  27.  
  28. <body> 
  29. <div>
  30. <p>This div has only one entry</p>
  31. </div> 
  32. <div>
  33. <p>This div has a couple items</p>
  34. <p>This div has a couple items</p>
  35. </div> 
  36. <div>
  37. <p>This div has a couple items</p>
  38. <p>This div has a couple items</p>
  39. </div> 
  40. <div>
  41. <p>This div has only one entry</p>
  42. </div> 
  43. <div>
  44. <p>This div has a lot to say!</p>
  45. <p>This div has a lot to say!</p>
  46. <p>This div has a lot to say!</p>
  47. </div> 
  48. <div>
  49. <p>This div has only one entry</p>
  50. </div>
  51. </body> 
  52. </html>
  53.  
Oct 2 '09 #1
6 19321
Motoma
3,237 Recognized Expert Specialist
Partial solutions also accepted!
Oct 2 '09 #2
drhowarddrfine
7,435 Recognized Expert Expert
Yep. It does that.

As you probably know, all those elements are block level and browsers will try and keep everything stacked on top of each other. Floating one removes it from the normal flow but the space for the non-floated blocks is maintained which is what is causing the gaps.

There are a couple of elegant solutions that I've seen but I'd have to look them up. I tend to create documents and stuff them in a folder with hundreds of others so that may take a while.

The first uses javascript and I might be able to find the link to that fairly quick. The second I don't recall and might take longer to find.

In either case, let me know if the js solution is acceptable.
Oct 2 '09 #3
drhowarddrfine
7,435 Recognized Expert Expert
Found the javascript solution.
Oct 2 '09 #4
Motoma
3,237 Recognized Expert Specialist
Are you suggesting that I should, on resize, rearrange each div into the appropriate number of colunms?

That's a terrible hack, and it introduces the problem of measuring the heights of each element to get evenly tall columns.
Oct 5 '09 #5
drhowarddrfine
7,435 Recognized Expert Expert
Your original post sounds like that's exactly what you're trying to do so I guess I don't understand.
Oct 5 '09 #6
Motoma
3,237 Recognized Expert Specialist
Yeah, I was hoping for some sexy CSS that would do the work for me :)
Oct 6 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

6
7699
by: Finn Newick | last post by:
By defining a style as follows: @media aural, handheld {td.layout {display:block;}} I'm hoping to linearise layout tables when viewed by screenreaders and handheld devices (it is also be in some selectable user preferences). This works as intended in Netscape 7 - all the cells stack vertically above each other nicely, but not in...
12
12363
by: Michael Ramey | last post by:
Hi, I've have two divs, that are laid out side-by-side. (I'm floating the first div to the left) I need to set up css on these two divs so that the second div is vertically aligned to the first one (in the middle). How can I go about doing this?, both divs contain textual elements and I won't easily know the heights, so absolute...
20
3034
by: Tyler Carver | last post by:
I would like to do something that seems so basic with two div's but I don't think it can be done. Tables can do it in a snap. I was convinced that css was the way to go for layout but without being able to do even the easiest things, I don't see how. Here is the table way to do the layout (I want this to work in compliance mode in all...
3
4654
by: Oddball | last post by:
I have a problem with the positioning of two divisions. They are containined within a content division in which all the page content happens (ie not the menus, etc.). The behavior I would like (and the behavior that happens in IE) is for the content division (from now on 'ConDiv') to resize with the content of either of the sub divisions...
2
1944
by: Guadala Harry | last post by:
Please follow my thinking here and tell me if I'm nuts or if this is a reasonable thing to do given the objective: I'd like to present 3 data values on an aspx page - each styled uniquely, and the total width to be limited to some arbitrary value (400px or so). Given that I'd like to limit the total width, I can't use a <td> because the...
8
15002
by: maroger | last post by:
I'm sure this is a common issue, but I haven't come across anything that works for me thusfar. I am trying to fix my header, which works fine in firefox but has extra space in IE. Here are example html and css files that illustrate my problem: http://torch.cs.dal.ca/~mroger/css/ietest.html http://torch.cs.dal.ca/~mroger/css/styles.css ...
1
1387
by: Erind | last post by:
Okay, I tried the above divs but they didnt work. My columns and whatnot were being pushed around and settled on top of each other. then I started all over and ended up with a layout 30px bigger on each side. I put a picture together to help with this: http://www.imagemule.com/uploads/erindoNOc.gif -The two blue boxes (column-left and...
0
1613
by: stan | last post by:
I have internal links/jumps within divs. The divs have vertical scrolling. When a link is clicked, both the space within the div as well as the entire page vertically scroll. I would like to restrict the vertical scrolling in this situation (when an internal link is clicked) to the space within the div (the entire page should not scroll). ...
4
8406
by: Adam | last post by:
I have four roughly square DIVs, all the same height, which I need to line up horizontally across the page. What would be the best way to do this? At the moment I have a very botched solution where I have display:table-cell set on each of the DIVs. This works as far as lining them up is concerned, however to get any spacing between them the...
0
7666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7584
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7888
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8108
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7644
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7951
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1201
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.