Search code examples
htmlcssbackground-imagebackground-position

CSS background-position not applying to my class


Here is my CSS:

.header
{
    background-image:url(Images/head.png);
    background-position: center top;
    background-repeat:no-repeat;
    width:1010px;
    height:269px;
}

This is my HTML:

<!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>xSky Software - Most likely the only software on Clickbank that exists.</title>
<link href="style.css" rel="stylesheet" type="text/css" /> 
</head>
<body>

<div class="header"></div>
</div>
</body>
</html>

I am trying to get my image centered on the X-axis, and top'ed on the Y-axis. However my CSS class .header wont do that. Can you see what I am doing wrong?

EDIT: Turning the top center around does not work either


Solution

  • The order of background-position is left top. Try flipping the values.

    You'll also need background-repeat: no-repeat.

    jsFiddle.