Table Cells Overflow Despite Box-sizing: Border-box
I want to add padding to the cells of my table, but this causes text, inputs, etc inside the table to overflow. From other Stack Overflow discussions, I've gathered that the answer
Solution 1:
set the width of the input so it will fill the table cell
input{
max-width: 100%;
}
* {
box-sizing: border-box;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
}
table,
th,
td {
border: 1px solid black;
padding: 1.5%;
}
table {
border-collapse: collapse;
}
input {
max-width: 100%;
}
<!DOCTYPE html>
<table>
<tr>
<td>Lorem ipsum dolor sit amet, consectetur adipiscing elit</td>
<td><input value=1></td>
</tr>
</table>
EDIT: thanks @javier Rey for the correction
Solution 2:
Ensure the input
inside the td
only spans to the cell's width.
* {
box-sizing: border-box;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
}
table {
border-collapse: collapse;
}
th, td {
border: 1px solid black;
padding: 1.5%;
}
td>input {
max-width: 100%;
}
<table>
<tr>
<td>Lorem ipsum dolor sit amet, consectetur adipiscing elit</td>
<td><input value="1"/></td>
</tr>
</table>
Post a Comment for "Table Cells Overflow Despite Box-sizing: Border-box"