在网页/浏览器中使用Antd居中登录表单,可以通过以下步骤实现:
Form
、Input
、Button
等组件来构建表单。container
),然后在JavaScript文件中使用React或其他框架将登录表单组件渲染到该容器中。完整的示例代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Login Form</title>
<link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/antd/4.16.13/antd.min.css">
<style>
.container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
</style>
</head>
<body>
<div id="root" class="container"></div>
<script src="https://cdn.bootcdn.net/ajax/libs/antd/4.16.13/antd.min.js"></script>
<script>
const { Form, Input, Button } = antd;
const { useState } = React;
const LoginForm = () => {
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
const handleUsernameChange = (e) => {
setUsername(e.target.value);
};
const handlePasswordChange = (e) => {
setPassword(e.target.value);
};
const handleSubmit = (e) => {
e.preventDefault();
// 处理登录逻辑
};
return (
<Form onSubmit={handleSubmit}>
<Form.Item>
<Input placeholder="Username" value={username} onChange={handleUsernameChange} />
</Form.Item>
<Form.Item>
<Input.Password placeholder="Password" value={password} onChange={handlePasswordChange} />
</Form.Item>
<Form.Item>
<Button type="primary" htmlType="submit">Login</Button>
</Form.Item>
</Form>
);
};
ReactDOM.render(<LoginForm />, document.getElementById('root'));
</script>
</body>
</html>
这样,登录表单将会在网页/浏览器中居中显示。你可以根据实际需求进行样式和布局的调整。
领取专属 10元无门槛券
手把手带您无忧上云