вот накидал небольшой пример
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="css.css">
<script src="jsTest.js"></script>
</head>
<body>
<div id="testDIV">
<span>SPAN 1</span>
<span>SPAN 2</span>
</div>
</body>
</html>
Код:
|
#testDIV{
position: relative;
} |
window.onload = function(){
var obj = {};
var testDiv = document.querySelector('#testDIV');
var childTestDiv = testDiv.children;
for(var i = 0; i < childTestDiv.length; i++){
var leftPos = childTestDiv[i].offsetLeft;
childTestDiv[i].style.position = 'absolute';
childTestDiv[i].style.left = leftPos + 'px';
}
}