css新闻列表制作
CSS新闻列表制作
新闻列表是网站常见的布局形式,通常包含标题、摘要、时间和图片等元素。以下是一个完整的CSS新闻列表制作方法:
HTML结构

<div class="news-list">
<div class="news-item">
<img src="news1.jpg" alt="新闻图片">
<div class="news-content">
<h3>新闻标题</h3>
<p class="summary">新闻摘要内容...</p>
<span class="time">2023-05-20</span>
</div>
</div>
<!-- 更多新闻项 -->
</div>
CSS样式
.news-list {
width: 100%;
max-width: 800px;
margin: 0 auto;
font-family: 'Microsoft YaHei', sans-serif;
}
.news-item {
display: flex;
padding: 15px 0;
border-bottom: 1px solid #eee;
transition: background-color 0.3s;
}
.news-item:hover {
background-color: #f9f9f9;
}
.news-item img {
width: 120px;
height: 80px;
object-fit: cover;
margin-right: 15px;
}
.news-content {
flex: 1;
}
.news-content h3 {
margin: 0 0 8px 0;
font-size: 16px;
color: #333;
}
.summary {
margin: 0 0 5px 0;
color: #666;
font-size: 14px;
line-height: 1.5;
}
.time {
color: #999;
font-size: 12px;
}
响应式设计
为适应不同设备屏幕,可以添加媒体查询实现响应式布局:

@media (max-width: 600px) {
.news-item {
flex-direction: column;
}
.news-item img {
width: 100%;
height: auto;
margin-bottom: 10px;
margin-right: 0;
}
}
动画效果
可以添加一些交互效果增强用户体验:
.news-item {
transform: translateY(0);
transition: transform 0.2s;
}
.news-item:hover {
transform: translateY(-2px);
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
分页样式
如果需要添加分页功能,可以使用以下样式:
<div class="pagination">
<a href="#">«</a>
<a href="#" class="active">1</a>
<a href="#">2</a>
<a href="#">3</a>
<a href="#">»</a>
</div>
.pagination {
display: flex;
justify-content: center;
margin-top: 20px;
}
.pagination a {
color: #333;
padding: 8px 16px;
text-decoration: none;
border: 1px solid #ddd;
margin: 0 4px;
}
.pagination a.active {
background-color: #4CAF50;
color: white;
border: 1px solid #4CAF50;
}
.pagination a:hover:not(.active) {
background-color: #ddd;
}
这些样式可以根据实际需求进行调整和扩展,创建出符合网站整体风格的新闻列表。






