基于HTML5和CSS3搭建一个Web网页
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body {
margin: 0;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background-color: #f7f7f7;
font-family: Arial, sans-serif;
}
.container {
width: 80%;
max-width: 600px;
text-align: center;
}
.input-container {
margin: 20px 0;
padding: 10px;
background-color: #fff;
border: 1px solid #ddd;
border-radius: 5px;
}
input[type="text"] {
width: 100%;
padding: 10px;
border: none;
border-radius: 5px;
font-size: 16px;
outline: none;
}
input[type="submit"] {
width: 100%;
padding: 10px;
background-color: #5cb85c;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
outline: none;
}
input[type="submit"]:hover {
background-color: #449d44;
}
</style>
</head>
<body>
<div class="container">
<div class="input-container">
<input type="text" id="url" placeholder="请输入URL" required>
</div>
<button onclick="shortenUrl()">缩短链接</button>
</div>
<script>
function shortenUrl() {
const url = document.getElementById('url').value;
// 这里应该调用后端API进行处理
console.log('将', url, '缩短');
// 示例:假设后端返回了缩短的URL
const shortUrl = 'http://shorter.url';
// 显示缩短后的链接
alert('缩短链接为: ' + shortUrl);
}
</script>
</body>
</html>
这个代码实例展示了如何在一个简单的HTML页面中使用CSS3和HTML5创建一个输入框和一个按钮,并使用JavaScri
评论已关闭