I am trying to centre a button on a simple website, and I have looked at many tutorials and the main concepts are flexboxes and margins.
I have gone through the full tutorial for both of those and I have not managed to get either working.
What can I improve to make this code work?
function genSquawk() {
const div = document.getElementById('squawk')
var num1 = Math.floor(Math.random() * 7);
var num2 = Math.floor(Math.random() * 7);
var num3 = Math.floor(Math.random() * 7);
var num4 = Math.floor(Math.random() * 7);
div.textContent = `${num1}${num2}${num3}${num4}`;
}
body {
background-color: dimgray;
font-family: Arial, Helvetica, sans-serif;
}
.button.center {
margin: auto 0;
width: 50%;
border: 3px solid black;
padding: 10px;
}
.button {
width: 500px;
height: 250px;
font-family: Arial, Helvetica, sans-serif;
text-align: center;
font-size: 70px;
}
#squawk {
color: white;
padding: 50px;
text-align: center;
font-size: 50px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<link rel = "stylesheet" href = "index.css">
<script src = "index.js"></script>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id = "squawk">0000</div>
<button onclick = "genSquawk()" class="button center">CREATE SQUAWK</button>
</body>
</html>