1.使用html+css+javascript制作静态网页
使用html+css+javascript制作网页
1.使用html制作一个静态网页
创建first.html
1
2
3
4
5
6
7
8
9
10
11
12
13
<html>
<head>
<meta charset="UTF-8">
<title>Page Title</title>
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
</body>
</html>浏览器打开网页。
显示成功
2.使用html与css制作一个静态网页
Internal CSS
first.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<html>
<head>
<meta charset="UTF-8">
<title>Page Title</title>
<style>
body {
background-color: linen;
}
h1 {
color: maroon;
margin-left: 40px;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>浏览器打开网页。
查看结果
Inline CSS
first.html
1
2
3
4
5
6
7
8
9
10
11
12
13
<html>
<head>
<meta charset="UTF-8">
<title>Page Title</title>
</head>
<body>
<h1 style="color:blue;text-align:center;">This is a heading</h1>
<p style="color:red;">This is a paragraph.</p>
</body>
</html>浏览器打开网页。
查看结果
External CSS
first.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hello HTML and CSS</title>
<link rel="stylesheet" href="styles.css" type="text/css">
</head>
<body>
<main>
<h1>Welcome, Web Creator!</h1>
<p>This box is built with HTML structure and CSS styling.</p>
<p><mark>Edit the code</mark> to change colors, fonts, or layout.</p>
<button>Start Building</button>
</main>
</body>
</html>styles.css
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30body {
font-family: "Segoe UI", sans-serif;
background:#f2f6fb;
margin:0;
}
main {
max-width: 600px;
margin: 60px auto;
background:#fff;
padding:32px;
border-radius:8px;
}
h1 {
color:#04AA6D;
margin-top:0;
}
mark {
background:#fffd91;
}
button {
background:#04AA6D;
color:#fff;
border:none;
padding:12px 24px;
border-radius:999px;
cursor:pointer;
}
button:hover {
background:#028a56;
}运行first.html
查看结果
3.html+css+javascript
Internal JS
first.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<html>
<body>
<head>
<meta charset="UTF-8">
<title>Hello HTML and JavaScript</title>
</head>
<h1>My First JavaScript</h1>
<p>JavaScript can change the content of an HTML element:</p>
<button type="button" onclick="myFunction()">Click Me!</button>
<p id="demo">This is a demonstration.</p>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "Hello JavaScript!";
}
</script>
</body>
</html>运行first.html
查看结果
HTML 标签属性触发
first.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<html>
<body>
<head>
<meta charset="UTF-8">
<title>Hello HTML and JavaScript</title>
</head>
<h1>My First JavaScript</h1>
<p>JavaScript can change the content of an HTML element:</p>
<button type="button" onclick="myFunction()">Click Me!</button>
<p id="demo">This is a demonstration.</p>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "Hello JavaScript!";
}
</script>
</body>
</html>运行first.html
查看结果
External JS
first.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<html>
<body>
<head>
<meta charset="UTF-8">
<title>Hello HTML and JavaScript</title>
</head>
<h2>Demo JavaScript in Body</h2>
<p id="demo">A Paragraph</p>
<button type="button" onclick="myFunction()">Try it</button>
<script src="myScript.js"></script>
</body>
</html>myScript.js
1
2
3function myFunction() {
document.getElementById("demo").innerHTML = "Paragraph changed.";
}运行first.html
查看结果
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.
