html - 屏幕中央的 Onclick 按钮
问题描述
这是我的盒子代码。下面是它在浏览器中的样子。我试过 text-align: center、box-align: center 和 position: relative。这些都没有奏效。我错过了什么?
解决方案
尝试这个:
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>
推荐阅读
- rest - 如何在 Rest API 中维护静态引用数据
- bash - 用于检查乘法结果并引发错误的 AWk 脚本
- postgresql - Postgresql - 准备好的语句与连接池 - 这是一种权衡吗?
- powershell - 检查 azure storage powershell 中是否存在表
- sap-fiori - Fiori中目录和目录组之间的区别
- typescript - 我如何扩展声明为命名空间的类
- javascript - ExtJs (v 6.0.0, classic) 带有自定义文本和表单的消息框
- javascript - JQuery parseXML 似乎什么也没给我
- node.js - 在路由中创建了一个 Promise,但未从其返回
- javascript - 无法使用 react-router 访问 URL 路径组件