Why does the CSS property overflow:scroll; not work in <td>, while overflow:hidden; works well?
<table border="1" style="table-layout:fixed; width:100px">
<tr>
<td style="overflow:scroll; width:50px;">10000000000000000000000000000000000</td>
<td>200</td>
<td>300</td>
</tr>
</table>
From the CSS specs1,2, I can't see why.
You have to wrap it in a div, that will work:
<table border="1" style="table-layout:fixed; width:500px">
<tr>
<td style="width:100px;"><div style="overflow:scroll; width:100%">10000000000000000000000000000000000</div></td>
<td>200</td>
<td>300</td>
</tr>
</table>
Firstly provide desired height to td and then Apply "float: left" property to respective "td" you want scrollbar to appear.
I got something from here!
Andrew Fedoniouk wrote:
This is actually my question:
"One technical reason is that the overflow property does not apply to
tables." - why? What is this reason?
I'm no expert, but I believe this is
just for backward compatibility with
legacy table behavior. You can check
the "automatic" table layout
algorithm in the spec. I'm pretty
sure that this layout algorithm is
incompatible with the overflow
property (or, more accurately, the
layout algorithm will never result in
the need for any value of overflow
except 'visible').
Yep, this is why I am asking. Seems like there are no formal reasons
why or should not be scrollable but seems like
UA vendors reached some silent agreement in this area. So is the
question.
The spec agrees with you with respect
to elements. Table cells are
supposed to respect overflow, although
Mozilla, at least, appears not to do
so. I can't answer your question in
this instance, although I would still
guess the answer is still tied to
legacy rendering.
The main thread is here.
<table border="1" style="table-layout:fixed; width:500px">
<tr>
<td style="width:100px;"><div style="overflow:scroll; width:100%">10000000000000000000000000000000000</div></td>
<td>200</td>
<td>300</td>
</tr>
</table>
Related
When adding a CSS transformation like transform:translate(0px, -45px) to a table row, Internet Explorer (tested 10 and 11) and Microsoft Edge do not correctly display the transformation.
Using some simple code as an example:
<table style="width:500px;">
<tbody>
<tr style="height: 30px; background-color:red; color:white;">
<td>1</td>
</tr>
<tr style="height: 30px; background-color:blue; color:white;">
<td>2</td>
</tr>
<tr style="height: 30px; background-color:yellow; color:black; transform:translate(0, -45px);">
<td>3</td>
</tr>
</tbody>
</table>
This screenshot shows the problem: row 3 should be positioned on top of rows 1 and 2, but in IE/Edge, it hasn't moved. Almost any other modern browser behaves as expected. Microsoft notes that IE 10+ and Edge should support (unprefixed) transform, and based on the standard, elements with display table-row are supported.
Does anyone have any clue why this doesn't work?
As defined in the spec, transformable-elements includes elements whose display property computes to table-row. As such, you are correct to expect transform to relocate table rows on the screen. Microsoft Edge appears to lack this support.
Edge does, however, translate table cells. This may provide temporary relief for the time being. I am going to work up a few tests to ensure that we are accurately implementing this functionality.
Yeah, I am facing the same issue. You can make the tr display:block but... this will destroy your table. Let's hope microsoft will deal with this fast.
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 am currently re-styling a site but unforunately I am unable to edit any of the markup, which leads me to the following problem...
I have a table, similar to this:
<table>
<tr>
<td>Some content</td>
<td>Some content</td>
</tr>
<tr>
<td>Some content</td>
<td>Some content</td>
</tr>
<tr>
<td>Some content</td>
<td>Some content</td>
</tr>
</table>
and I want to display all the table cells on one line. In good browsers, I'm using:
table tr {
display: inline;
float: left;
}
to achieve this. However, this doesn't work in IE7. Is there any other CSS I can use to achieve the same effect? I have to stress that I have no access to the markup whatsoever and none of the table rows or cells have any way of accessing them directly so there's no way I can position absolutely.
You can't do that, I believe.
A tr is a table row and I'd expect the unexpected when trying to float one.
Besides, any element floated is instantly a block level element, so display: inline is redundant.
(The only exception when using it to prevent double margin bug in IE6 - but only if you have a margin set).
You could restructure the HTML with JavaScript, but I would not recommend you do that:)
I agree with #Pekka that this is illegal. The best course of action here would be to add small js to transform table into somethings else. If you have access to just css you can still do that for IEs by adding a behavior and for other browser if that work - just use your solution.
You can attempt inline-block but styling table elements with things such as float is a sin. You can attempt hiding the entire table and insert some load of loading icon while you extract the table info and display it with semantic markup.
Best course of action in this case is to ask for access. Just say you can't do the work without access to the markup. If they won't let you, just don't do the work.
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
I am developing a card board which is 4x3. So I have tryed to do markup with XTHML Transitional. I have used containers mixed with tables.
The example for first row:
<table>
<tr>
<div class="slot_01"></div>
<div class="slot_02"></div>
<div class="slot_03"></div>
<div class="slot_04"></div>
</tr>
<tr>
...
</tr>
</table>
Is this correctly done? Or its better to use only div/span blocks instead everywhere and make styling through css?
If you use a table, use table, tr, td, not div.
I think most people nowadays try to avoid tables for anything but "really tabular data" and prefer the "pure CSS" solution.
It depends a bit on your overall markup (e.g. what you want to display in the cells). In your case, I guess I would go for a tableless solution.
No, You need td's in there, like this:
<table>
<tr>
<td></td>
<td></td>
</tr>
</table>
If you really need to, put your divs inside the TDs.
If your data is tabular in nature there's nothing wrong with using tables. Everyone else is correct - you need to use table cells instead of the divs in your sample code.
Ideally use div/span blocks if you can, but the above code is ok, you just need to wrap each div in a td element:
<table>
<tr>
<td><div class="slot_01"></div></td>
<td><div class="slot_02"></div></td>
<td><div class="slot_03"></div></td>
<td><div class="slot_04"></div></td>
</tr>
<tr>
...
</tr>
</table>
For the lay out of the entIre page I would do it tableless. Remember: XHTML is for structure, CSS for displaying the structure.