用HTML和css写一个博客
很高兴帮您完成这个任务!以下是一个简单的博客模板,您可以根据需要进行修改和自定义。请注意,这是一个基本的模板,您可以根据自己的需要添加更多的内容和样式。
HTML代码:
<!DOCTYPE html>
<html>
<head>
<title>我的博客</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<header>
<h1>欢迎来到我的博客</h1>
<nav>
<ul>
<li><a href="#">首页</a></li>
<li><a href="#">关于我</a></li>
<li><a href="#">博客</a></li>
<li><a href="#">联系我</a></li>
</ul>
</nav>
</header>
<main>
<section>
<h2>最新博客</h2>
<article>
<h3>我的第一篇博客</h3>
<p>这是我的第一篇博客。我很兴奋地开始写作,并且希望能够与更多的人分享我的想法。</p>
</article>
<article>
<h3>我的第二篇博客</h3>
<p>这是我的第二篇博客。我希望通过写作来提高自己的表达能力,同时也能够记录下我的成长和思考。</p>
</article>
</section>
<aside>
<h2>关于我</h2>
<p>我是一名热爱写作和分享的人。我喜欢探索新的事物,并且乐于把我的发现和经验分享给他人。</p>
</aside>
</main>
<footer>
<p>版权所有 © 2021 我的博客</p>
</footer>
</body>
</html>
CSS代码:
/* 重置默认样式 */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
/* 设置页面背景颜色 */
body {
background-color: #f5f5f5;
}
/* 设置头部样式 */
header {
background-color: #333;
color: #fff;
padding: 20px;
}
header h1 {
margin: 0;
font-size: 36px;
}
nav ul {
list-style: none;
display: flex;
}
nav li {
margin-right: 20px;
}
nav a {
color: #fff;
text-decoration: none;
font-size: 18px;
font-weight: bold;
}
/* 设置主体样式 */
main {
display: flex;
flex-wrap: wrap;
margin: 20px;
}
section {
flex: 2;
margin-right: 20px;
}
section h2 {
font-size: 24px;
margin-bottom: 10px;
}
article {
margin-bottom: 20px;
}
article h3 {
font-size: 20px;
margin-bottom: 10px;
}
article p {
font-size: 16px;
line-height: 1.5;
}
aside {
flex: 1;
background-color: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
aside h2 {
font-size: 24px;
margin-bottom: 10px;
}
aside p {
font-size: 16px;
line-height: 1.5;
}
/* 设置页脚样式 */
footer {
background-color: #333;
color: #fff;
text-align: center;
padding: 20px;
margin-top: 20px;
}
您可以将这些代码保存为HTML和CSS文件,然后使用浏览器进行预览。请注意,这只是一个基本的博客模板,您可以根据需要进行修改和自定义。祝您好运!
原文地址: https://www.cveoy.top/t/topic/QM2 著作权归作者所有。请勿转载和采集!