"Box always in center"
Bootstrap 3.0.0 Snippet by vishalsingh119

<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.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 id="test"> </div>
#test{ background:red; width:100px; height:100px; position:absolute; }
$(document).ready(function(){ function move_div(){ window_width=$(window).width(); window_height=$(window).height(); obj_width = $('#test').width(); obj_height = $('#test').height(); console.log(obj_width) $('#test').css('top',(window_height/2)-(obj_width/2)).css('left',(window_width/2)-(obj_height/2)) } move_div(); $(window).resize(function(){ move_div(); }); });

Related: See More


Questions / Comments: