1

これが私のCSSです:

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

これは私の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>

画像をX軸の中央に配置し、Y軸を上に配置しようとしています。しかし、私のCSSクラス.headerはそれを行いません。私が間違っていることがわかりますか?

編集:上部の中心を回転させることも機能しません

4

2 に答える 2

2

あなたのbackground-position価値観は間違った方向にあります。そのはず:

background-position: 50% 0; /* Short values FTW! */

中央に配置したい場合は、コンテンツをコンテナにラップして、margin:0 autoすべてを中央に配置するために使用するなどの操作も必要になることを忘れないでください。

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;
}

デモ:jsfiddle.net/UGDxU/show(または編集

于 2011-05-22T11:40:28.807 に答える
1

の順序はbackground-positionですleft top。値を反転してみてください。

また、が必要になりbackground-repeat: no-repeatます。

jsFiddle

于 2011-05-22T11:40:10.867 に答える