Here is the scenario: I want exactly something like stackoverflow's comments. A table contained 3 <td>. one for the number of votes, one for shapes (vote up and flag), one for text of comment. So each <td> has its own property:
- VN (Votes Number): If the number not exist, then
width = 0;, also the with of this cell should be dynamic. (for every-digit number) - S (Shapes): This cell has fixed width, it should be noted that the
visibilityof its shapes ishiddenin first and they will be show on hover of<tr>, then the width of this cell always should be assigned. - CT (Comment Text): The width of this cell should be all the remaining width. It should be
word-wrap: break-word;.
The structure:
+--+-+---------------------------------------------------+
|VN|S|CT |
+--+-+---------------------------------------------------+
example1:
+-+-+---------------------------------------------------+
|4|^|this comment is a test...! |
+-+-+---------------------------------------------------+
example2:
+-+------------------------------------------------------+
|^|this comment has not any voteup ...! |
+-+------------------------------------------------------+
example3:
+---+-+---------------------------------------------------+
|123|^|the width of number of vote up cell should be |
| | |changeable and it should be noted that this cell is|
| | |break-word. |
+---+-+---------------------------------------------------+
Here is my try: But it does not work correctly.
HTML:
<div class="container">
<table>
<tr>
<td class="VN">4</td>
<td class="S">^</td>
<td class="CT">this is a sample.</td>
</tr>
</table>
</div>
CSS:
.container{
width: 60%;
}
table{
table-layout: fixed;
width: 100%;
}
td{
word-wrap: break-word;
vertical-align: top;
}
.VN{
width: auto;
}
.S{
width: 10px;
}
.CT{
width: 98%;
}
As I said, I don't know why my code does not work correctly (It should be noted my container is responsive), How can I fix it ? Here is a fiddle of what I did.