7

CSS で Web ページの上部中央に画像を配置する必要があります。今、私background-image:は css を使用しているだけですが、これによりページの中央に配置されます。

これが私のコードです:

body {
  background-image: url("theimageurlgoeshere"); //The image is 842 x 508
  background-attachment:fixed;
  background-position: center top;
  background-repeat: no-repeat;
}

また、 を変更しbackground-position:ても、サイトの結果には影響がないようです。どんな助けでも大歓迎です。

4

3 に答える 3

6

これらの値の配置を からcenter topに変更しますtop center

background-position: top center;

Safari 4、Chrome、および FF 3.5 でテスト済み

テストで使用したコードは次のとおりです。

 body { background: url(./image.png) no-repeat top center; }
于 2010-05-20T23:40:57.740 に答える
1

そして、それを1行にしたい場合:

body {
  background: url('path') center top fixed no-repeat;
}

詳細: http://www.w3schools.com/css/pr_background-position.asp

于 2010-05-20T23:46:50.240 に答える
0

これが機能しない場合。margin:0 auto; を行います。

于 2013-06-16T14:57:29.890 に答える