Reputation: 5215
THIS IS NOT THE USUAL 3-COLUMN LAYOUT QUESTION :-)
So imagine the classified ads section in a newspaper (remember those?)... I have a design where I have a fixed-size box on the screen (say, 600x200), divided in 3 columns, with tweets displayed in each column. So the tweets would start to fill the first column and they would keep stacking up in the first column until we come to a tweet that no longer fits, so it would be bumped to the next column.. etc.
Here's a mockup of what I'm after (I had to erase the name on each tweet but you get the idea):
It's tricky since the goal is to fit as many tweets as possible into the box but I don't know how tall each tweet will be... it could be one word, it could be all 140 characters using all caps which would take a lot of space. The enclosing box is always the same size and can't change. So I need some kind of smart "flow" so it knows when it move to the next column and fill in all available space. Is there any way to do this in CSS/HTML?
Upvotes: 3
Views: 1290
Reputation: 86260
Using just CSS, columns appear to be the best way.
Each tweet is just a pair of <strong>
usernames, and <p>
tweet bodies. Change these to whatever you like, but make sure to change the CSS to match.
<div class="threecol">
<strong>@someone</strong>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae.</p>
<strong>@nextuser</strong>
<p>...</p>
</div>
This CSS is for the container. Other than your specificiations (width, height, hidden overflow) it just adds the column settings.
.threecol {
height: 200px;
width: 600px;
margin: auto;
overflow: hidden;
-webkit-column-count: 3;
-moz-column-count: 3;
column-count: 3;
}
This is just for your style where you want the tweets to fall into line with the @name
s.
p {
display: inline;
width: 30%;
}
This causes a line break between a <p>
and the following tweet.
p:after {
display: block;
content: '';
margin: 10px 0;
}
For this simple setup, it should work fine on most browsers. For old browsers, they'll just have everything stacked, which will still look okay, and show almost as many tweets.
You could search for a Masonry plugin, and hide elements whose bottom is below its container's bottom. Probably the best solution for fixed height containers.
Upvotes: 5