Sunday, 8 March 2015

Make a Div Align Center Using J-query

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>

For more kindly visit http://findnerd.com/NerdDigest/Html

No comments:

Post a Comment