当然可以!以下是一个纯HTML单文件(仅用HTML+CSS+原生JS,无外部依赖),高度还原谷歌首页风格,支持响应式布局和亮/暗主题切换。你可以直接保存为.html文件打开体验。
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Google</title>
<link rel="icon" href="https://www.google.com/favicon.ico">
<style>
:root {
--bg: #fff;
--text: #202124;
--input-bg: #fff;
--input-border: #dfe1e5;
--input-shadow: rgba(60,64,67,.3);
--btn-bg: #f8f9fa;
--btn-bg-hover: #f1f3f4;
--btn-text: #3c4043;
--link: #1a0dab;
--footer-bg: #f2f2f2;
}
[data-theme="dark"] {
--bg: #202124;
--text: #e8eaed;
--input-bg: #303134;
--input-border: #5f6368;
--input-shadow: rgba(23,23,23,.5);
--btn-bg: #303134;
--btn-bg-hover: #3c4043;
--btn-text: #e8eaed;
--link: #8ab4f8;
--footer-bg: #171717;
}
html, body {
height: 100%;
margin: 0;
padding: 0;
background: var(--bg);
color: var(--text);
font-family: 'Roboto', Arial, sans-serif;
transition: background .3s, color .3s;
}
body {
min-height: 100vh;
display: flex;
flex-direction: column;
justify-content: space-between;
}
header {
display: flex;
justify-content: flex-end;
align-items: center;
padding: 16px 24px 0 24px;
font-size: 14px;
gap: 16px;
}
header a {
color: var(--text);
text-decoration: none;
margin-left: 12px;
transition: color .2s;
}
header a:hover {
text-decoration: underline;
color: var(--link);
}
.avatar {
width: 32px;
height: 32px;
border-radius: 50%;
background: #eee;
display: inline-block;
vertical-align: middle;
margin-left: 8px;
border: 1px solid #ccc;
}
.theme-toggle {
background: none;
border: none;
cursor: pointer;
font-size: 20px;
margin-left: 8px;
color: var(--text);
transition: color .2s;
}
main {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 60vh;
}
.logo {
margin-top: 40px;
margin-bottom: 32px;
width: 272px;
height: 92px;
background: none;
display: flex;
align-items: center;
justify-content: center;
}
.logo svg {
width: 272px;
height: 92px;
display: block;
}
.search-box {
width: 100%;
max-width: 584px;
display: flex;
flex-direction: column;
align-items: center;
}
.search-bar {
width: 100%;
display: flex;
align-items: center;
background: var(--input-bg);
border: 1px solid var(--input-border);
border-radius: 24px;
box-shadow: 0 1px 6px 0 var(--input-shadow);
padding: 0 14px;
height: 44px;
transition: box-shadow .2s, border-color .2s;
margin-bottom: 24px;
}
.search-bar:focus-within {
box-shadow: 0 1px 8px 0 var(--input-shadow);
border-color: #4285f4;
}
.search-bar input {
flex: 1;
border: none;
outline: none;
background: transparent;
font-size: 18px;
color: var(--text);
padding: 8px 0;
}
.search-bar .icon {
width: 24px;
height: 24px;
margin: 0 8px;
fill: #5f6368;
cursor: pointer;
transition: fill .2s;
}
.search-bar .icon:hover {
fill: #4285f4;
}
.search-buttons {
display: flex;
gap: 8px;
margin-bottom: 24px;
flex-wrap: wrap;
justify-content: center;
}
.search-buttons button {
background: var(--btn-bg);
color: var(--btn-text);
border: 1px solid #f8f9fa;
border-radius: 4px;
padding: 10px 20px;
font-size: 14px;
margin: 4px 2px;
cursor: pointer;
transition: background .2s, box-shadow .2s;
box-shadow: 0 1px 1px rgba(0,0,0,0.05);
}
.search-buttons button:hover {
background: var(--btn-bg-hover);
box-shadow: 0 1px 2px rgba(60,64,67,.15);
}
.lang {
font-size: 13px;
color: #5f6368;
margin-bottom: 16px;
text-align: center;
}
.lang a {
color: var(--link);
text-decoration: none;
margin: 0 4px;
}
.lang a:hover {
text-decoration: underline;
}
footer {
background: var(--footer-bg);
color: #5f6368;
font-size: 14px;
padding: 16px 24px;
display: flex;
flex-direction: column;
gap: 8px;
}
.footer-row {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-items: center;
gap: 8px;
}
.footer-links {
display: flex;
gap: 16px;
flex-wrap: wrap;
}
.footer-links a {
color: #5f6368;
text-decoration: none;
transition: color .2s;
}
.footer-links a:hover {
color: var(--link);
text-decoration: underline;
}
@media (max-width: 600px) {
.logo {
width: 180px;
height: 60px;
}
.logo svg {
width: 180px;
height: 60px;
}
.search-box {
max-width: 95vw;
}
header, footer {
padding: 12px 8px;
}
}
</style>
</head>
<body>
<header>
<a href="#">Gmail</a>
<a href="#">图片</a>
<button class="theme-toggle" title="切换主题" aria-label="切换主题">🌙</button>
<span class="avatar"></span>
</header>
<main>
<div class="logo">
<!-- Google Logo SVG -->
<svg viewBox="0 0 272 92">
<g>
<text x="0" y="70" font-family="Product Sans,Arial,sans-serif" font-size="80" font-weight="bold">
<tspan fill="#4285F4">G</tspan>
<tspan x="60" fill="#EA4335">o</tspan>
<tspan x="120" fill="#FBBC05">o</tspan>
<tspan x="180" fill="#4285F4">g</tspan>
<tspan x="240" fill="#34A853">l</tspan>
<tspan x="260" fill="#EA4335">e</tspan>
</text>
</g>
</svg>
</div>
<form class="search-box" autocomplete="off" onsubmit="return doSearch(event)">
<div class="search-bar">
<svg class="icon" viewBox="0 0 24 24">
<path d="M15.5 14h-.79l-.28-.27A6.471 6.471 0 0 0 16 9.5 6.5 6.5 0 1 0 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99c.41.41 1.09.41 1.5 0s.41-1.09 0-1.5l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"/>
</svg>
<input id="searchInput" type="text" name="q" autofocus autocomplete="off" aria-label="搜索" />
<svg class="icon" viewBox="0 0 24 24" id="micBtn" title="语音搜索" style="cursor:pointer;">
<circle cx="12" cy="12" r="10" fill="#4285F4"/>
<rect x="10" y="6" width="4" height="8" rx="2" fill="#fff"/>
<rect x="11" y="15" width="2" height="3" rx="1" fill="#fff"/>
</svg>
</div>
<div class="search-buttons">
<button type="submit">Google 搜索</button>
<button type="button" onclick="luckySearch()">手气不错</button>
</div>
<div class="lang">
Google 提供:<a href="#">English</a> <a href="#">日本語</a> <a href="#">更多语言</a>
</div>
</form>
</main>
<footer>
<div>中国</div>
<div class="footer-row">
<div class="footer-links">
<a href="#">关于 Google</a>
<a href="#">广告</a>
<a href="#">商务</a>
<a href="#">如何运作</a>
</div>
<div class="footer-links">
<a href="#">隐私</a>
<a href="#">条款</a>
<a href="#">设置</a>
</div>
</div>
</footer>
<script>
// 主题切换
const themeBtn = document.querySelector('.theme-toggle');
function setTheme(theme) {
document.documentElement.setAttribute('data-theme', theme);
themeBtn.textContent = theme === 'dark' ? '☀️' : '🌙';
localStorage.setItem('theme', theme);
}
// 自动检测或读取主题
(function() {
const saved = localStorage.getItem('theme');
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
setTheme(saved || (prefersDark ? 'dark' : 'light'));
})();
themeBtn.onclick = function() {
const current = document.documentElement.getAttribute('data-theme');
setTheme(current === 'dark' ? 'light' : 'dark');
};
// 搜索功能
function doSearch(e) {
e.preventDefault();
const q = document.getElementById('searchInput').value.trim();
if (q) {
window.location.href = 'https://www.google.com/search?q=' + encodeURIComponent(q);
}
return false;
}
// 手气不错
function luckySearch() {
const q = document.getElementById('searchInput').value.trim();
if (q) {
window.location.href = 'https://www.google.com/search?q=' + encodeURIComponent(q) + '&btnI=1';
} else {
window.location.href = 'https://www.google.com/doodles';
}
}
// 语音搜索(仅演示)
document.getElementById('micBtn').onclick = function() {
alert('此为演示,语音搜索需浏览器支持Web Speech API。');
};
</script>
</body>
</html>
主要特性说明
- 高度还原谷歌首页布局与配色,自适应亮/暗主题,SVG矢量Logo。
- 响应式设计,在手机和PC上均美观。
- 主题切换,自动检测系统主题,支持手动切换,持久化保存。
- 搜索/手气不错,输入后可跳转Google搜索或“手气不错”。
- 语音按钮为演示,点击有提示(可扩展Web Speech API)。
- 顶部导航、底部页脚,仿谷歌风格。
- 无外部依赖,纯HTML单文件,开箱即用。
如需进一步美化或扩展功能(如自动补全、语音识别等),可继续补充JS代码。