Skip to content

Instantly share code, notes, and snippets.

@rajeshg
Created October 29, 2009 02:58
Show Gist options
  • Save rajeshg/221076 to your computer and use it in GitHub Desktop.
Save rajeshg/221076 to your computer and use it in GitHub Desktop.
<html>
<head>
<style type="text/css">
div#centered {
position: absolute;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js">
</script>
<script type='text/javascript'>
$(document).ready(function(){
var height = $('#centered').height();
var width = $('#centered').width();
var docheight = $(document).height();
var docwidth = $(document).width();
var top = (docheight - height)/2;
var left = (docwidth - width)/2;
$('#centered').css('top', top+'px');
$('#centered').css('left', left+'px');
});
</script>
</head>
<body>
akjdakfjdkf
<div id="centered">
<p>Paragraph 1 text.</p>
<p>Paragraph 2 text.</p>
</div>
kadjkfjadkf
kajfkadjf
<div>
akjfkdajfk
</div>
<p>ajdfkdjaf kajfkdajf .jkjakdjfakdjf.
kadjfkadjfka.
kdjfkajdfkdajf kajdfkadjf kjfkajdfka. </p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment