HTML學習
注釋
<!-- -->
組成
告訴瀏覽器我是html文件<!DOCTYPE html>
<title>瀏覽器標簽</title>
<body> <!--- 其中是主要內容 --->
<p> 段落 </p>
</body>
</html> (結束點)
標題 段落
- **
**開始標簽 **
**結束標簽 也叫雙標簽 這里面是 一級標題標簽
; 還有這是二級標簽,相比一級字體變小了;一共有6級標簽
字體改變,有序,無序標簽的使用
<em> 強調斜體文字 </em> <br>
<u>下劃線文字</u><br>
<i>斜體文字</i><br>
<small>小文字</small><br>
<mark>高亮文字</mark><br>
<del>表示內容刪除文字</del><br>
<ins>下劃線文字</ins>

有序列表
- 列表一
- 列表二
- 列表三
無序列表
- 蘋果
- 香蕉
- 橙子
圖片
‘<!— img src= —>’
- alt可以給圖片說明
空格 劃線換行
’
’
’
表格
- td data數據
- th header標題
- row 行
<table>
<tr>
<th> 姓名</th>
<th> 年齡</th>
</tr>
<tr>
<td> 張三</td>
<td>李四</td>
</tr>
<tr>
<td>10</td>
<td>9</td></table>
ps:若想要其中表格有分割線,則在table后寫border=" "
表單
用于搜集不同類型的用戶輸入
input標簽
純文本:
<input type=text" name=firstname>性別選擇:(單選)
<input type="radio" name="sex"value="female" checked>
<input type="radio" name="sex"value="male"checked><br>密碼:
<input type="password" name="pwd"> <br>提交文件:
<input type="file"><br>提交按鈕:
<input type="submit">選擇顏色
<input type="color"><br>
<form action="#"><p><label>用戶名 <input type="text" placeholder="請輸入內容"></label></p><p><label>密碼 <input type="password" placeholder="請輸入密碼"></label></p><p>性別:<label><input type="radio" name="gender"> 男</label><label><input type="radio" name="gender"> 女</label><label><input type="radio" name="gender"> 其他</label></p><p>愛好:<label><input type="checkbox" name="hobby"> 唱</label><label><input type="checkbox" name="hobby"> 跳</label><label><input type="checkbox" name="hobby"> rap</label><label><input type="checkbox" name="hobby"> 籃球</label></p><p><input type="submit" value="提交"></p>
</form><!-- p標簽的使用可以讓每行間距更大 更美觀 --->
<!-- 被label包圍住的標簽只要點擊文字也可以選中框 -->
<!-- type是固定的 name value名字不是固定的
div標簽
- 塊級元素
- 一個個盒子 可以給頁面分塊
- 單單的div是看不見的 要與css結合
<div class=a>
<h1>標題</h1>
<p>主要內容</p>
<p>主要內容</p>
</div>
span標簽
- 行內元素 和div相像
- 給段落中某段字某種樣式
- 配合css使用
<h2>變<span style="color:blue">色</span>了</h2>
CSS3
html中引用css3
注釋
/* */
優先級:外部CSS < '
1. 外部CSS
.html中
<head>
<title>我的網站標簽</title> <link rel="stylesheet" href="./css/css1.css">
</head>.css中
body{
background-color:lightblue'
}2.內部CSS
.html的head 和 body中間
<style>h1{background-color: lightblue}p{background-color: black;}
</style>3.行內CSS
<body><h1 style="color:blue;text-align:center;">This is a heading</h1>
<p style="color:red;">This is a paragraph.</p></body>
CSS選擇器
class類名
- 可以有好幾個
<div class="my-box">
<h2>第一個標題</h2><p>第一個模塊</p><p>第二個模塊</p>
</div><hr>
<div class="my-box"><h2>第二個標題</h2><p>第三個模塊</p><p>第四個模塊</p>
</div>.my-box{
background-color:lightblue;
padding:10px;
border:1px solid #ccc;
}
id
- 元素的 id 在頁面中是唯一的,因此 id 選擇器用于選擇一個唯一的元素
- 一般給table , div之類的 命名
<div id="unique-box"><h2>第一個標題</h2><p>第一個模塊</p><p>第二個模塊</p>
</div>#unique-box{background-color: rgb(144, 166, 238);padding: 10px;
}
通用選擇器
*{
text-align:center;
color:blue;}
分組選擇器
h1 {text-align: center;color: red;
}h2 {text-align: center;color: red;
}p {text-align: center;color: red;
}
CSS顏色
背景
background-color:rgb(255, 99, 71);
<h1 style="background-color:DodgerBlue;">China</h1>
文本顏色
color:tomato;
h1 style="color:Tomato;">China</h1>
邊框顏色
border:2px solod Tomato
<h1 style="border:2px solid Tomato;">Hello World</h1>
<div id="potato">#potato {border: 2px solid #333; /* 邊框 */padding: 5px; /* 內邊距 */border-radius: 8px; /* 圓角 */background-image: url("..\GauKIM4aAAMbLnh.jpeg");background-image: ;background-size: cover; 讓圖片鋪滿整個div,等比縮放background-repeat: no-repeat; /* 不重復平鋪 */background-position: center; background-color: azure;
}
CSS字體
font-size: 24px; /*文字大小*/
color: #ccc; /*文字顏色*/
text-align: center; /*默認left*/
letter-spacing:15px; /*字間距 */
font-weight:bolid; /*加粗*/
表格
<table id="table_css" border>#table_css{width: 300px;height: 300px;border-spacing: 5px;margin: 0 auto; /* 讓表格整體在中央 */
}
#table_css th{text-align: center; /*單元格中的文本在中央*/}
#table_css td{text-align: center;}/*給某一行設置顏色*/
#table_css tr:nth-child(1) { background-color: rgb(131, 14, 30); } /* 第一行 */
#table_css tr:nth-child(2) { background-color: lightgreen; } /* 第二行 */
#table_css tr:nth-child(3) { background-color: pink; } /* 第三行 *//*給某列data設置顏色,不給head 上色*/
#table_css td:nth-child(2) { background-color: lightgreen; } /* 第二行 */
邊框
高度和寬度
auto 瀏覽器默認高 寬
length
%
initial 將高 寬設為默認值
inherit 從其父繼承div{height:200px;width: 50%;background-color: powerblue;}
邊框
樣式
border-style
border-radius:5px //圓角邊框
border-top-style:dotted; //上下左右單獨邊框
border-right-style: solid;
border-bottom-style:dotted;
border-left-style:solid;
寬度
border-width
border-width:215px 10px 4px 35px
//對應 上 右 下 左
border-width:medium/thin/thick
顏色
border-color
border-color: red blue green yellow
//對應 上紅 左藍 下綠 右紅色
簡寫
p{
border 5px solid red;
}或者單邊定義
p{
border-left:6px solid red
}
外邊距
p{
margin-top: 100px;
margin-bottom:100px;
margin-right: 150px;
margin-left: 80px;
}或者簡寫
margin: 25px 50px 75px 100px;
//上 右 下 左
內邊距
padding
div{padding-top:50px;padding-right:30px;padding-bottom:50px;padding-left:80px;
}
浮動
像word中的圖片內嵌之類的
定位
一共五種
position staticrelativefixedabsolutesticky
- static
-
靜態定位的元素不受 top、bottom、left 和 right 屬性的影響。
.map{width: 400px;height: 400px;background-color: black;position:static; }
- relative
-
position: relative;
的元素相對于其正常位置進行定位.map{width: 400px;height: 400px;background-color: black;position:relative;left:150px;top:0px; }
- fixed
-
position: fixed;
的元素是相對于視口定位的,這意味著即使滾動頁面,它也始終位于同一位置 -
top、right、bottom 和 left 屬性用于定位此元素。
<style> .map{width: 400px;height: 400px;background-color: black;position:fixed;left:150px;top:0px; } </style>
- absolute
-
position: absolute;
的元素相對于最近的定位祖先元素進行定位 -
如果絕對定位的元素沒有祖先,它將使用文檔主體(body),并隨頁面滾動一起移動
-
跟隨元素的div要放在父元素的div里面
.map{width: 400px;height: 200px;background-color: rgb(44, 246, 65);position:fixed;top:150px;left:15px;}.map2{width: 200px;height: 100px;background-color: rgb(0, 0, 0);position:absolute;left:15px;top:50px; <div class="map"><div class="map2"></div></div>
-
sticky
-
重疊元素
<div class="bg-box"><h1>這是透明度</h1> </div>.bg-box {background-image: url("https://img-s-msn-com.akamaized.net/tenant/amp/entityid/AA1LMdmf.img?w=534&h=300&m=6");background-size: cover; /* 讓圖片鋪滿 */background-position: center;width: 300px;height: 300px; }后面這個方法不好 不推薦 img {position: absolute;left: 0px;top: 0px;z-index: -1; }
動畫
@keyframes
animation-name
animation-duration
animation-delay
animation-iteration-count
animation-direction
animation-timing-function
animation-fill-mode
animation
一個顏色塊逐漸變色效果
這整塊內容都在>
div {width: 100px;height: 100px;background-color: red; animation-name: example1; animation-duration: 4s;
}
@keyframes example1{from{background-color:black;}to {background-color: blue;}
}
顏色塊變色和滑動效果