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
Your background-position
values are around the wrong way. It should be:
background-position: 50% 0; /* Short values FTW! */
Don't forget if you want it to stay centered, you'll also need to do something like wrap the content in a container and use margin:0 auto
on it to keep everything centered.
HTML:
<div class="wrap">
<div class="header"></div>
</div>
CSS:
.wrap {
width:1010px;
margin:0 auto;
}
.header {
width:1010px;
height:265px;
background:transparent url('//placehold.it/1010x265') no-repeat;
}
Demo: jsfiddle.net/UGDxU/show (or edit it)
The order of background-position
is left top
. Try flipping the values.
You'll also need background-repeat: no-repeat
.
jsFiddle.
精彩评论