I am using bootstrap 3. I wanted the input field get fit inside my table. Here is my code, I want to do it in table-bordered class of bootstrap. here is the code:
<table class="table table-bordered table-hover">
<thead>
<tr>
<th class="col-md-4">Organization:</th>
<th class="col-md-4">City:</th>
<th class="col-md-2">From:</th>
<th class="col-md-2">To:</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="name in getdrugnameNewArray">
<td>Stackoverflow</td>
<td>2001</td>
<td>2009</td>
</tr>
</tbody>
</table>
CSS code :
td>input {
margin: 0;
height: 100% !important;
display: inline-block;
width: 100%;
border-radius: 0 !important;
}
I need my <td>
cell be the input field as such. Any help is appreciated. Thanks.
Set the heights of input elements using classes like . input-lg and . input-sm . Set the widths of elements using grid column classes like .
We can also adjust the size of input elements in bootstrap by the use of classes like . input-lg and . input-sm for adjusting heights and . col-lg* and .
Use the . input-sm class to set small input field in Bootstrap.
Bootstrap provides a series of classes that can be used to apply various styling to the tables such as changing the heading appearance, making the rows stripped, adding or removing borders, making rows hoverable, etc.
One way to achieve this, is by making the input absolutely
positioned so that it bypasses its parents padding/margin (td), of course the parent has to have position: relative;
Demo:
table td {
position: relative;
}
table td input {
position: absolute;
display: block;
top:0;
left:0;
margin: 0;
height: 100%;
width: 100%;
border: none;
padding: 10px;
box-sizing: border-box;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<table class="table table-bordered table-hover">
<thead>
<tr>
<th class="col-md-4">Organization:</th>
<th class="col-md-4">City:</th>
<th class="col-md-2">From:</th>
<th class="col-md-2">To:</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="name in getdrugnameNewArray">
<td>Stackoverflow</td>
<td>2001</td>
<td>2009</td>
<td><input type="text" placeholder="2016"></td>
</tr>
</tbody>
</table>
jsFiddle: https://jsfiddle.net/azizn/dp0yLa3d/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With