0

画像の位置を中央にしたいcenterタグとテキストの配置を使用しましたが、機能しません。助けてください

CSS:

#indtrans
{
    position :fixed;
    display:block;
    background-color : none;
    top: 2px; 
    text-align:center;
    padding-left:130px;
}

html:

 <center><div  id="indtrans"><img src="indeximg.png"></img></div></center>
4

4 に答える 4

2

divに設定幅を指定すると、マージンを設定できるはずです。0 auto; それを中心に置くでしょう。

于 2012-11-07T09:35:00.850 に答える
0

追加width:100%

このようにCSSを変更します

    #indtrans{
    position :fixed;
    display:block; width:100%;
    background-color : none;
    top: 2px; 
    text-align:center;
    padding-left:130px;
}​

デモ

于 2012-11-07T09:36:30.163 に答える
0

これを試して:

#indtrans
 {
   display: block;
   left: 50%;
   position: fixed;
   top: 2px;
}
于 2012-11-07T09:41:22.150 に答える
-1

位置を固定してDIVを配置しているため#indtrans、位置合わせをより具体的にする必要があります。単に使用margin: 0 auto;するだけでは機能しません。

代わりにこれを試してください。残りのマージンは、要素の全幅のマイナス50%である必要があります。

#indtrans
{
    position :fixed;
    display:block;
    background-color : none;
    top: 2px; 
    left: 50%;
    margin-left: (-50% of total width);
    text-align:center;
    padding-left:130px;
}
于 2012-11-07T09:48:30.650 に答える