I have implemented a style that changes the layout of a table to fit a smartphone screen, based on this answer.
It does what I am asking it to do except for 1 thing: it does not allow for any word wrapping, for reasons that will become obvious. Problem is: I need word wrap for the table to fit on the table screen.
For illustration, I created this JSFiddle.
If the view is sufficiently narrow, the layout changes as expected but the cells containing word wrapping have this annoying behavior that the 2nd line ignores the padding.
This is caused by the display:inline
in the CSS (Specifically, the one with the commented /*-block*/
next to it.
This is the result.
When uncommenting the -block
to have display:inline-block
, then the padding is not ignored as desired but the borders get disconnected from the table on the left, and extend outside the table on the right.
What is the way to get the best of both worlds (correct border as in the first screenshot but with paddings as in the second)?
2
Answers
This is a feature of an inline formatting context.
Are you sure you don’t want
inline-block
instead?The extending outside to the right is of course the result of 100% width plus .5em padding on each side – that could be fixed using
box-sizing
.But that still doesn’t get your "borders" extended.
So let’s simply make the element
block
to begin with, and remove the width.And your borders, which – luckily, in this instance – are made via pseudo elements already, can then simply be extended to cover the necessary width, by giving them a negative margin matching the padding on either side.