技术咨询:如何完成服务器端简易HTML登录页面开发?
Hey there! Looks like you're building a basic login page for your server. Let's clean up and format your existing code properly, plus share some improvements to make it more modern, accessible, and user-friendly.
First, here's your original code formatted clearly (I've completed the cut-off section logically):
<html> <head> <title>Login Page</title> </head> <body> <form name="loginForm" method="post" action="login.php"> <table> <tr> <td colspan=2> <center> <font size=4><b>HTML Login Page</b></font> </center> </td> </tr> <tr> <td>Username:</td> <td><input type="text" size=25 name="userid"></td> </tr> <tr> <td>Password:</td> <td><input type="password" size=25 name="password"></td> </tr> <tr> <td colspan=2> <center> <input type="submit" value="Login"> </center> </td> </tr> </table> </form> </body> </html>
Quick Notes on the Original Code:
- Deprecated elements like
<font>and<center>are outdated—they're not semantic and hard to style consistently. - Using tables for layout is an old practice; modern design uses CSS Flexbox/Grid for positioning.
- Missing
<label>elements hurt accessibility (screen readers can't associate text with input fields). - No basic styling makes the page feel unpolished.
Revised, Modern Login Page:
Here's a cleaner, more accessible version with proper HTML5 structure and CSS styling:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Server Login</title> <style> body { font-family: Arial, sans-serif; display: flex; justify-content: center; align-items: center; min-height: 100vh; margin: 0; background-color: #f0f2f5; } .login-card { background: white; padding: 2rem; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); width: 100%; max-width: 400px; } .login-card h1 { text-align: center; color: #1a73e8; margin-bottom: 1.5rem; font-size: 1.8rem; } .form-group { margin-bottom: 1rem; } .form-group label { display: block; margin-bottom: 0.5rem; color: #5f6368; } .form-group input { width: 100%; padding: 0.8rem; border: 1px solid #dadce0; border-radius: 4px; font-size: 1rem; box-sizing: border-box; } .form-group input:focus { outline: none; border-color: #1a73e8; box-shadow: 0 0 0 2px rgba(26, 115, 232, 0.2); } .login-btn { width: 100%; padding: 0.8rem; background-color: #1a73e8; color: white; border: none; border-radius: 4px; font-size: 1rem; cursor: pointer; transition: background-color 0.3s; } .login-btn:hover { background-color: #1557b0; } </style> </head> <body> <div class="login-card"> <h1>Server Login</h1> <form name="loginForm" method="post" action="login.php"> <div class="form-group"> <label for="userid">Username</label> <input type="text" id="userid" name="userid" required> </div> <div class="form-group"> <label for="password">Password</label> <input type="password" id="password" name="password" required> </div> <button type="submit" class="login-btn">Login</button> </form> </div> </body> </html>
Key Improvements:
- Semantic HTML: Uses
<div>for layout instead of tables, and proper<label>elements linked to inputs for accessibility. - Responsive Design: Centers the form on all screen sizes and works well on mobile.
- Modern Styling: Adds subtle shadows, rounded corners, and hover effects for a professional look.
- Accessibility: Includes
requiredattributes for mandatory fields and clear focus states for keyboard navigation. - Valid HTML5: Includes the proper doctype declaration and character encoding.
This version is easier to maintain, looks polished, and provides a better user experience across devices.
内容的提问来源于stack exchange,提问作者Niall Cooley
相关产品推荐
相关产品推荐

