Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Make a div align center using jquery

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 569
    Comment on it

    Hello Readers !

    Here is an example, how to make a div always center align using jquery. You can do this using css but this method will work with positions (absolute, fixed etc) and it is also compatible with internet explorer.

    <script>
        $(document).ready(function(){
          var windowWidth = $(window).width();
          var divWidth = $("div").width();
          $("div").css({"margin-left":(windowWidth-divWidth)/2});
        });
    </script>
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: