I'm doing a cv online and I can't center the main block via CSS, so I'm trying to find a solution with JavaScript. What seemed easy to me a priori turns out to be not so easy. If anyone can tell me where I am wrong I would be very grateful.
init();
var width;
function init(){
posicionCentral();
}
function getWidth() {
return Math.max(
document.body.scrollWidth,
document.documentElement.scrollWidth,
document.body.offsetWidth,
document.documentElement.offsetWidth,
document.documentElement.clientWidth
);
}
function posicionCentral(){
width = getWidth();
var posicion = (width/2) - 512;
document.getElementById('#bloqueCentral').style.left=posicion;
}
<body>
<div id="bloqueCentral">
<div id="cabecera">
<img src="imagenes/no_avatar.jpg" alt="foto" id="avatar">
</div>
<div id="bloqueIzquierdo">
</div>
<div id="bloqueDerecho">
</div>
</div>
</body>
The CSS does not let me publish it because it contains too much code, but it does say that it includes a:
*{margin:0px;}
Attached link to the CSS code: GitHub