SS3中包含幾個新的背景屬性,提供更大背景元素控制。
表中的數(shù)字指定完全支持該屬性的第一個瀏覽器版本。
數(shù)字后面的 -webkit- 或者 -moz- 使用時需要指定前綴。
屬性ChromeFirefoxSafariOperaIEbackground-image (多背景)4.09.03.63.111.5background-size4.0 1.0 -webkit-9.04.0 3.6 -moz-4.1 3.0 -webkit-10.5 10.0background-origin1.09.04.03.010.5background-clip4.09.04.03.010.5
CSS3允許你為一個元素添加多個背景圖像, 通過使用 background-image 屬性.不同的背景圖像用逗號隔開,圖像疊加在一起,
例:有兩個背景圖像,第一圖像是背景圖(在右下角)和第二圖像是一個GIF動圖(在左上角)。
代碼如下:
<!DOCTYPE HTML>
<meta charset="utf-8">
<title>項目</title>
<head>
<style>
#example1 {
background-image: url(img/fy_indexBg.jpg), url(img/17I_hd.mp4.gif);
background-position: right bottom, left top;
background-repeat: no-repeat, repeat;
}
</style>
</head>
<html>
<body>
<div id="example1">
<h1>Lorem Ipsum Dolor</h1>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
<p>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>
</div>
</body>
</html>
可以使用單獨的背景屬性(如上所示)或背景簡寫屬性指定多個背景圖像。
下面的例子使用了背景速記
(上面的例子,有相同的結果)
#example1 {
background: url(img_flwr.gif) right bottom no-repeat, url(paper.gif) left top repeat;
}
CSS3 background-size 屬性允許你指定背景圖像的尺寸.
在CSS3之前的背景圖像大小是圖像的實際大小。CSS3允許我們使用背景圖像在不同的上下文中。
size可以指定長度、百分比,或通過使用一個關鍵詞: contain 或者 cover.
示例:圖片背景圖像比原圖像小得多(以像素為單位):
代碼如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>項目</title>
<style>
#example1 {
border: 1px solid black;
background:url(img_flwr.gif);
background-repeat: no-repeat;
padding:15px;
}
#example2 {
border: 1px solid black;
background:url(img_flwr.gif);
background-size: 100px 80px;
background-repeat: no-repeat;
padding:15px;
}
</style>
</head>
<body>
<p>原背景:</p>
<div id="example1">
<h2>Lorem Ipsum Dolor</h2>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
<p>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>
</div>
<p>縮放背景圖:</p>
<div id="example2">
<h2>Lorem Ipsum Dolor</h2>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
<p>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>
</div>
</body>
</html>
background-size 屬性兩個可能值是:contain 和 cover.
含有關鍵詞尺度的背景圖像盡可能大的(但它的寬度和高度必須在內(nèi)容區(qū)域)。因此,根據(jù)背景圖像的比例和背景區(qū)的定位,有可能不被背景圖像覆蓋。
cover 關鍵詞縮放背景圖像,內(nèi)容區(qū)域完全覆蓋了背景圖像(它的寬度和高度等于或超過該范圍的內(nèi)容)。因此,背景圖像的某些部分可能不在背景區(qū)的定位是可見的。
下面的示例演示了使用contain和cover:
#div1 {
background: url(img_flower.jpg);
background-size: contain;
background-repeat: no-repeat;
}
#div2 {
background: url(img_flower.jpg);
background-size: cover;
background-repeat: no-repeat;
}
background-size 屬性也接受多個背景值(使用逗號分隔列表),當處理多個背景時。
下面的示例指定三個背景圖像,每個圖像具有不同的background-size值:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>項目</title>
<style>
#example1 {
background: url(img/fy_indexBg.jpg) left top no-repeat, url(img/fy_indexBg.jpg) right bottom no-repeat, url(img/17I_hd.mp4.gif) left top repeat;
padding: 15px;
background-size: 50px, 130px, auto;
color: white;
}
</style>
</head>
<body>
<div id="example1">
<h1>Lorem Ipsum Dolor</h1>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
<p>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>
</div>
</body>
</html>
如果希望在一個覆蓋整個瀏覽器窗口的網(wǎng)站上有一個背景圖像。.
要求如下:
填滿整個頁面的圖像(沒有空白)
下面的示例演示如何使用HTML元素(HTML元素始終是瀏覽器窗口的高度)。然后設置一個固定中心的背景上。然后用background-size屬性調(diào)整它的大小:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>項目</title>
<style>
html {
background: url(img/fy_indexBg.jpg) no-repeat center fixed;
background-size: cover;
}
</style>
</head>
<body>
<h1>整個頁面背景圖</h1>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper
suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>
</body>
</html>
CSS3 background-origin 屬性指定在背景圖像定位在哪里.
這個屬性有三個不同的值:
border-box :背景圖像從邊框的左上角開始。
padding-box :(默認)背景圖像從左上角的填充邊緣。
content-box :背景圖像從左上角的內(nèi)容
下面的例子說明了background-origin屬性:
#example1 {
border: 10px solid black;
padding: 35px;
background: url(img/fy_indexBg.jpg);
background-repeat: no-repeat;
}
#example2 {
border: 10px solid black;
padding: 35px;
background: url(img/fy_indexBg.jpg);
background-repeat: no-repeat;
background-origin: border-box;
}
#example3 {
border: 10px solid black;
padding: 35px;
background: url(img/fy_indexBg.jpg);
background-repeat: no-repeat;
background-origin: content-box;
}
完整代碼:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>編程字典</title>
<style>
#example1 {
border: 10px solid black;
padding: 35px;
background: url(img/fy_indexBg.jpg);
background-repeat: no-repeat;
}
#example2 {
border: 10px solid black;
padding: 35px;
background: url(img/fy_indexBg.jpg);
background-repeat: no-repeat;
background-origin: border-box;
}
#example3 {
border: 10px solid black;
padding: 35px;
background: url(img/fy_indexBg.jpg);
background-repeat: no-repeat;
background-origin: content-box;
}
</style>
</head>
<body>
<p>沒有 background-origin (padding-box 默認):</p>
<div id="example1">
<h2>Lorem Ipsum Dolor</h2>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
<p>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>
</div>
<p>background-origin: border-box:</p>
<div id="example2">
<h2>Lorem Ipsum Dolor</h2>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
<p>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>
</div>
<p>background-origin: content-box:</p>
<div id="example3">
<h2>Lorem Ipsum Dolor</h2>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
<p>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>
</div>
</body>
</html>
CSS3 background-clip 屬性指定背景的繪制面積.
該屬性有三個不同的值:
border-box - (默認) 背景是畫的邊框外邊緣 padding-box-背景被顯示到填充物的外緣。content-box - 背景是畫在內(nèi)容框內(nèi)
下面舉例演示了background-clip屬性:
#example1 {
border: 10px dotted black;
padding: 35px;
background: yellow;
background-clip: content-box;
}
本文主要介紹了CSS背景,通過CSS實現(xiàn)多背景顯示,自定義某一些尺寸顯示格式,background-origin等多個屬性的應用,豐富的案例幫助大家更好的理解。
希望大家自己去嘗試一下,實現(xiàn)的時候,總會有各種各樣的問題,切勿眼高手低,勤動手,才可以理解的更加深刻。
想學習更多Python網(wǎng)絡爬蟲與數(shù)據(jù)挖掘知識,可前往專業(yè)網(wǎng)站:http://pdcfighting.com/
海無涯,不要沉浸在知識的海洋里,迷失自己。
要知道自己想要什么,抓住重點,不忘初心。
這個世界上百分之20的人,掌握著百分之80的財富。
接下來一系列教程,就帶領大家抓住重點,一起做那百分之20的人。
往期知識點回顧:
重點屬性-display
重點屬性-position
重點屬性-float
重點屬性-flex
重點屬性-overflow
重點屬性-media
CSS 背景這里指通過background對對象設置背景屬性,如通過CSS設置背景各種樣式。
設置顏色作為對象背景顏色
設置圖片作為背景圖片
設置背景平鋪重復方向
設置或檢索背景圖像是隨對象內(nèi)容滾動還是固定的。
設置或檢索對象的背景圖像位置。
背景樣式的值是復合屬性值組合,也就是背景單詞的值可以跟多個屬性值,值與值之間使用一個空格間隔鏈接上即可。
1、設置純色背景。背景background可以設置對象純色的背景顏色,
2、設置圖為背景。可以設置對象背景為圖片,如果背景是圖片可以讓圖片重復平鋪橫鋪,或將圖片作為對象背景固定在對象任何位置。
屬性解析
no-repeat:不重復
repeat-x:水平方向(橫向)重復平鋪
repeat-y:垂直方向(豎向)重復平鋪
如果不設置,為全背景平鋪
left 圖片靠左
right 圖片靠右
top 圖片靠上
bottom 圖片靠下
fixed 圖片固定
scroll 背景圖片內(nèi)容滾動
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>flex布局css</title>
<style>
.container{
background: #FFF url(https://image.baidu.com/beijing.gif) no-repeat 0 0 fixed
}
</style>
</head>
<body>
<div class="container">
背景圖
</div>
</body>
</html>
復制代碼
1、由使用float浮動造成浮動產(chǎn)生無法顯示css背景顏色
2、高度不夠而產(chǎn)生背景無法顯示
3.如果是float造成:解決方法有三種,一個是設置clear清除浮動、設置css高度、設置css overflow樣式。
4.如果是高度原因:解決方案如下,設置夠高的高度,或取消刪除高度樣式即可。
挑戰(zhàn)30天在頭條寫日記#
HTML是一種用于創(chuàng)建網(wǎng)頁結構和內(nèi)容的標記語言,其中包含了許多標簽,可以用于排版、布局和展示內(nèi)容。本文將詳細介紹HTML中的<tr>和<td>標簽的使用方法,并通過示例展示如何創(chuàng)建表格。
1. <tr>標簽的作用: <tr>標簽代表HTML表格中的一行(行數(shù)據(jù)),它可以包含一個或多個<td>元素作為單元格。
2. <td>標簽的作用: <td>標簽用于定義表格中的一個單元格(列數(shù)據(jù)),可以包含文本、圖像、鏈接等內(nèi)容。
3. 如何使用<tr>和<td>: 在使用<tr>和<td>標簽時,首先需要創(chuàng)建一個<table>元素作為表格的容器,然后在其中嵌套<tr>和<td>標簽,如下所示:
htmlCopy code<table>
<tr>
<td>單元格1</td>
<td>單元格2</td>
</tr>
<tr>
<td>單元格3</td>
<td>單元格4</td>
</tr>
</table>
4. 表格樣式: 可以使用CSS來為表格添加樣式,如設置邊框、背景顏色等。以下是一個簡單的示例:
htmlCopy code<style>
table {
border-collapse: collapse;
width: 100%;
}
td {
border: 1px solid black;
padding: 8px;
text-align: center;
}
</style>
5. 示例應用: 以下示例演示了如何使用<tr>和<td>標簽創(chuàng)建一個包含姓名、年齡和城市的簡單表格:
htmlCopy code<!DOCTYPE html>
<html>
<head>
<style>
table {
border-collapse: collapse;
width: 100%;
}
td {
border: 1px solid black;
padding: 8px;
text-align: center;
}
</style>
</head>
<body>
<table>
<tr>
<td>姓名</td>
<td>年齡</td>
<td>城市</td>
</tr>
<tr>
<td>張三</td>
<td>25</td>
<td>北京</td>
</tr>
<tr>
<td>李四</td>
<td>30</td>
<td>上海</td>
</tr>
<tr>
<td>王五</td>
<td>28</td>
<td>廣州</td>
</tr>
</table>
</body>
</html>
6. 書籍參考:
7. 總結: 通過本文的介紹,我們了解了HTML中<tr>和<td>標簽的基本用法,以及如何創(chuàng)建簡單的表格和添加樣式。使用這些標簽,我們可以輕松地創(chuàng)建具有結構和內(nèi)容的網(wǎng)頁表格,提升頁面的可讀性和可視性。
*請認真填寫需求信息,我們會在24小時內(nèi)與您取得聯(lián)系。