Horizontal scrollbar only appearing at bottom of page
Its because your document (body
) isnt stretched to the full height of the viewport (html
), you need to assign height:100vh
, also remove your overflow settings so you dont get 2 scrollbars appearing (one on body
one on html
).
Simply change your CSS to:
html,body{
height:100vh;
width:100vw;
margin: 0;
padding: 0;
}
Why is a horizontal scroll bar appearing if none of the elements are wider than the 960px container?
Try add overflow hidden:
#main_wrap{
margin:0 auto;
width:960px;
position:relative;
overflow: hidden;
}
That should work (but is hacky).
Table inside a div - horizontal scrollbar only at the bottom of the div
How about something like this?
$("#scrollbar").on("scroll", function(){ var container = $("#container"); var scrollbar = $("#scrollbar"); ScrollUpdate(container, scrollbar);});
function ScrollUpdate(content, scrollbar){ $("#spacer").css({"width":"500px"}); // set the spacer width scrollbar.width = content.width() + "px"; content.scrollLeft(scrollbar.scrollLeft());}
ScrollUpdate($("#container"),$("#scrollbar"));
$("#tab").tableHeadFixer({ "left": 1, "right": 0, "head": true});
#container { width: 300px; height: 300px; background: green; overflow-x: hidden !important; overflow-y: auto; position: absolute; left: 0px; top: 0px;}
#scrollbar { position: fixed; left: 0px; bottom: 0px; width: 300px; overflow-x: scroll; overflow-y: hidden; z-index: 10;}
#spacer { height: 1px;}
#tab { width: 500px; height: 500px; background: #CCCCCC;}
tr,td { border: 1px solid black;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script><body>
<div id="scrollbar"><div id="spacer"></div></div>
<div id="container"> <table id="tab"> <thead> <tr> <th>Title</th> <th>Name</th> <th>History</th> </tr> </thead> <tbody> <tr> <td>test</td> <td>test</td> <td>test</td> </tr> <tr> <td>test</td> <td>test</td> <td>test</td> </tr> <tr> <td>test</td> <td>test</td> <td>test</td> </tr> <tr> <td>test</td> <td>test</td> <td>test</td> </tr> </tbody> </table></div>
Related Topics
CSS Pseudo-Element: :Before(2);: Before and: :Before
CSS Media Queries: Target Mobile Devices Without Specifying Width, Pixel Ratio, etc
Definition List with Inline Pairs
Putting an Image as a Frame Around an Iframe
Bootstrap Navbar-Static-Top Menu Breaks on Two Lines
How to Prevent Shifting When Changing Border Width
How to Style Radio Button or Checkbox Inside a Bootstrap Table
@Font-Face Fonts Showing Blurred on MAC in Safari and Chrome
Font Awesome Icons Not Working in Osx Safari
Bootstrap Collapse Accordion - Default Expand/Collapse
Why Does Adding Float:Left to My CSS Make My Link Unclickable
Remove Dotted Border/Outline of Focused Dropdown Menu
Em Vs Px and Cross Browser Compatibility
Hiding Text Using "Text-Indent"
Bootstrap 3 and .Col-Xs-* - Do You Not Need Rows of 12 Units