1
<div id="tagcontainer"><img id="tagimg" src="img/tri.png"/></div>

CSS:

#tagcontainer {
    width:100%;
    top:0;
    position:absolute;
}
    #tagimg {
        position:relative;
        margin:auto;
    }

なぜ私はそれを理解できないのか分かりません。この画像が中央にないのはなぜですか?

4

4 に答える 4

2

<img>インライン要素だからです。text-align: center代わりにコンテナで使用してください。

于 2012-09-11T23:09:15.820 に答える
0

#tagimg をブロック レベル要素にするか、{ display: inline-block; } または、親で text-align center を使用します...

于 2012-09-11T23:07:56.337 に答える
0

これを試して:

#tagcontainer {
width:100%;
position:absolute;
}
#tagimg {
width:[imagewidth]px;
top:0;
position:relative;
margin:auto;
}
于 2012-09-11T23:11:23.837 に答える
0

css プロパティをもう 1 つ追加しますdisplay:block;

    #tagimg {
        display:block;
        position:relative;
        margin:auto;
    }
于 2012-09-11T23:15:15.337 に答える