
批改狀態(tài):合格
老師批語(yǔ):總得來說寫的不錯(cuò)很認(rèn)真,不要重復(fù)提交!
先來個(gè)概述圖:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
div {
/* 設(shè)定div大小 */
width: 200px;
height: 200px;
/* 邊框線方便演示 */
border: 1px dashed black;
float: left;
}
.box {
/* 背景顏色:16進(jìn)制 */
background-color: #eee;
}
.box2 {
/* 背景顏色:rgb */
background-color: rgb(109, 109, 109);
}
.box3 {
/* 背景顏色:單詞 */
background-color: gray;
}
.box4 {
/* 背景顏色:rgba */
background-color: rgb(109, 109, 109,0.5) ;/*其中a代表透明度*/
}
</style>
</head>
<body>
<div class="box">box</div>
<div class="box2">box2</div>
<div class="box3">box3</div>
<div class="box4">box4</div>
</body>
</html>
背景默認(rèn)顯示方式:垂水平直平鋪
No-repeat:不重復(fù)
Repeat-x:水平平鋪
Repeat-y:垂直重復(fù)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
div {
/* 設(shè)定div大小 */
width: 600px;
height: 600px;
/* 邊框線方便演示 */
border: 1px dashed black;
float: left;
margin: 0 20px;
}
.box {
/* 圖片地址可以為本地圖片和網(wǎng)絡(luò)地址 */
/* 背景默認(rèn)顯示方式,水平垂直平鋪 */
background-image: url("1.jpeg");
}
.box2 {
/* 不重復(fù) */
background-image: url("1.jpeg");
background-repeat: no-repeat;
}
.box3 {
/* 水平平鋪 */
background-image: url("1.jpeg");
background-repeat: repeat-x;
}
.box4 {
/* 垂直平鋪 */
background-image: url("1.jpeg");
background-repeat: repeat-y;
}
</style>
</head>
<body>
<div class="box">box</div>
<div class="box2">box2</div>
<div class="box3">box3</div>
<div class="box4">box4</div>
</body>
</html>
屬性值cover 寬和高較高值得比例縮放 會(huì)破壞圖片的顯示效果
屬性值contain 寬和高較低值得比例縮放 不會(huì)破壞圖片的顯示效果
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
div {
/* 設(shè)定div大小 */
width: 600px;
height: 800px;
/* 邊框線方便演示 */
border: 1px dashed black;
float: left;
margin: 0 20px;
}
.box1 {
/* 導(dǎo)入圖片 */
background-image: url("1.jpeg");
/* 設(shè)置不重復(fù) */
background-repeat: no-repeat;
/* 屬性值contain 寬和高較低值得比例縮放 不會(huì)破壞圖片的顯示效果*/
background-size: contain;
}
.box2 {
/* 導(dǎo)入圖片 */
background-image: url("1.jpeg");
/* 設(shè)置不重復(fù) */
background-repeat: no-repeat;
/* 屬性值cover 寬和高較高值得比例縮放 會(huì)破壞圖片的顯示效果*/
background-size: cover;
}
.box3 {
/* 導(dǎo)入圖片 */
background-image: url("1.jpeg");
/* 設(shè)置不重復(fù) */
background-repeat: no-repeat;
/* 數(shù)值 */
background-size: 200px 200px;
}
.box4 {
/* 導(dǎo)入圖片 */
background-image: url("1.jpeg");
/* 設(shè)置不重復(fù) */
background-repeat: no-repeat;
/* 百分百 */
background-size: 20% 20%;
}
</style>
</head>
<body>
<div class="box1">box1</div>
<div class="box2">box2</div>
<div class="box3">box2</div>
<div class="box4">box2</div>
</body>
</html>
數(shù)值定位是,屬性值是有順序的
屬性值只有一個(gè),第二個(gè)默認(rèn)center
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
div {
width: 800px;
height: 1000px;
border: 1px dashed red;
float: left;
/* 導(dǎo)入圖片 */
background-image: url('1.jpeg');
/* 防止重復(fù) */
background-repeat: no-repeat;
}
.box1{
/* 數(shù)值定位,水平/垂直 有順序 */
background-position: 100px ;
}
.box2{
/* 方位定位,無順序要求 */
background-position: center left;
}
.box3{
/* 方位定位,無順序要求 */
background-position: 100% 20%;
}
/* 定位時(shí),單個(gè)值,第二個(gè)值默認(rèn)center */
</style>
</head>
<body>
<div class="box1"></div>
<div class="box2"></div>
<div class="box3"></div>
</body>
</html>
使用fixed屬性值時(shí),圖片脫離原有的位置,可以使用定位。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<style>
body > * {
float: left;
border: 1px dashed red;
margin: 0 100px;
}
.box1,
.box2 {
width: 600px;
height: 600px;
overflow: scroll;
}
.box3,
.box4 {
width: 256px;
height: 600%;
background-repeat: no-repeat;
background-image: url("1.jpeg");
}
.box3 {
/* 固定背景 */
background-attachment: fixed;
/* 定位背景位置 */
background-position: 120px 20px;
}
.box4 {
/* 背景不固定默認(rèn)值*/
background-attachment: scroll;
}
</style>
<body>
<div class="box1">
<div class="box3"></div>
</div>
<div class="box2">
<div class="box4"></div>
</div>
</body>
</html>
background:顏色 圖片 重復(fù) 固定 定位;
同時(shí)擁有顏色和圖片時(shí), 圖片會(huì)覆蓋顏色
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<style>
div {
width: 500px;
height: 500px;
border: 1px dashed red;
/* 屬性簡(jiǎn)寫 */
background: #ccc url("1.jpeg") no-repeat scroll 100px 20px;
}
</style>
<body>
<div></div>
</body>
</html>
什么是精靈圖:
css精靈(CSS sprites),是一種網(wǎng)頁(yè)圖片應(yīng)用處理技術(shù)。主要是指將網(wǎng)頁(yè)中需要的零星的小圖片集成到一個(gè)大的圖片中
應(yīng)用的原因:
精靈圖的使用: css精靈圖需要配合背景的圖片和背景定位
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.box {
width: 960px;
height: 500px;
border: 1px solid black;
clear: both;
}
.box > *:not(img) {
width: 100px;
height: 100px;
border: 1px dashed red;
float: left;
}
.box1 {
/* 導(dǎo)入圖片 */
background-image: url("1.png");
/* 定位背景獲取精靈圖上需要的部分圖片 */
background-position: 0px -30px;
}
.box2 {
/* 導(dǎo)入圖片 */
background-image: url("1.png");
/* 定位背景獲取精靈圖上需要的部分圖片 */
background-position: 100px -30px;
}
.box3 {
/* 導(dǎo)入圖片 */
background-image: url("1.png");
/* 定位背景獲取精靈圖上需要的部分圖片 */
background-position: -90px -120px;
}
.box4 {
/* 導(dǎo)入圖片 */
background-image: url("1.png");
/* 定位背景獲取精靈圖上需要的部分圖片 */
background-position: -275px -210px;
}
.box5 {
/* 導(dǎo)入圖片 */
background-image: url("1.png");
/* 定位背景獲取精靈圖上需要的部分圖片 */
background-position: 0px -30px;
}
</style>
</head>
<body>
<div class="box">
<div class="box1"></div>
<div class="box2"></div>
<div class="box3"></div>
<div class="box4"></div>
<div class="box5"></div>
<img src="1.png" alt="" />
</div>
</body>
</html>
眾所周知,單位字體的文件大小小于圖片的大小,考慮精靈圖處理的是一張張圖片,有人就有了一個(gè)奇思妙想—把圖片轉(zhuǎn)換成字體(實(shí)際上字體本來就是那么設(shè)計(jì)下來的。)
轉(zhuǎn)換成字體后,可以使用特殊的代碼來顯示出指定的圖片。
字體圖標(biāo)比精靈圖有一個(gè)非常明顯的好處,因?yàn)樗亲煮w,所以它能夠改變字體顏色,能改變字體大?。ú⑶也粫?huì)失真)。
例子:
僅演示字體圖標(biāo)的使用
1.獲取字體圖標(biāo)
iconfont(下面演示使用)
IconShock·····
? 多圖演示獲取步驟:
將下載的壓縮包解壓獲取文件夾,并將壓縮包下的所有文件移動(dòng)到項(xiàng)目(也可將文件夾拖至項(xiàng)目,保證項(xiàng)目的目錄層次)
字體引用
第一步:引入項(xiàng)目下面生成的 fontclass 代碼:
<link rel="stylesheet" href="./iconfont.css">
第二步:挑選相應(yīng)圖標(biāo)并獲取類名,應(yīng)用于頁(yè)面:
<span class="iconfont icon-xxx"></span>
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號(hào)
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號(hào)