If you have a position: fixed on the element. it can only be controlled by the browser window, it cannot be controlled by the parent div. so if you add a width: 25% will fill 25% of your browser window. not in the parent div.
i has 2 solutions,
- use javascript. dynamically add width to 'px' and add position: fixed after
- usage position: absolute. instead of fixed. (In fact, your growth is 100%, so it does not matter, your position is corrected.)
1st solution: javascript approach [code sample] :
//remove position:fixed from #one #one { float: left; width: 25%; background: #666; height: 100%; } <script src="http://code.jquery.com/jquery-2.1.4.min.js"></script> <script type="text/javascript"> var calWidth = $("#one").width(); </script>
2nd solution: CSS approach [sample code]
#wrap{ position:relative; } #one{ position:absolute; }
source share