日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > CSS >内容正文

CSS

background的用法css,关于CSSbackground的使用方法

發布時間:2024/9/27 CSS 216 豆豆
生活随笔 收集整理的這篇文章主要介紹了 background的用法css,关于CSSbackground的使用方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

下面為大家帶來一篇CSS background全部匯總。內容挺不錯的,現在就分享給大家,也給大家做個參考。

所有背景屬性都不能繼承。

1. background-color

所有元素都能設置背景顏色。

background-color的默認值是transparent;也就是說,如果一個元素沒有指定背景顏色,那么背景就是透明的,這樣其祖先元素的背景才能可見。

2. background-image

所有元素都能設置背景圖像;

背景圖像可以設置多個,中間用逗號隔開;背景圖像會層疊,寫在前面的層次在上面。

3. background-repeat

repeat(默認)/no-repeat/repeat-x/ repeat-y

4. background-attachment

scroll(默認)/fixed

5. background-position

像素法:以圖像左上角為起點,第一個值為水平移動的距離,第二個值為垂直移動的距離;若只規定一個值,第二個值默認為50%。

百分比法:百分比同時應用于圖像和元素,相應的點重合進行定位。如果只指定一個百分數,意味著垂直方向為50%。

關鍵字法:top、right、bottom、left、center進行組合定位;若只規定一個值,第二個值默認為center。

注意:background-position可以為負值。

在默認情況下,背景顏色延伸到邊框下面,背景圖像在padding區域的左上角。

6. background-size

設置背景圖像的尺寸;默認值為auto。

像素法:第一個值設置寬度,第二個值設置高度;若只有一個值,第二個值為auto。

百分比法:以父元素的寬度和高度以基準來計算。

關鍵字cover,不改變圖像寬高比例,在水平和垂直方向都鋪滿整個元素,有可能導致一部分圖像溢出。

關鍵字contain,不改變圖像寬高比例,盡可能拉伸,直到某一方向鋪滿整個元素,有可能導致另一方向沒有鋪滿。

7. background-origin

定義背景圖像的初始位置

border-box,邊框左上角。

padding-box,padding區域左上角;默認值。

content-box,內容區左上角。

8. background-clip

The CSS3 background-clip property specifies the painting area of the background.

The property takes three different values:

?border-box - (default) the background is painted to the outside edge of the border

?padding-box - the background is painted to the outside edge of the padding

?content-box - the background is painted within the content box

(英文的解釋得比較清楚)

(英文都是從W3Schools Online搬運)

關于background-origin和background-clip,它們是相互獨立的,互不干擾。

關于background的CSS寫法,個人認為應該邏輯明確、層次分明;具體而言:

background定義背景圖像,background-color定義背景顏色,background-clip定義背景顯示區域。

(個人見解,僅供參考)

Full Size Background Image

If we want to have a background image on a website that covers the entire browser window at all times.

The requirements are as follows:

? Fill the entire page with the image (no white space)

? Scale image as needed

? Center image on page

? Do not cause scrollbars

The following example shows how to do it; Use the html element (the html element is always at least the height of the browser window). Then set a fixed and centered background on it. Then adjust its size with the background-size property:html {

background: url(img_flower.jpg) no-repeat center fixed;

background-size: cover;

}

小tips:

利用背景圖像的水平平鋪,實現波浪式的邊框效果。

(目前只有想法,還沒找到符合需求的圖像。)

以上就是本文的全部內容,希望對大家的學習有所幫助,更多相關內容請關注PHP中文網!

相關推薦:

關于CSS3開啟硬件加速的使用和陷阱

關于CSS代碼如何書寫規范

總結

以上是生活随笔為你收集整理的background的用法css,关于CSSbackground的使用方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。