ページの中心から 20 ピクセル離れた固定幅と高さの HTML div 要素を配置したいと考えています。これは可能ですか?
2 に答える
0
はい。div の css を次のように変更します。
position: absolute;
top: 50%;
left: 50%;
margin: (whatever direction you want to move)
于 2012-10-16T15:29:26.900 に答える
0
詳しい情報がないとわかりにくいですが、そうです。
水平方向に中央に配置し、「側面」に 20 ピクセル:
#my-element {
margin: 0 auto; /* center */
position: relative;
left: -20px; /* offset */
}
水平方向と垂直方向の中央揃え (要素の高さを固定する必要があります):
#my-element {
width: 100px;
height: 100px;
position: absolute; /* or fixed */
left: 50%;
top: 50%;
margin: -50px 0 0 -50px; /* half of the elements width and height in negative margin pulls it to the center - to offset it 20px simply increase/decrease these values */
}
于 2012-10-16T15:34:32.703 に答える