我已经开始通过在 Mac 上的 TextEditor 中编写 HTML 来创建一个网站。我已成功创建按钮作为链接并将某些页面互连在一起。我想随着时间的推移慢慢开发我的网站,例如添加数据库等。
我观看了有关如何创建登录页面的视频,并且创建了一个要求用户输入用户名和密码的登录页面。我已经完成了我的研究,但我不知道如何将登录表单链接到仅保存为 html 文件的主网站页面 Mac。
这是我登录的 HTML 代码:
body {
margin: 0;
padding: 0;
background: url(pic1.jpg);
background-size: cover;
background-position: center;
font-family: sans-serif;
}
.loginbox {
width: 320px;
height: 420px;
background: #000;
color: #fff;
top: 50%;
left: 50%;
position: absolute;
transform: translate(-50%, -50%);
box-sizing: border-box;
padding: 70px 30px;
}
.avatar {
width: 100px;
height: 100px;
border-radius: 50%;
position: absolute;
top: -50px;
left: calc(50% - 50px);
}
h1 {
margin: 0;
padding: 0 0 20px;
text-align: center;
font-size: 22px;
}
.loginbox p {
margin: 0;
padding: 0;
font-weight: bold;
}
.loginbox input {
width: 100%;
margin-bottom: 20px;
}
.loginbox input[type="text"],
input[type="password"] {
border: none;
border-bottom: 1px solid #fff;
background: transparent;
outline: none;
height: 40px;
color: #fff;
font-size: 16px;
}
.loginbox input[type="submit"] {
border: none;
outline: none;
height: 40px;
background: #fb2525;
color: #fff;
font-size: 18px;
border-radius: 20px;
}
.loginbox input[type="submit"]:hover {
cursor: pointer;
background: #ffc107;
color: #000;
}
.loginbox a {
text-decoration: none;
font-size: 12px;
line-height: 20px;
color: darkgrey;
}
.loginbox a:hover {
color: #ffc107;
}
<html>
<head>
<title>Login Form Design</title>
<link rel="stylesheet" type="text/css" href="style.css">
<body>
<div class="loginbox">
<img src="avatar.png" class="avatar">
<h1>Login Here</h1>
<form>
<p>Username</p>
<input type="text" name="" placeholder="Enter Username">
<p>Password</p>
<input type="password" name="" placeholder="Enter Password">
<input type="submit" name="Login" value="Login">
<a href="#">Lost your password?</a><br>
<a href="#">Don't have an account?</a>
</form>
</div>
</body>
</head>
</html>
如果您纯粹尝试从登录页面打开主页,那么您可以在代码顶部使用此代码:
<form method="post" action="http://www.yourdomain.com/index.html">
或者,如果您还没有域/托管,则将 http:// 部分替换为 index.html (或您称为其他文件的任何名称)所在文件的路径
这不会对登录表单进行任何验证,但会打开另一个页面。 出于验证目的,最好使用 javascript/php。如果您还不了解 javascript,我建议您暂时使用此解决方案。先走再跑之类的..
祝你好运!
正如您所说,您想使用数据库开发网站。我认为这只是前端部分。如果您想从数据库验证用户名和密码。你可以使用一种服务器端语言,比如我说的 PHP。您可以使用 POST 方法来发布数据,并使用操作来发布数据。为此,您可能必须学习一些 PHP。我在这里提供一些可能对您有用的链接。
https://www.tutorialspoint.com/php/php_mysql_login.htm https://www.tutorialspoint.com/php/php_login_example.htm
谢谢
body {
margin: 0;
padding: 0;
background: url(pic1.jpg);
background-size: cover;
background-position: center;
font-family: sans-serif;
}
.loginbox {
width: 320px;
height: 420px;
background: #000;
color: #fff;
top: 50%;
left: 50%;
position: absolute;
transform: translate(-50%, -50%);
box-sizing: border-box;
padding: 70px 30px;
}
.avatar {
width: 100px;
height: 100px;
border-radius: 50%;
position: absolute;
top: -50px;
left: calc(50% - 50px);
}
h1 {
margin: 0;
padding: 0 0 20px;
text-align: center;
font-size: 22px;
}
.loginbox p {
margin: 0;
padding: 0;
font-weight: bold;
}
.loginbox input {
width: 100%;
margin-bottom: 20px;
}
.loginbox input[type="text"],
input[type="password"] {
border: none;
border-bottom: 1px solid #fff;
background: transparent;
outline: none;
height: 40px;
color: #fff;
font-size: 16px;
}
.loginbox input[type="submit"] {
border: none;
outline: none;
height: 40px;
background: #fb2525;
color: #fff;
font-size: 18px;
border-radius: 20px;
}
.loginbox input[type="submit"]:hover {
cursor: pointer;
background: #ffc107;
color: #000;
}
.loginbox a {
text-decoration: none;
font-size: 12px;
line-height: 20px;
color: darkgrey;
}
.loginbox a:hover {
color: #ffc107;
}
<html>
<head>
<title>Login Form Design</title>
<link rel="stylesheet" type="text/css" href="style.css">
<body>
<div class="loginbox">
<img src="avatar.png" class="avatar">
<h1>Login Here</h1>
<form>
<p>Username</p>
<input type="text" name="" placeholder="ZCaller">
<p>Password</p>
<input type="password" name="" placeholder="Spabdulla369">
<input type="submit" name="Login" value="Login">
<a href="#">Lost your password?</a><br>
<a href="#">Don't have an account?</a>
</form>
</div>
</body>
</head>
</html>