I have some table headers like:
<table>
<tr>
<th>
Invoice Number
</th>
<th>
Invoice Date
</th>
...
I'm wanting to get the different words on different lines in the headers so I did this:
<table>
<tr>
<th>
Invoice<br />Number
</th>
<th>
Invoice<br />Date
</th>
...
This works but I'm unsure if it obeys best practises. I have heard on a webcast that you shouldn't really use <br /> anymore and shouldn't use tags to format what your output looks like but should use css so you can change it more easily.
Can anyone suggest a better way to do this?
You could code it as:
<table>
<tr>
<th>
<div>Invoice</div><div>Number</div>
</th>
<th>
<div>Invoice</div><div>Date</div>
</th>
...
Although frankly, I see nothing wrong with that use of the <br /> tag.
You can set the width for all of your table headers with this:
th {width: 60px;}
or you can assign a class so you just make some of them more narrow:
th.narrow {width: 60px;}
You can adjust the font size and width as necessary.
Just a side note: don't forget to add scope for accessibility. If the data is below your header cells then use
<th scope="col">
and put the th in a thead section and the td cells in the tbody section. If your header cells are on the left side of the table and the cells related to those headers are to the right, then use
<th scope="row">.
You could try putting a div inside the th with a specific width and height style to force the second word down.
You could set word-spacing to a sufficiently too-large size. Personally I would probably just let it not wrap.
I was expecting to be able to find a CSS property specifically for forcing breaking on white space, but didn't (upon a cursory search). In case your eyes are better than mine: http://w3.org/tr/css3-text/
Related
Here is a page that I have a problem with:
http://musdesigns.com/invoice/guest/view/invoice/3810b25e7b5c22afe2a33a16974732f4
As you can see, the item name field has a huge margin on the right.
Any idea how to fix this?
I would like it to have a small margin similar to the other fields.
You have to provide specific width for the second "td(column)" or do it for all.
If wish to do only for second "td(column)", then you can do like this also.
<td style="width: 40%;">Item</td>
or
table td:nth-child(2){width:100px;}
or make a class and provide it width and place it on every td
On your <th>Item</th> you can set the width using CSS.
Like:
<th style="width: 40%;">Item</th>
What I am doing seems to work on firefox and IE but not safari.
I have something like this
<table>
<thead>
<tr>
<th style="display: none;">hi</th>
</tr>
</thead>
<tr class="someClass">
<td style="display: none;"><span>hi</span></td>
</tr>
Now imagine I have many columns and rows and many headers. Now in all browsers this coulmn would be hidden. In safari it makes some gap and then all the other columns are out of alignment.
http://gyazo.com/ef5ce5e994abb954aab7069b14699476.png
this is how my column headers look like. Am I missing something?
Setting display:none on an element takes it out of the document flow, but that doesn't always work well with table cells as they are not independent of the surrounding elements.
You would have to actually remove the elements from the table rather than hiding them to make the table realign itself with the remaining elements.
I think I figured it out. I just put that column last(and the header last as well). Now it seems to look proper.
I have been using the page-break-after command to break an html report after each "grouping". My problem is it is now leaving my table floating in the middle of the page. Each page is different where it puts the table, sometimes at the top of the page, sometimes in the middle and sometimes at the bottom. There is quite a bit of complexity in the HTML so I decided to take an image instead:
I will try to sum up the html
<body>
<table>
<thead>
{this is top bold box on each page}
</thead>
<tr>
<td>
<table> {this is the results table}
<thead>
{this is the headers of the "floating" results table}
</thead>
{tr's of data here}
</table>
</td>
</tr>
</table>
</body>
we are using display:table-header-group to get the table headers to show up on each page. Can you help me figure out what I need to do to get those tables to be at the top of the page? (this is in IE8)
Impossible to tell from the information provided. Obviously, a CSS issue but can't tell where to begin. Common problems are the display CSS not completely accounted for in the print CSS and, using display:none; on an child element inside of a div tag that has height defined (removes the content but the space is still there.) The latter is what I suspect. I've found adding background colors to various elements very helpful in debugging CSS problems such as yours.
In a table of mine I have the table header, th which have two separate links in each cell. Each of them wrap to a new line which I don't want. If I remove all the style sheets it doesn't fix it. If i disable style sheets in the browser it fixes it but there are no inline styles that would cause the wrapping. If they are non-hyperlinked words they don't wrap. If I use the td tag it doesn't fix it either. There is too much code all over the shop to post but all I want is in a th cell a word with an image next to it with a different hyperlink.
Here is a quick bit of code. Although doing nowrap does work in this quick look it doesn't work in the actual code for some reason.
<table>
<tr>
<th>Time:</th>
<th style="width: 8%">
V505(2)
<img src = "images/information.png" width = "25" height = "25" border = "0"/>
</th>
<th>Time:</th>
</tr>
</table>
Any reason why you can't do a white-space: nowrap;?
Have you tried setting the width to a measure instead of a %? With no width specified on the Table, the browser might not be sure what 8% means (unless of course, these are specified in some styles).
I am attempting to create a page with tabular data, which must appear as multiple tables. I have two conflicting requirements to get around, however:
Each table must have a border around it.
Column widths for each table must be able to re-size based upon the content. However, the column widths must be consistent across all tables. (i.e. the size of a column is based upon the largest cell in that column across all tables).
To handle the second requirement, I have a single, top-level table which contains multiple thead and tbody sections. This accomplishes #2 beautifully. Essentially, I have created multiple pseudo-tables within a larger parent table, grouped as a single thead with an accompanying tbody:
<table>
<thead>
table1 header content...
</thead>
<tbody>
table1 body content...
</tbody>
<thead>
table2 header content...
</thead>
<tbody>
table2 body content...
</tbody>
</table>
Now, I am attempting to address the first requirement. Each pseudo table must have a border around it, passing itself off as a genuine table.
I have found, to my dismay, that IE 6/7 do not allow for adding border styles around thead/tbody tags, or I would simply have added a top/left/right border style to thead and a bottom/left/right border style to tbody.
Creating genuine tables and styling borders for those works to solve #1, but it breaks #2.
Another alternative would be to use first-child and last-child styles to create my borders. Unfortunately, this is neither pretty, nor does it work in IE 6/7.
Another alternative I have been looking into is creating a border around the entire table and attempting to create a row between the pseudo-tables which creates my separation, but while I can create top/bottom borders for it ok, I have yet to discover a means to erase the table's left/right border for just that row. Is that possible?
My last-ditch alternative is to create classes for drawing left, right, top, and bottom borders, setting the appropriate table cells to use these classes. I know this will ultimately work, but it is horribly clunky and makes for really messy markup. Colgroups cannot save me here, as they are incapable of handling border styles. That is unfortunate, as it would make this solution a little easier to stomach.
Is there a better method to accomplish the borders that I may have missed?
use <table rules="groups"> or similar values for rules
see http://www.w3.org/TR/html4/struct/tables.html#h-11.3.1
Go with the method for creating the genuine tables, then try this.
I would just go with creating separate tables. Let's suppose each table looks like this:
<table>
<thead>
<tr>
<th class="column_1">Header 1</th>
<th class="column_2">Header 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>Column 1</td>
<td>Column 2</td>
</tr>
...
</tbody>
</table>
Then, use jQuery to set the width:
var columnOneWidth = 0;
var columnTwoWidth = 0;
$(document).ready( function() {
$(".column_1").each( function() {
if( $(this).css("width") > columnOneWidth ) columnOneWidth = $(this).css("width");
});
$(".column_2").each( function() {
if( $(this).css("width") > columnTwoWidth ) columnTwoWidth = $(this).css("width");
});
$(".column_1").css({width: columnOneWidth + "px"});
$(".column_2").css({width: columnTwoWidth + "px"});
});
All you have to do is include the jQuery Javascript file (available from jquery.com) in your head tag:
<script type="text/javascript" src="scripts/my_jquery_file.js"></script>