效果
完整代码
HTML部分
<header> <div class="logo">LOGO</div> <nav> <ul> <li><a href="#home">首页</a></li> <li><a href="#about">关于我们</a></li> <li><a href="#services">服务</a></li> <li><a href="#news">新闻公告</a></li> <li><a href="#contact">联系我们</a></li> </ul> </nav> </header> <section id="home" class="banner"> <h1>欢迎来到我们的公司</h1> <p>我们致力于提供最佳的服务。</p> </section> <section id="about"> <div class="container"> <h2>关于我们</h2> <p>我们公司成立于2000年,专注于提供高质量的产品和服务。我们的团队由经验丰富的专业人士组成,致力于为客户提供最佳解决方案。</p> <p>我们的使命是通过创新和卓越的服务,帮助客户实现他们的目标。</p> </div> </section> <section id="news"> <div class="container"> <h2>公司新闻和公告</h2> <div class="news-container"> <article class="news-item"> <h3>新闻标题1</h3> <img src="./img/1.png" alt="新闻图片1"> <p>这是新闻内容1的详细描述。</p> <a href="#">阅读更多</a> </article> <article class="news-item"> <h3>新闻标题2</h3> <img src="./img/2.png" alt="新闻图片2"> <p>这是新闻内容2的详细描述。</p> <a href="#">阅读更多</a> </article> <article class="news-item"> <h3>新闻标题3</h3> <img src="./img/3.png" alt="新闻图片3"> <p>这是新闻内容3的详细描述。</p> <a href="#">阅读更多</a> </article> </div> </div> </section> <footer> <p>© 2024 公司名. 保留所有权利.</p> <div class="social-media"> <a href="#">微博</a> <a href="#">微信</a> <a href="#">领英</a> </div> </footer>
CSS部分
* { box-sizing: border-box; margin: 0; padding: 0; font-family: Arial, sans-serif; } body { background-color: #f4f4f4; line-height: 1.6; padding: 0px; } header { background: #333; color: #fff; padding: 20px; display: flex; justify-content: space-between; align-items: center; animation: slideDown 1s ease-out; } .logo { font-size: 1.5em; font-weight: bold; } nav ul { list-style: none; display: flex; gap: 20px; } nav a { color: #fff; text-decoration: none; transition: color 0.3s; } nav a:hover { color: #ff6347; } .banner { background: url(https://images.unsplash.com/photo-1600585154340-be6161a56a0c) no-repeat center center / cover; color: #fff; text-align: center; padding: 150px 20px; animation: fadeIn 2s ease-in; } .container { max-width: 1200px; margin: 0 auto; padding: 20px; animation: fadeIn 1s ease-in; } #about, #services, #contact { padding: 40px 20px; background: #fff; border-radius: 10px; margin-bottom: 20px; } h2 { margin-bottom: 20px; } .service-item { background: #f9f9f9; padding: 20px; margin-bottom: 20px; border-radius: 10px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); transform: translateY(-20px); animation: slideIn 0.5s forwards; } #news .news-container { display: flex; flex-wrap: wrap; gap: 20px; } .news-item { flex: 1 1 calc(33.333% - 20px); background: #fff; padding: 20px; border-radius: 10px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); transition: transform 0.3s; } .news-item:hover { transform: scale(1.05); } .news-item img { max-width: 100%; border-radius: 10px; } .news-item h3 { margin-top: 10px; margin-bottom: 10px; } .news-item p { margin-bottom: 10px; } .news-item a { color: #333; text-decoration: none; font-weight: bold; transition: color 0.3s; } .news-item a:hover { color: #ff6347; } footer { background: #333; color: #fff; text-align: center; padding: 20px; margin-top: 20px; border-radius: 10px; animation: slideUp 1s ease-in; } .social-media a { color: #fff; text-decoration: none; margin: 0 10px; transition: color 0.3s; } .social-media a:hover { color: #ff6347; } /* 动画效果 */ @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } } @keyframes slideIn { from { transform: translateY(-20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } } @keyframes slideDown { from { transform: translateY(-100%); opacity: 0; } to { transform: translateY(0); opacity: 1; } } @keyframes slideUp { from { transform: translateY(100%); opacity: 0; } to { transform: translateY(0); opacity: 1; } }