如何使用CSS文件将HTML中的表格居中? [重复]

问题描述 投票:1回答:1

我目前正在将CSS添加到HTML网页中。目前,我的CSS文件在我刚开始时是非常基础的。它基本上将正文中的所有内容居中,但是,我的HTML页面中的任何表格都没有居中,它们只是停留在屏幕的左侧。有人可以告诉我我应该添加到此CSS代码中以使表格居中吗,谢谢!

main.css

body {
    text-align: center; 
        font-family: "Times New Roman", Times, serif;

    }

changePassword.html] >>

<!DOCTYPE html> 
<html> 
<head> 
<meta charset = "UTF-8"> 
<link rel = "stylesheet" type = "text/css" href = "main.css">
<title>Change Password</title>
</head>

<body>
    <h1>Change Password</h1>
    <form action ="NewPassword" method = post> 
    <table border ="1"> 
    <tr>
    <td>Existing Password:</td>
    <td><input type = "password" name = "oldpassword" size = "20"></td>
    </tr>

    <tr>
    <td>New Password:</td>
    <td><input type = "password" name = "newpassword" size = "20"></td>
    </tr>

    <tr>
    <td>Confirm New Password</td>
    <td><input type = "password" name = "confirmpassword" size = "20"></td>
    </tr>
    </table>
    <input type = "submit" value = "Update Password">
    </form>.
</body>

</html>

我目前正在将CSS添加到HTML网页中。目前,我的CSS文件在我刚开始时是非常基础的。它基本上将正文中的所有内容居中,但是,我的HTML中没有任何表...

html css centering
1个回答
0
投票

给出以下css将使您的表格位于水平中心:

© www.soinside.com 2019 - 2024. All rights reserved.