Sorry but just can’t get this working, thankful for any advices,
in example below the browser either ignores the td-width or expands outside the container-div:
Example available at: https://jsfiddle.net/tomjoad2000/1jn9b2f7/
<div>
<div style="width:50%;background-color:#ccc" style="overflow-x:hidden">
<h2>ignores td width:</h2>
<table border="1" width="100%" style="display:block;table-layout:fixed;overflow-x:scroll">
<tr>
<td style="width:400px">asdf</td>
<td style="width:400px">asdf</td>
<td style="width:400px">asdf</td>
<td style="width:400px">asdf</td>
<td style="width:400px">asdf</td>
<td style="width:400px">asdf</td>
</tr>
</table>
</div>
<div style="width:50%;background-color:#ccc" style="overflow-x:scroll">
<h2>ignores overflow-x:</h2>
<table border="1" width="2000px">
<tr>
<td style="width:400px">asdf</td>
<td style="width:400px">asdf</td>
<td style="width:400px">asdf</td>
<td style="width:400px">asdf</td>
<td style="width:400px">asdf</td>
<td style="width:400px">asdf</td>
</tr>
</table>
</div>
</div>
5
Answers
Change:
To :
Error: you are using 2 styles in a single
tag
additionally useauto
instead ofscroll
Please change your css. you can used two time style tag.
style="width:50%;background-color:#ccc" style="overflow-x:scroll"
to
**style="width:50%;background-color:#ccc;overflow-x:auto" **
Use only one style property for a html tag ,too many styles will lose function beside the first one , but you can use more class for a tag
I would do the following:
overflow: auto
If you want to apply the fixed width to the
<td>
then you must assign any width to the<table>
tag width:100% ideally with table-layout: fixed and it is not the<table>
tag which handles the overflow it is actually the parent<div>
tag so you must set overflow-x: auto/scroll to the direct parent of your table.On the other hand you can also assign the fixed width to the
<table>
tag like 2000px without setting it’s table-layout to fixed, the<td>
tags will get the equally divided width or if the content is small or will adjust the width automatically according the content available in<td>
tags or you can still assign extra width to any specific<td>
tag, i hope you get it.