【CSS】【javascript】要素の中心を基準に描画(Draw relative to the center of the element.)
- 【HTML】
-
<div class="Container"><div class="Contents"></div></div>
- 【CSS】
-
.Container { position: absolute; width: 0; height: 0; overflow: visible; } .Container .Contents { position: absolute; left: -1rem; // herf width top: -1rem; // herf height right: -1rem; // herf width bottom: -1rem; // herf height background-color: #6699FF; }
- 【使い方】
var container = document.querySelector('.Container');
// Container's center is the origin.
container.style.left = '100px';
container.style.right = '100px';