gpt4 book ai didi

html - 页面中间的完美居中按钮

转载 作者:可可西里 更新时间:2023-11-01 13:06:43 25 4
gpt4 key购买 nike

代码

<!DOCTYPE html>
<html>
<head>
<title>Google Maps</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<style type="text/css">
#button {
appearance: none;
-moz-appearance: none;
-webkit-appearance: none;
height: 30px;
width: 200px;
left: 50%;
top: 50%;
position: absolute;
}
</style>
</head>
<body>
<input type="button" id="button" value="Open Map" />
</body>
</html>

我不确定如何正确地将按钮完美地置于页面中间。我尝试使用左和前 50%;但这并不能使按钮完美地居中于页面中间。谢谢。

下面是演示工作代码。

Demo code Check Out

最佳答案

除了一些更改外,您已正确完成所有操作:

margin-top: -15px;   /* = -height / 2   */
margin-left: -100px; /* = -width / 2 */
position: fixed; /* Fixed is better */

片段

#button {
appearance: none;
-moz-appearance: none;
-webkit-appearance: none;
height: 30px;
width: 200px;
left: 50%;
top: 50%;
margin-top: -15px; /* = -height / 2 */
margin-left: -100px; /* = -width / 2 */
position: fixed; /* Fixed is better */
}
<input type="button" id="button" value="Open Map" />

关于html - 页面中间的完美居中按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32088932/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com