I have a unordered list of thumbnails that work on every other page except one. On this one particular page, there is a large amount of whitespace on the third row. See below:
I don't get why it is doing this, it happens even if you take away padding and margin. The page that this is doing this on is http://bransonweekend.net/cabins/trailsend
This is because you are using:
.picture-board .pinned-photo img {
max-height: 160px;
}
and in that row the first image form factor makes it go the max-height but the other two are too wide so the height is less than the max 160px.
try adding this:
.thumbnails>li{
min-height:172px;
}
this will make sure they are the same height even if they are too wide
Try out this library:
http://masonry.desandro.com/
It's useful in cases like these, where elements have to line up on a grid. Masonry is used all over the internet.
I'm trying to replace a two column table on my index page with CSS. To get a look at my current index page, it is at http://www.negative-g.com.
I have my columns set up. I'm actually using a three column layout with the third being for my sidebar image, and for the other two I want to have boxes (basically tables without using tables) with images and text alternating (park logos and their name/location in text underneath lined up with those in the other column). What sort of code would I need to add to each column to replicate my table layout?
Usually I'd use a bunch of floated blocks for that. For example, if I've got a list of items:
<ul>
<li>Foo</li>
<li>Bar</li>
<li>Baz</li>
<li>Quux</li>
</ul>
(After removing all the margins and padding) I can set dimensions on the li elements, make them blocks, and float them left:
li {
display: block;
width: 100px;
height: 50px;
float: left;
}
If there's only 200px of space for them, then they'll wrap around. Try it.
If you set the width to 50%, you'll get a two-column layout. Remove the height, style the interior, and you're good to go.
This doesn't take your sidebar into account, but your sidebar isn't really part of the list, and you appear to be dealing with it as a background anyway, so there shouldn't really be any need for anything special. If you want to make sure the list doesn't overlap it, you can set a margin-right on the list and it won't go over there.
I have a panel div with a title bar div. In the title bar, I may have several different icons on the right side (to be determined at runtime). I'm trying to construct the CSS so the icons will always stack as far to the right as possible, and also have it that the title text doesn't run over the icons (ie, it'll wrap around to a new line if necessary). I just haven't been able to get it right. For my icons, I have <img class="icon" ...> where
.icon {
display: block;
float: right;
padding-left: 4px;
}
The icons appear fine on their own. But when I try to add the actual title is when things get wonky. I can't seem to get the title to take up the remaining space to the left correctly. The div (or span, which I've tried) will either be completely below or above the icons. Or sometimes, it'll force the icons to stacked vertically on the right, depending on the length of the title.
So in essence, what I'm looking for is one or more small fix-sized elements stacked horizontally to the upper right, and a longer element to take up the remaining space to the left, and this last element may end up taking more space vertically depending on if there's any text wrapping.
Any help would be greatly appreciated!
Adding the following rule to the css of the element you have your text in might help:
white-space: nowrap;
I think I got it working.
Basically, I had the title text within a div (also tried span). But if I didn't put it within anything (ie, it's part of the main title div), everything seems to work.
http://jsfiddle.net/ADLrh/
Hopefully you can see what I'm after. The three 'fillers' on the top row have sunk, upsetting the pyramid-like formation. Any idea what's causing this?
EDIT: I should also add that the method I go for needs to be flexible because potentially any filler could be a like button and the actual pyramid is quite a lot bigger.
Indeed, like Guy suggested, you're going to want to use the float property rather than display: inline-block, because inline-block is pretty finicky for vertical alignment when using different types of elements next to each other, with whitespace between them.
However, to keep the "pyramid" form, you'll want to wrap the buttons in another div that IS set to display: inline-block, to allow the whole row to center in the current parent div.
Like in this example: http://jsfiddle.net/syd8L/
Remove the white spaces between the HTML elements. This is not however the case where you should use display: inline-block;. Analyze this example. You could use float instead, then you wouldn't need to worry about whitespaces between HTML elements.
Easiest way would be to add some relative positioning to the buttons on the first row, like this:
http://jsfiddle.net/ADLrh/1/
Where you have display: inline-block, you should also add vertical-align: top.
See: http://jsfiddle.net/thirtydot/ADLrh/2/
I want to display data like the following:
Title Subject Summary Date
So my HTML looks like:
<div class="title"></div>
<div class="subject"></div>
<div class="summary"></div>
<div class="date"></div>
The problem is, all the text doesn't appear on a single line. I tried adding display="block" but that doesn't seem to work.
What am I doing wrong here?
Important: In this instance I dont want to use a table element but stick with div tags.
It looks like you're wanting to display a table, right? So go ahead and use the <table> tag.
I would use the following markup:
<table>
<tr>
<th>Title</th>
<th>Subject</th>
<th>Summary</th>
<th>Date</th>
</tr>
<!-- Data rows -->
</table>
One other thing to keep in mind with all of these div and list based layouts, even the ones that specify fixed widths, is that if you have a bit of text that is wider than the width (say, a url), the layout will break. The nice thing about tables for tabular data is that they actually have the notion of a column, which no other html construct has.
Even if this site has some things, like the front page, that are implemented with divs, I would argue that tabular data (such as votes, responses, title, etc) SHOULD be in a table. People that push divs tend to do it for semantic markup. You are pursuing the opposite of this.
I don't mean to sound patronizing; if I do, I've misunderstood you and I'm sorry.
Most people frown upon tables because people use them for the wrong reason. Often, people use huge tables to position things in their website. This is what divs should be used for. Not tables!
However, if you want to display tabular data, such as a list of football teams, wins, losses, and ties, you should most definitely use tables. It's almost unheard of (although not impossible) to use divs for this.
Just remember, if it's for displaying data, you can definitely use a table!
If there's a legitimate reason to not use a table then you could give each div a width and then float it. i.e.
div.title {
width: 150 px;
float: left;
}
Is there a reason to not use tables? If you're displaying tabular data, it's best to use tables - that's what they're designed for.
To answer your question, the best way is probably to assign a fixed width to each element, and set float:left. You'll need to have either a dummy element at the end that has clear:both, or you'll have to put clear:both on the first element in each row. This method is still not fool-proof, if the contents of one cell forces the div to be wider, it will not resize the whole column, only that cell. You maybe can avoid the resizing by using overflow:auto or overflow:hidden, but this won't work like regular tables at all.
or indeed this, which is very literally using tables for tabular data:
https://stackoverflow.com/badges
Just to illustrate the remarks of the previous answers urging you to use table instead of div for tabular data:
CSS Table gallery is a great way to display beautiful tables in many many different visual styles.
Sorry, but, I'm going to tell you to use tables. Because this is tabular data.
Perhaps you could tell us why you don't want to use tables?
It appears to me, and I'm sure to a lot of other people, that you're confused about the "don't use tables" idea. It's not "don't use tables", it's "don't use tables to do page layout".
What you're doing here is laying out tabular data, so of course it should be in a table.
In case you're unclear about the idea "tabular data", I define it like this: bits of data whose meaning isn't clear from the data alone, it has to be determined by looking at a header.
Say you have a train or bus timetable. It will be a huge block of times. What does any particular time mean? You can't tell from looking at the time itself, but refer to the row or column headings and you'll see it's the time it departs from a certain station.
You've got strings of text. Are they the title, the summary, or the date? People will tell that from checking the column headings. So it's a table.
The CSS property float is what you're looking for, if you want to stack div's horizontally.
Here's a good tutorial on floats: http://css.maxdesign.com.au/floatutorial/
display:block garauntees that the elements will not appear on the same line. Floating for layout is abuse just like tables for layout is abuse (but for the time being, it's necessary abuse). The only way to garauntee that they all appear on the same line is to use a table tag. That, or display:inline, and use only (Non-Breaking Space) between your elements and words, instead of a normal space. The will help you prevent word wrapping.
But yea, if there's not a legitimate reason for avoiding tables, use tables for tabular data. That's what they're for.
In the age of CSS frameworks, I really don't see a point of drifting away from table tag completely. While it is now possible to do display: table-* for whatever element you like, but table is still a preferred tag to format data in tabular form (not forgetting it is more semantically correct). Just pick one of the popular CSS framework to make tabular data looks nice instead of hacking the presentation of <div> tags to achieve whatever it is not designed to do.
display: block
will certainly not work, try
display: inline
or float everything to the left then position them accordingly
but if you have tabular data, then it is the best to markup in <table> tag
some reference: from sitepoint
You'll need to make sure that all your "cells" float either left or right (depending on their internal ordering), and they also need a fix width.
Also, make sure that their "row" has a fixed width which is equal to the sum of the cell widths + margin + padding.
Lastly make sure there is a fixed width on the "table" level div, which is the sum of the row width + margin + padding.
But if you want to show tabular data you really should use a table, some browsers (more common with previous generation) handle floats, padding and margin differently (remember the famous IE 6 bug which doubled the margin?).
There's been plenty of other questions on here about when to use and when not to use tables which may help explain when and where to uses divs and tables.
Using this code :
<div class="title">MyTitle</div><div class="subject">MySubject</div><div class="Summary">MySummary</div>
You have 2 solutions (adapt css selectors to you case):
1 - Use inline blocks
div
{
display: inline;
}
This will result in putting the blocks on the same line but remove the control you can have over their sizes.
2 - Use float
div
{
width: 15%; /* size of each column : adapt */
float: left; /* this make the block float at the left of the next one */
}
div.last_element /* last_element must be a class of the last div of your line */
{
clear: right; /* prevent your the next line to jump on the previous one */
}
The float property is very useful for CSS positioning : http://www.w3schools.com/css/pr_class_float.asp
The reason the questions page on stack overflow can use DIVs is because the vote/answers counter is a fixed width.
Tabular data can also be represented as nested lists - i.e. lists of lists:
<ul>
<li>
heading 1
<ul>
<li>row 1 data</li>
<li>row 2 data</li>
<ul>
</li>
<li>
heading 2
<ul>
<li>row 1 data</li>
<li>row 2 data</li>
<ul>
</li>
</ul>
Which you can layout like a table and is also semantically correct(ish).
For the text to appear on a single line you would have to use display="inline"
Moreover, you should really use lists to achieve this effect
<ul class="headers">
<li>Title</li>
<li>Subject</li>
<li>Summary</li>
<li>Date</li>
</ul>
The style would look like this:
.headers{padding:0; margin:0}
.headers li{display:inline; padding:0 10px} /The padding would control the space on the sides of the text in the header/
I asked a similar question a while ago Calendar in HTML and everyone told me to use tables too. If you have made an igoogle home page, just yoink their code.
I made a system of columns and sections within the columns for a page. Notice with google you can't have an infinite number of columns and that offends our sensibilities as object people. Here's some of my findings:
You need to know the width of the columns
You need to know the number of columns
You need to know the width of the space the columns inhabit.
You need to ensure whitespace doesn't overflow
I made a calendar with DIV tags because it is impossible to get XSL to validate without hard coding a maximum number of weeks in the month, which is very offensive.
The biggest problem is every box has to be the same height, if you want any information to be associated with a field in your table with div tags you're going to have to make sure the whitespace:scroll or whitespace:hidden is in your CSS.
Preface: I'm a little confused by the responses so far, as doing columns using DIVs and CSS is pretty well documented, but it doesn't look like any of the responses so far covered the way it's normally done. What you need is four separate DIVS, each one with a greater "left:" attribute. You add your data for each column into the corresponding DIV (column).
Here's a website that should help you. They have many examples of doing columns with CSS/DIV tags:
http://www.dynamicdrive.com/style/layouts/
All you have to do is extrapolate from their 2-column examples to your 4-column needs.
You should use spans with:
display:inline-block
This will allow you to set a width for each of elements while still keeping them on the same line.
See here, specifically this section.
Now, to appease the downvoters - of course tabular data should be in a table. But he very specifically does NOT WANT a table. The above is the answer to HIS QUESTION!!!
First display:block should be display:inline-block , Although you might have figured it out already.
Second you can also use display:table , display:table-cell , display:table-row and other properties.
Although these are not as good as using table.