web前端网页设计代码
时间: 2023-07-27 19:06:13 浏览: 110
Web前端网页设计需要使用HTML、CSS和JavaScript等技术,以下是一个简单的示例代码:
HTML代码:
```
<!DOCTYPE html>
<html>
<head>
<title>我的网页</title>
<meta charset="UTF-8">
<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>
</ul>
</nav>
</header>
<main>
<section>
<h2>最新新闻</h2>
<article>
<h3>标题1</h3>
<p>内容1</p>
</article>
<article>
<h3>标题2</h3>
<p>内容2</p>
</article>
</section>
<aside>
<h2>热门文章</h2>
<ul>
<li><a href="#">文章1</a></li>
<li><a href="#">文章2</a></li>
<li><a href="#">文章3</a></li>
</ul>
</aside>
</main>
<footer>
<p>© 2021 我的网页</p>
</footer>
</body>
</html>
```
CSS代码:
```
body {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
}
header {
background-color: #333;
color: #fff;
padding: 20px;
}
nav ul {
list-style: none;
margin: 0;
padding: 0;
}
nav li {
display: inline-block;
margin-right: 20px;
}
nav a {
color: #fff;
text-decoration: none;
}
main {
display: flex;
flex-wrap: wrap;
padding: 20px;
}
section {
flex-grow: 1;
flex-basis: 70%;
margin-right: 20px;
}
aside {
flex-grow: 1;
flex-basis: 30%;
}
article {
margin-bottom: 20px;
}
h3 {
margin-top: 0;
}
footer {
background-color: #333;
color: #fff;
text-align: center;
padding: 20px;
}
```
JavaScript代码:
```
// 实现一个简单的导航栏下拉菜单
var dropdowns = document.querySelectorAll('.dropdown');
for (var i = 0; i < dropdowns.length; i++) {
dropdowns[i].addEventListener('click', function() {
this.classList.toggle('active');
var dropdownMenu = this.querySelector('.dropdown-menu');
dropdownMenu.classList.toggle('show');
});
}
```
阅读全文