用html和css写一个知乎首页
时间: 2023-09-23 18:12:08 浏览: 77
好的,以下是一个简单的知乎首页的HTML和CSS代码:
HTML代码:
```html
<!DOCTYPE html>
<html>
<head>
<title>知乎首页</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<header>
<div class="logo">知乎</div>
<nav>
<ul>
<li><a href="#">首页</a></li>
<li><a href="#">发现</a></li>
<li><a href="#">话题</a></li>
<li><a href="#">消息</a></li>
</ul>
</nav>
<form>
<input type="text" placeholder="搜索">
</form>
<button>提问</button>
<a href="#">登录</a>
</header>
<main>
<section class="hot-questions">
<h2>热门问题</h2>
<ol>
<li><a href="#">如何学好编程?</a></li>
<li><a href="#">如何学好英语?</a></li>
<li><a href="#">如何写好作文?</a></li>
<li><a href="#">如何学好数学?</a></li>
</ol>
</section>
<section class="recommendations">
<h2>为你推荐</h2>
<ul>
<li>
<a href="#">
<img src="https://picsum.photos/id/237/200/300" alt="推荐内容">
<h3>推荐标题</h3>
<p>推荐描述</p>
</a>
</li>
<li>
<a href="#">
<img src="https://picsum.photos/id/238/200/300" alt="推荐内容">
<h3>推荐标题</h3>
<p>推荐描述</p>
</a>
</li>
<li>
<a href="#">
<img src="https://picsum.photos/id/239/200/300" alt="推荐内容">
<h3>推荐标题</h3>
<p>推荐描述</p>
</a>
</li>
</ul>
</section>
</main>
<footer>
<p>© 2021 知乎</p>
<ul>
<li><a href="#">关于</a></li>
<li><a href="#">加入我们</a></li>
<li><a href="#">联系我们</a></li>
<li><a href="#">服务条款</a></li>
<li><a href="#">隐私政策</a></li>
</ul>
</footer>
</body>
</html>
```
CSS代码:
```css
/* 样式重置 */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
/* 全局样式 */
body {
font-family: Arial, sans-serif;
font-size: 16px;
line-height: 1.5;
}
header {
background-color: #fff;
display: flex;
justify-content: space-between;
align-items: center;
padding: 20px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.logo {
font-size: 30px;
font-weight: bold;
color: #0084ff;
}
nav ul {
display: flex;
list-style: none;
}
nav li {
margin-right: 20px;
}
nav a {
color: #333;
text-decoration: none;
}
form input[type="text"] {
border: none;
border-radius: 20px;
padding: 10px 20px;
margin-right: 20px;
background-color: #f6f6f6;
}
button {
background-color: #0084ff;
color: #fff;
border: none;
border-radius: 20px;
padding: 10px 20px;
margin-right: 20px;
cursor: pointer;
}
a {
color: #0084ff;
text-decoration: none;
margin-right: 20px;
}
main {
padding: 20px;
}
.hot-questions {
margin-bottom: 40px;
}
.hot-questions h2 {
font-size: 24px;
font-weight: bold;
margin-bottom: 20px;
}
.hot-questions ol {
list-style: none;
}
.hot-questions li {
margin-bottom: 10px;
}
.hot-questions a {
color: #333;
text-decoration: none;
}
.recommendations {
margin-bottom: 40px;
}
.recommendations h2 {
font-size: 24px;
font-weight: bold;
margin-bottom: 20px;
}
.recommendations ul {
display: flex;
list-style: none;
}
.recommendations li {
margin-right: 20px;
}
.recommendations img {
width: 200px;
height: 300px;
}
.recommendations h3 {
font-size: 18px;
font-weight: bold;
margin-top: 10px;
}
.recommendations p {
color: #999;
margin-top: 10px;
}
.footer {
background-color: #f6f6f6;
padding: 20px;
display: flex;
justify-content: space-between;
align-items: center;
font-size: 14px;
color: #999;
box-shadow: 0 -2px 4px rgba(0, 0, 0, 0.1);
}
.footer ul {
display: flex;
list-style: none;
}
.footer li {
margin-right: 20px;
}
.footer a {
color: #999;
text-decoration: none;
}
```
这个页面包括一个头部导航栏、一个搜索框、一个提问按钮、一个登录链接、一个热门问题列表、一个为你推荐列表和一个页脚。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)