Html 使用CSS对中按钮

Html 使用CSS对中按钮,html,css,layout,Html,Css,Layout,我正试图将这些按钮居中,但大多数在线功能都不起作用。不起作用且文本对齐:居中不起作用 按钮应该以完全相同的方式显示,除非以中间为中心。如果你尝试这个,它将不起作用。我想一定有问题 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>website</

我正试图将这些按钮居中,但大多数在线功能都不起作用。不起作用且文本对齐:居中不起作用

按钮应该以完全相同的方式显示,除非以中间为中心。如果你尝试这个,它将不起作用。我想一定有问题

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>website</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
});
</script>
<style type="text/css">
.button0 {
position:fixed;
left:88px;
top:58px;
font-family:MS Shell Dlg 2;
font-size:8px;
font-weight:NORMAL;
}
.button1 {
position:fixed;
left:6px;
top:191px;
font-family:MS Shell Dlg 2;
font-size:8px;
font-weight:NORMAL;
text-align: center;
margin-left:auto;
margin-right:auto;
}
.button2 {
position:fixed;
left:358px;
top:216px;
font-family:MS Shell Dlg 2;
font-size:8px;
font-weight:NORMAL;
}
</style>
<body>
<center>
<div class="button0"><input type="button" style="width: 268px;height: 145px;" value="Button"/></div>
<div class="button1"><input type="button" style="width: 40px;height: 88px;" value="Button"/></div>
<div class="button2"><input type="button" style="width: 76px;height: 73px;" value="Button"/></div>
</center>
</body>
</html>

您希望将其包装在相对div中。然后可以将左侧和右侧的边距设置为“自动”

说清楚,这就是你要找的吗

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>website</title>
</head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
</script>
<style type="text/css">

</style>
<body>
    <div style="position:relative; width:500px; height:200px; background:green; text-align:center">
        <input type="button" style="width: 268px;height: 145px;" value="Button1"/>
        <input type="button" style="width: 40px;height: 88px;" value="Button2"/>
        <input type="button" style="width: 76px;height: 73px;" value="Button3"/>
    </div>
</body>
</html>
您不能指定位置:固定和上左,并期望元素居中。通常,保证金:0px自动将工作良好。见下面的例子

.button0 {
    font-family:MS Shell Dlg 2;
    font-size:8px;
    font-weight:NORMAL;
    margin: 0px auto;
}
.button1 {
    font-family:MS Shell Dlg 2;
    font-size:8px;
    font-weight:NORMAL;
    text-align: center;
    margin: 0px auto;
}
.button2 {
    font-family:MS Shell Dlg 2;
    font-size:8px;
    font-weight:NORMAL;
    margin: 0px auto;
}

这里是。

-只需将按钮旋转到块元素,指定宽度,然后自动设置左右边距。

尝试在一个div中垂直居中的文本。例如,请参见。

我想我已经尝试过了,但按钮不在它们应该在的位置。如果希望按钮在一起,可能需要将它们包装到另一个div中。那么按钮就不需要自动边距,但是包装div会。嗯,我不知道为什么,但它没有做任何事情。我不太明白你想把什么放在中间-按钮内的文本?按钮本身垂直?仅供参考,您缺少一个闭合头标记Cool,它使它们居中,但它们的位置不使用给定的位置,所以您想通过FIFO以外的其他方式使它们居中?
.container {
width: 200px;
}

.center-element {
width: 100px;
position: relative;
left: 50%;
margin-left: -50px;
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>website</title>
</head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
</script>
<style type="text/css">

</style>
<body>
    <div style="position:relative; width:500px; height:200px; background:green; text-align:center">
        <input type="button" style="width: 268px;height: 145px;" value="Button1"/>
        <input type="button" style="width: 40px;height: 88px;" value="Button2"/>
        <input type="button" style="width: 76px;height: 73px;" value="Button3"/>
    </div>
</body>
</html>
.button0 {
    font-family:MS Shell Dlg 2;
    font-size:8px;
    font-weight:NORMAL;
    margin: 0px auto;
}
.button1 {
    font-family:MS Shell Dlg 2;
    font-size:8px;
    font-weight:NORMAL;
    text-align: center;
    margin: 0px auto;
}
.button2 {
    font-family:MS Shell Dlg 2;
    font-size:8px;
    font-weight:NORMAL;
    margin: 0px auto;
}