WEB01_Day03(上)-盒子模型、文字相關樣式、CSS三大特性、定位
一、盒子模型
1.1 定義:
盒子模型是所有標籤(HTML元素)都擁有的模型特徵。盒子模型中規定所有標籤擁有的層級結構,使用盒子模型可以進行對標籤元素進行修飾和定位處理。如圖所示:
-
元素的寬和高
-
元素的內邊距
-
元素的邊框
-
元素的外邊距
1.2 盒子模型:元素寬高
盒子模型中使用寬和高進行控制元素的大小。如果需要對於元素的大小進行賦值,可以使用畫素px進行賦值,也可以使用百分比的方式進行賦值(對上級元素進行百分比設定賦值)
注意:塊級元素可以進行設定寬和高,行內元素不可以設定寬和高,行內塊可以進行設定寬和高
1.3 盒子模型:內邊距
-
表示方式:padding
-
作用:用來表示元素內容到邊框之間的距離
-
賦值的方式:
-
padding:5px; 表示上下左右四個方向的內邊距值為5畫素。
-
padding:10px 5px; 表示上下的畫素值為10畫素,左右的畫素值為5畫素。
-
padding:1px 2px 3px 4px; 表示順時針方位(上右下左)的內邊距的值分別為1、2、3、4畫素
-
padding-left/right/top/bottom:3px; 表示距離單獨的某一個方位的內邊距畫素值為3畫素。
-
-
特徵:內邊距這個範圍內是可以顯示顏色或者圖片。
1.4 盒子模型:邊框
-
邊框:border
-
作用:可以設定元素的邊框,包括邊框粗細,顏色樣式等,讓元素更美觀
-
賦值方式 :
-
border:邊框粗細 邊框樣式 顏色; 四個方向新增邊框
-
border-left/right/top/bottom: 邊框粗細邊框樣式顏色; 單獨某個方向賦值
-
border-radius: 圓⻆值越大越圓當值大於寬高(包括邊框)一半時為正圓
-
1.5 盒子模型:外邊距
-
外邊距:margin
-
作用:設定元素邊框到上級元素或其它同級元素的距離,這個距離不會出現當前元素的背景,但是也計算在當前元素總的寬和高中
-
賦值方式 :
-
margin-left /top/right /bottom 單獨給某一個方向新增外邊距
-
margin:10px 給四個方向新增10個畫素外邊距
-
margin: 10px 20px 上下10 左右20px
-
margin: 0 auto 上下0 左右自動居中
-
margin: 10px 20px 30px 40px
-
-
案例一:同級元素之間外邊距設定
-
案例二:上級元素之間外邊距設定
二、文字相關樣式
2.1文字修飾和字型設定
-
文字水平對齊方式 text-align:left/right/center
-
文字修飾 text-decoration:overline/underline/line-through/none
-
文字陰影 text-shadow: 顏色 x偏移值 y偏移值濃度值越大越模糊
-
行高 line-height: 20px 實現文字垂直居中
-
字型大小 font-size:20px;
-
字型加粗 font-weight: bold加粗 normal去掉加粗效果
-
斜體 font -style:italic(斜體)/oblique(傾斜)/normal(正常)
-
字體系列設定 font-family:xxx,xxxx;
-
font : 字型 xxx,xxx,xxxx;(最不常用的)
2.2 CSS專案實戰
學子商城練習(一)