how to place an image at the center of the browser irrespective of the resolution?
i want an image to be placed at the center horizontally irrespective of the dimensions of the image or the resolution of the browse开发者_如何学编程r. How can i do that using html and css?
its for the logo of the website and i want that it always shows up in the center of the header.
you can use this code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<style type="text/css">
#apDiv1 {
margin:0px auto;
top:0px;
width:800px;
text-align: center;
}
</style>
</head>
<body>
<div id="apDiv1"><img src="http://upload.wikimedia.org/wikipedia/en/2/2b/Small-logo.jpg" alt=""/></div>
</body>
</html>
img {
display: block;
margin: auto;
}
You can also see http://www.w3.org/Style/Examples/007/center for more centering tricks.
精彩评论