That is the missalignmentSo, I wanted to program TicTacToe on a Webpage, using plain JavaScript, HTML, and CSS. I've made some logic, so the board can update based on the entries in an array, but when I do that, the buttons aren't in a line anymore, and it looks really bad. Expected result: Text gets filled into the button, the button remains at its place. Actual Result: Text gets filled in but the button moves down. HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<script src="scripts.js"></script>
<title>My Website</title>
</head>
<body>
<div id="board">
<div id="row1">
<button class="field"> </button>
<button class="field"> </button>
<button class="field"> </button>
</div>
<div id="row2">
<button class="field"> </button>
<button class="field"> </button>
<button class="field"> </button>
</div>
<div id="row3">
<button class="field"> </button>
<button class="field"> </button>
<button class="field"> </button>
</div>
</div>
</body>
</html>
CSS:
.field{
display: inline-block;
border-style: solid;
background-color: white;
height: 100px;
width: 100px;
font-size: 10px;
}
#board {
margin-left: 40%;
margin-top: 20%;
height: 50%;
}
JS:
function game() {
this.board = [
" ", "x ", " ",
" ", " ", " ",
" ", " ", " x"
]
this.printBoard = function(buttons) {
for(i = 0; i < buttons.length; i++) {
buttons[i].innerHTML = this.board[i];
}
}
}
window.onload = function() {
let buttons = document.getElementsByClassName("field");
let myGame = new game();
myGame.printBoard(buttons);
}