を使用して相対要素を含むDIVを中心にするこの動作については苦労します。私はDIVコンテナの中に2つのDIV(sub1とsub2)を追加します。 Sub2は、Sub1の右下隅と重なる相対位置に設定されます。これを行うには、コンテナDIVの幅が良くない、Sub1の相対位置を変更する前と同じです。当初、それは問題ではありませんでしたが、クライアントは全体を集中させることにしました。そのため、コンテナの実際の幅が必要でした。CSS
これはCSSで実現できますか? JavaScriptでも、私は同じ幅(erronus)を持っています。私はあなたが見たいものを行動の少しは不明だ
html, body {
width:100%;
height: 100%;
}
#main {
position: fixed;
display: inline-block;
margin: auto;
}
#sub1 {
width: 100px;
height: 100px;
background-color:red;
position: relative;
}
#sub2 {
width: 100px;
height: 100px;
background-color: blue;
position: relative;
left: 80px;
top: -20px;
}
<div id="main">
<div id="sub1">
</div>
<div id="sub2">
</div>
</div>
ああ!問題を正確に修正しました! –