[英]My buttons go down when I press them
I have 9 buttons in a board and I want to show an 'X' or an 'O' whenever I press them. 我在一个电路板上有9个按钮,每当我按下它时我想要显示'X'或'O'。 However when I press a button it goes down. 然而,当我按下按钮时它会下降。
$(document).ready(function(){ var against = 'human'; var board = ['-','-','-', '-','-','-', '-','-','-']; var turn = 'X'; $('.xo-btns').click(function(){ $(this).text(turn); }); });
body{ padding: 0px; margin: 0px; width: auto; height: auto; background: black; font-family: 'Raleway', sans-serif; } .container{ text-align: center; } .board{ display: inline-block; text-align: center; background: red; padding-top: 15px; padding-left: 10px; height: 250px; width: 250px; position: absolute; top: 0; bottom: 0; left: 0; right: 0; margin: auto; } .xo-btns{ width: 70px; height: 70px; padding: 0px; border-radius: 4px; background: transparent; outline: none; color: white; /* display: inline-block; */ }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <div class="container"> <div class="board"> <button class="xo-btns" id="one" value="1"></button> <button class="xo-btns" id="two" value="2"></button> <button class="xo-btns" id="three" value="3"></button> <br> <button class="xo-btns" id="four" value="4"></button> <button class="xo-btns" id="five" value="5"></button> <button class="xo-btns" id="six" value="6"></button> <br> <button class="xo-btns" id="seven" value="7"></button> <button class="xo-btns" id="eight" value="8"></button> <button class="xo-btns" id="nine" value="9"></button> <br> </div> </div>
How can I fix it so every time I press one of them, they stay where they started. 我怎样才能解决它,所以每当我按下其中一个时,它们就会停留在它们开始的地方。
Thank you! 谢谢!
This happens because of the vertical-align attribute, which sometimes has a buggy behaviour in my opinion. 这是因为vertical-align属性,在我看来有时会出现错误行为。
Add vertical-align: middle;
添加vertical-align: middle;
to your "xo-btns" class and you should be fine. 到你的“xo-btns”课,你应该没事。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.