I have made bars in a waterfall diagram that I want to be look like blocks on each other. They are inline-blocks programmatically set to a width and adjusted sideways by margin-left.
The javascript to set innerHTML is irrelevant in this case, but the minimal CSS and HTML I have experimented on is below. Run this fiddle to see how it looks like:
* { padding:0; margin:0; }
div { display:inline-block; }
table {
width:100%;
white-space:nowrap;
cellpadding:0;
}
td { border:solid 1px black; }
.bar{
margin:0;
border:solid 1px red;
background:yellow;
}
.padOnlyThisCell{
padding:20px;
}
.padNotThisCell{
padding:0;
}
<br>
<table cellspacing="0">
<tr>
<td class='padOnlyThisCell'>
First column
</td>
<td class='padNotThisCell'>
<div class='bar padNotThisCell' style='margin-left:30%; width:30%'><sub> Why does this bar have margin? </sub></div>
<sup> Why does this cell have padding?</sup>
</td>
</table>
<br>
There is an unwanted table cell padding despite padding:0
everywhere but not in the cells of first column where padding is wanted.
What I want is a bar with upper and lower red border touching it's surrounding black border.
It's the same in both Chrome and Firefox: The padding
in the first <td>
affects the other <td>
in the <tr>
. Why? How to change this code to not have space above and under the bar without loosing the padding in first column?