Toggle navigation
Bootsnipp
Bootstrap
For
CSS Frameworks
Bootstrap
Foundation
Semantic UI
Materialize
Pure
Bulma
References
CSS Reference
Tools
Community
Page Builder
Form Builder
Button Builder
Icon Search
Dan's Tools
Diff / Merge
Color Picker
Keyword Tool
Web Fonts
.htaccess Generator
Favicon Generator
Site Speed Test
Snippets
Featured
Tags
By Bootstrap Version
4.1.1
4.0.0
3.3.0
3.2.0
3.1.0
3.0.3
3.0.1
3.0.0
2.3.2
Register
Login
"Force table row to be 100 percent of table when thead is fixed"
Bootstrap 3.3.0 Snippet by
wesnoel
3.3.0
table
Preview
HTML
CSS
View Full Screen
Fork
Fork this
8.8K
 
2 Fav
Post to Facebook
Tweet this
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script> <script src="//code.jquery.com/jquery-1.11.1.min.js"></script> <!------ Include the above in your HEAD tag ----------> <div class="container"> <div class="row"> <div class="bs-twrapper"> <table class="table table-bordered"> <!-- We are wrapping the thead in an extra tr (nesting) this will allow us to give the body a percentage width --> <thead class="sticky"> <tr> <th>#</th> <th>Name </th> <th>Points</th> </tr> </thead> <!-- We are also wrapping the tbody in an extra tr (nesting) this will allow us to give the body a percentage width --> </table> <table class="table table-bordered"> <tbody> <tr> <td>54</td> <td>Mike </td> <td>77</td> </tr> <tr> <td>54</td> <td>Mike </td> <td>77</td> </tr> <tr> <td>54</td> <td>Mike </td> <td>77</td> </tr> <tr> <td>54</td> <td>Mike </td> <td>77</td> </tr> <tr> <td>54</td> <td>Mike </td> <td>77</td> </tr> <tr> <td>54</td> <td>Mike </td> <td>77</td> </tr> <tr> <td>54</td> <td>Mike </td> <td>77</td> </tr> <tr> <td>54</td> <td>Mike </td> <td>77</td> </tr> <tr> <td>54</td> <td>Mike </td> <td>77</td> </tr> <tr> <td>54</td> <td>Mike </td> <td>77</td> </tr> <tr> <td>54</td> <td>Mike </td> <td>77</td> </tr> <tr> <td>54</td> <td>Mike </td> <td>77</td> </tr> <tr> <td>54</td> <td>Mike </td> <td>77</td> </tr> <tr> <td>54</td> <td>Mike </td> <td>77</td> </tr> <tr> <td>54</td> <td>Mike </td> <td>77</td> </tr> <tr> <td>54</td> <td>Mike </td> <td>77</td> </tr> </body> </table> </div> </div> </div>
.bs-twrapper{ height:260px; overflow-x:scroll; overflow-x:hidden; border-bottom:solid 2px #353535; padding-top:39px; } table{ position: relative; margin: 10px auto; padding: 0; width: 100%; height: auto; border-collapse: collapse; text-align: center; } table > thead.sticky{ height:42px; position:fixed; background:#fff; width:100% !important; margin-top:-40px; } table > thead.sticky > tr{ width:500% !important; } table > thead th:nth-of-type(odd) { width:10%; } table > thead th:nth-of-type(even) { width:80%; } table > tbody td:nth-of-type(odd) { width:10%; } table > tbody td:nth-of-type(even) { width:80%; } tbody.scroll{ width:100%; }
Questions / Comments:
Post
Posting Guidelines
Formatting
- Now
×
Close
Donate
BTC: 12JxYMYi6Vt3mx3hcmP3B2oyFiCSF3FhYT
ETH: 0xCD715b2E3549c54A40e6ecAaFeB82138148a6c76