博客css制作
博客CSS制作方法
基础样式设置
使用CSS为博客设置统一的字体、颜色和间距。例如:
body {
font-family: 'Arial', sans-serif;
line-height: 1.6;
color: #333;
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
响应式布局
通过媒体查询确保博客在不同设备上显示正常:
@media (max-width: 768px) {
body {
padding: 10px;
}
.sidebar {
display: none;
}
}
文章样式优化
为博客正文设置易读的排版样式:
.post {
margin-bottom: 40px;
}
.post-title {
font-size: 2em;
margin-bottom: 10px;
}
.post-content {
font-size: 1.1em;
}
导航菜单设计
创建简洁的导航菜单:
.nav {
background: #f5f5f5;
padding: 10px;
margin-bottom: 20px;
}
.nav a {
margin-right: 15px;
text-decoration: none;
color: #333;
}
.nav a:hover {
color: #0066cc;
}
代码块样式
为技术博客中的代码片段设置专用样式:
pre {
background: #f8f8f8;
padding: 15px;
border-radius: 5px;
overflow-x: auto;
}
code {
font-family: 'Courier New', monospace;
color: #c7254e;
}
图片和媒体样式
确保图片适应容器并保持比例:
.post img {
max-width: 100%;
height: auto;
display: block;
margin: 20px auto;
}
评论区域样式
为博客评论区域设置清晰样式:
.comments {
border-top: 1px solid #eee;
padding-top: 20px;
}
.comment {
margin-bottom: 15px;
padding-bottom: 15px;
border-bottom: 1px dashed #ddd;
}






