简体   繁体   English

当我按下按钮时,我的按钮会下降

[英]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.

相关问题 为什么我按下按钮时页面会刷新? - Why does my page refresh when I press buttons? 我如何制作带有 0-9 数字的按钮,当我按下它们时添加到文本框中 - how can i make buttons with numbers from 0-9 that adds into a textbox when i press them 当表单提交被禁用时,如何在文本区域上按Enter下行 - How can I press enter go down line on textarea when form submit is disable keypress enter 为什么将输入字段更改为按钮时我的输入字段不显示? - Why are my input fields dissapearing when I change them to buttons? 当我单击它们时,如何让我的按钮正确隐藏/显示? - How can I get my buttons to hide/display properly when I click them? 当我按下影响效果的按钮时,如何做向下滑动效果以不使我的网页回到顶部? - How can I do the slide down effect to not bring my web page back to top when I press the button that actions the effect? 按下向下键时可以触发另一个键吗? - Can I trigger another key when I press the down key? 当我按下链接按钮时,在同一div上更新Google可视化 - Updatinging google visualization on the same div when I press link buttons 为什么当我在iPad中按GO时,不关注下一个输入? - Why when I press GO in iPad, does not focus next input? 当我按下链接时,页面顶部没有显示吗? - When I press the link does not go top the page?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM