Is there a way to position a column in a table so that it doesn't scroll along the x axis, but scrolls along the y? Perhaps some way to use absolute positioning that only effects one (like a spreadsheet. The header stays at the top, like absolute positioning)?
Note: I want to avoid using Javascript
EDIT: I need to have the overflow for the table set to scroll
OK I found an example that works the way I want: http://cross-browser.com/x/examples/xtable.php,
or this one: http://www.disconova.com/open_source/files/freezepanes.htm but I can't figure out what they do to make it work.
I ended up using Javascript anyway.
For fixed columns I found a great Javascript toolkit called DataTables and it has a plug-in called FixedColumns that allows fixed columns. Link.
I'm pretty sure you use
overflow-y: hidden;
For example, take a look at this website.
http://www.brunildo.org/test/Overflowxy2.html
In the following example we can create a table inside a table, not the cleanest idea but it should work.
<TABLE BORDER="2" CELLPADDING="5" CELLSPACING="5">
<TD>
<div style="width:325px; height:48px; overflow-y:scroll;">
<TABLE BORDER="0" CELLPADDING="3" CELLSPACING="3">
<TD>inside the first one<br />
we can add text and enable<br />
overflow-y for vertical<br />
scrolling.</TD>
</TABLE>
</div>
</TD>
<TD> This is a different table. You can edit this to fit your needs.</TD>
</TABLE>
Note: Head over to w3schools to try it on the fly, that way you can test it and learn from it ;) - http://www.w3schools.com/cssref/css3_pr_overflow-y.asp
If you want to do it with tables you would have to do something like this
<table>
<tr><td>col1 name</td><td>col2 name</td></tr>
</table>
<div>
<table>
<tr><td>col1 row1 data</td><td>col2 row1 data</td></tr>
<tr><td>col1 row2 data</td><td>col2 row2 data</td></tr>
<tr><td>col1 row3 data</td><td>col2 row3 data</td></tr>
</table>
</div>
Then you need to set styles appropriatley, make sure that the widths of each cell in the header is the same as the width you set for each column in the second table this will make your header and the data table lign up. Make the div scrollable so the data parts of the table will scroll while the header parts remain static.
You could do a similair thing for row headings too by placing a table to the left of the data table and making sure you offset the column header table appropriatley to the right.
I am not going to write out all the css though as I am sure you can figure this out.
You can wrap the table in a container with a fixed width and set it's overflow property.
<div id="foo">
<table>
<tr>
<td>a</td><td>b</td><td>c</td><td>d</td>
</tr>
<tr>
<td>a</td><td>b</td><td>c</td><td>d</td>
</tr>
<tr>
<td>a</td><td>b</td><td>c</td><td>d</td>
</tr>
</table>
</div>
CSS
#foo {
width: 100px;
overflow: auto;
}
Your table will obviously need to have the data displayed width-wise. Adding more rows won't cause it to scroll unless you specify a height to the container as well.
DEMO
Related
I open this post after I looked at this post without success: How to set table column widths to the longest value, excluding header
I want to draw a table, and I want that the width of each column will be compatible to the longest text in this column. For example, if the following values lie in column A: "abc", "abcd", "abcde", the width of column A will be 5 characters long.
I tried:
td {
white-space: nowrap;
overflow: hidden;
}
How can I do it?
I think that's the default behavior of tables. Have made a simple table that just behaves as you want it (refer this JSFiddle). The column width is equal to the longest text in them.
<table>
<thead>
<th>Column A</th>
<th>Column B</th>
</thead>
<tbody>
<tr>
<td>abc</td> <td>abcdefghijklm</td>
</tr>
<tr>
<td>abcdefghijklmno ddsp</td> <td>ab</td>
</tr>
<tr>
<td>ab</td> <td>ab</td>
</tr>
</tbody>
</table>
Not sure if you wanted to ask something else ?
Add this styling to your table and td:
table {
table-layout:fixed;
}
td {
width:1px;
white-space:nowrap;
}
If this doesn't work, make sure that these are the only styling attributes being set to your table and td. This will help you figure out if other styling attributes are causing conflicts ruining the mentioned styling you want to achieve.
On a similar issue happened with me, these styling attributes weren't working with me because I was setting width attribute to the table with them. When I removed it, everything worked good as expected.
A quote from the original post I got the solution from:
If the text is non wrapping text then you set the cell to width:1px and use white-space:nowrap. The text in that column will then determine the width of the cell.
It's a technique commonly used for images and captions (without the white-space:nowrap) and allows text to wrap at the limits of an image automatically.
Try styling the text to not wrap:
{
white-space: nowrap;
overflow: hidden;
}
And do not set width settings on your table, tr and td elements.
See if that works.
I'm trying to implement a table with editable cells using an approach like this. The cell contains a label or span and also an input box, and I'm using a flag to decide which one to display via ng-show. But when the label is made visible, the cell expands vertically. It's subtle in that demo but you can see the second row moving down slightly.
How can I make it remain the same size, like the editable table rows in this example? I've looked at the styles in that example but I can't figure out how it's being done. The span for non-edit mode seems to have the dimensions as 'auto' but when the input form appears, it has explicit width/height - and they happen to be exactly the same.
PS. I'm open to the idea that the way I'm doing it isn't optimal, in which case any alternative suggestions would be great.
<div ng-controller="MyCtrl">
<table>
<tr>
<td>
<label ng-click="editing=true" ng-show="!editing">{{ mytext }}</label>
<input ng-blur="editing=false" ng-show="editing" ng-model="mytext" />
</td>
</tr>
<tr>
<td>
<label>some more text</label>
</td>
</tr>
</table>
</div>
I found out why the cells don't expand in the xeditable example that I linked to in my question - it's because there's an explicit size set in the css:
div[ng-controller] table tr td {
height: 45px;
/*text-align: center;*/
vertical-align: middle;
}
I didn't find this at first because I was looking in the css file that comes with the package, and I couldn't find any rules in there that would explain it. But it's actually defined in another css file for the demo page itself (https://vitalets.github.io/angular-xeditable/docs/css/docs.css).
I want this layout where I have a rectangular box. And inside the box on the left there is a text and on the right there is an image. This looks fine in the browser, but when sent out as an html email, in outlook the float right doesn't seem to work. It puts the image in the next line under the text. Any ideas on how to make this work? (I am trying to avoid using tables.)
<div style="width: 100%;border-style:solid;overflow: hidden;">
<span style="float: left;">
<h3> Your appointment Details</h3>
</span>
<span style="float: right;">
<img src="someImage"/>
</span>
</div>
Very late to the conversation, but here is how to "float" in html email using align="" instead.
Example here
Also, if you are looking for resources on html email (I assume you are as the answer you marked correct is very general), here is a huge list of resources.
This is a really good guide from Mail Chimp on Coding for HTML Emails:
http://kb.mailchimp.com/article/how-to-code-html-emails
Some basic tips:
Use tables for layout.
Set your widest table to be maximum of 600px wide.
Don't try and use JavaScript or Flash
Don't use CSS in a style tag as some mail clients will discard it.
Use inline CSS styles only.
Basically code your emails as if it was roughly 2003.
CampaignMonitor provide this rather brilliant guide to all CSS support across multiple email clients, which is also available as a pdf or xls download.
As the answers above say, email support for CSS is very limited, mostly due to Microsoft's descision to use Word as its html rendering engine.
Simple floating images can be like
<img src="yourimage" align="left" />
BUT that way you won't get solid results with padding between text and image, outlook removes margin and padding and your text will stick right next to the image. So try this:
<div style="text-align:justify;">
...a lot of text here untill you want to insert an image that floats left...
<table cellpadding="0" cellspacing="0" align="left" style="float: left;">
<tr>
<td>
<img src="yourimage" align="left" vspace="4" />
</td>
<td width="15"> </td>
</tr>
</table>
...a lot more text here until you need an image that floats right...
<table cellpadding="0" cellspacing="0" align="right" style="float: right;">
<tr>
<td width="15"> </td>
<td>
<img src="yourimage" align="left" vspace="4" />
</td>
</tr>
</table>
... a lot more text here...
</div>
You need to wrap a 'table' element around it to get the padding-margin effect to work in Gmail, Outlook (online), Microsoft Outlook (desktop client),...
Give the table an align=left or right attribute. (Edit answer here: in addition and fallback for other email clients also give the table a float value so do both. They are back-ups to each other. Some clients understand "float", others understand "align", some understand both,...) Your table will float in the text almost like an image does. The only difference is that in outlook a table generates an automatic line break in the text where an image with align left or right does not generate breaks.
For setting the margin, since we are now working with a table, add an extra "td" with a width="15" to the left or right of your image cell and a non-breaking-space in it. (or a transparant gif -> spacer.gif)
You better not leave cells empty because otherwise the width of your cell will not be respected in certain email clients
For top and bottom margin we can use the 'vspace' attribute, don't forget to give the image an align = left or right attribute. Otherwise the 'vspace' will not work.
I've found a way to apply float on Outlook.com.
Just capitalize the tag like Float:left.
<span style="Float:left;">Content to float</span>
Maybe you should use !important too;
I tested it and it worked.
check out https://www.campaignmonitor.com/css/ here it has listed what are all the things supported and not supported in email
Instead of float you can use an outer table and put contents you want to float left in left td of outer table.
this is not an elegant answer but I did it this way
When you are floating something to the right of something the right floating element should allways apear first in code. Like this:
<div style="width: 100%;border-style:solid;overflow: hidden;">
<img src="someImage" style="float: right;"/>
<h3> Your appointment Details</h3>
</div>
I'm trying to build web app designed for mobiles. But I have some links which are extremely large. What i want to do is break these strings if the text doesn't fit, and use the entire string if it fits.
I tried using word-wrap:break-word:
.breakWord {
width: 100%
word-wrap: break-word;
}
My html is:
<table>
<tr>
<td rowspan="2" style="width:10%" >picture</td>
<td colspan="2" style="width:90%" class="breakWord">link</td>
</tr>
<tr>
<td style="width:80%">info1</td>
<td style="width:10%">info2</td>
</tr>
<tr>
</tr>
</table>
This code doesn't fit on the page - a horizontal scroll bar appears.
How can I make the text fit?
If you correct the errors in your source, it will work.
Remove the width:100% from the style block. It conflicts with the inline style in the td, and misses a semicolon
colpan should be colspan
Also, I believe that some browsers can get confused when encountering a colspanned td with a width style. You can safely remove the style="width:90%", since the two tds below set the width correctly already.
Edit:
So it doesn't work everywhere. According to the answers to this question, the problem is with the table: first, the width of the table is calculated, and then the 10% and 90% are taken as the calculated width instead of the available width on the screen.
So a possible solution is to give the table a specific width, and set its table-layout to fixed.
<table style="width:100%; table-layout:fixed">
I'm trying to give even spacing all around images I have in a table, and it's not working too well.
Look at the page. I tried margin, padding, everything I could on lots of different types of properties, but no luck. Any help?
The table has been created in an unusual way by photoshop - resulting in dodgey markup.
There a differing amount of <td>'s in the first row compared to the others
There are several spacer images which have been created by photoshop; which are redundant
There should be no need for the use of rowspans in your <td>'s
To fix this issue I would suggest modifying your table so the structure looks like this:
<table cellpadding="5">
<tr>
<td><img src="images/index_01.png" width="463" height="200" alt=""></td>
<td ><img src="images/index_02.png" width="465" height="200" alt=""></td>
</tr>
....
Then keep adding blocks of table rows e.g.:
<tr>
<td>... </td>
<td>...</td>
</tr>
with your links and images replacing the '...'. then finally close the table:
</table>
Hope this helps.
The problem is your rowspan="2" on your second cell... remove that and the spacing evens out. You may also want the following CSS (tested with Firefox/firebug rewrites)
<style>
#Table_01,#Table_01 a {margin:0;padding:0;}
#Table_01 img {padding:1em;}
</style>
Try specifying value for cellpadding attribute for the table.
Your markup is all wrong. You have TDs using rowspan when its not needed and i see some spacer gifs. Fix the markup and you wont have any issues with using cellpadding