本文将介绍如何使用HTML和CSS创建简单的登录表单,适合编程小白学习。
在创建登录表单前,我们需要使用HTML代码构建表单结构。下面是一个简单的HTML代码示例:
<form> <label>用户名:</label> <input type="text" name="username" placeholder="请输入用户名"> <br> <label>密码:</label> <input type="password" name="password" placeholder="请输入密码"> <br> <input type="submit" value="登录"> </form>
上述代码中,我们使用了form标签来创建表单,label标签来标注文本输入框的名称,input标签用于创建文本输入框和提交按钮。
接下来,我们需要使用CSS代码来美化表单样式。下面是一个简单的CSS代码示例:
form {
width: 300px;
margin: 0 auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 5px;
}
label {
display: block;
margin-bottom: 10px;
}
input[type="text"], input[type="password"] {
width: 100%;
padding: 10px;
margin-bottom: 20px;
border: 1px solid #ccc;
border-radius: 5px;
}
input[type="submit"] {
background-color: #4CAF50;
color: white;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
}
input[type="submit"]:hover {
background-color: #45a049;
}上述代码中,我们使用了form标签选择器来选择整个表单,label标签选择器来选择表单中的标注文本,input[type="text"], input[type="password"]选择器用于选择文本输入框,input[type="submit"]选择器用于选择提交按钮。我们使用了一些CSS属性来美化表单样式,例如width、margin、padding、border、border-radius、background-color等。
下面是完整的HTML和CSS代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>登录表单</title>
<style>
form {
width: 300px;
margin: 0 auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 5px;
}
label {
display: block;
margin-bottom: 10px;
}
input[type="text"], input[type="password"] {
width: 100%;
padding: 10px;
margin-bottom: 20px;
border: 1px solid #ccc;
border-radius: 5px;
}
input[type="submit"] {
background-color: #4CAF50;
color: white;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
}
input[type="submit"]:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<form>
<label>用户名:</label>
<input type="text" name="username" placeholder="请输入用户名">
<br>
<label>密码:</label>
<input type="password" name="password" placeholder="请输入密码">
<br>
<input type="submit" value="登录">
</form>
</body>
</html>使用上述代码可以创建一个简单的登录表单。
本文为翻滚的胖子原创文章,转载无需和我联系,但请注明来自猿教程iskeys.com
