MyWebsite Hello,World!">
以下是一些網頁制作中常用的HTML、CSS和JavaScript代碼示例:
### HTML 基礎結構
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Website</title>
</head>
<body>
<h1>Hello, World!</h1>
<p>This is a paragraph.</p>
</body>
</html>
```
### CSS 樣式設置
```css
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
}
h1 {
color: blue;
}
p {
font-size: 16px;
line-height: 1.5;
}
```
### JavaScript 基礎操作
```javascript
// 彈出對話框
alert("Hello, World!");
// 控制臺輸出
console.log("This is a message in the console.");
// 獲取元素并修改內容
document.getElementById("myElement")[xss_clean] = "New content";
```
### 響應式設計
```css
/* 在不同屏幕尺寸下修改樣式 */
@media screen and (max-width: 600px) {
body {
font-size: 14px;
}
}
```
### 簡單交互效果
```html
<!-- 切換圖片 -->
<button onclick="changeImage()">Change Image</button>
<img id="myImage" src="image1.jpg" alt="Image">
<script>
function changeImage() {
var img = document.getElementById("myImage");
img.src = "image2.jpg";
}
</script>
```
這些是網頁制作中常用的基礎代碼示例,您可以根據需要進行修改和擴展,實現不同的功能和效果。