首页 > 解决方案 > 屏幕中央的 Onclick 按钮

问题描述

这是我的盒子代码。下面是它在浏览器中的样子。我试过 text-align: center、box-align: center 和 position: relative。这些都没有奏效。我错过了什么? 在此处输入图像描述

标签: html

解决方案


尝试这个:

function myFunction(){

	document.getElementById("myP").style.textAlign = "center";
	
}
.blue {
  background-color: #0074D9;
  width: 100px;
  height: 100px;
  display: inline-block;
}
<html>
<body>

<center><h2>Click the Box</h2></center>

<div id="myP" onclick="myFunction()">
  <div class="blue"></div>
</div>

</body>
</html>


推荐阅读