iT邦幫忙

2024 iThome 鐵人賽

DAY 19
0

background主要控制元素的背景,可設定顏色、圖片、位置等背景樣式
接下來我們就來介紹一下有哪些背景設定吧~~

  1. background-color設定背景顏色
background-color: lightblue;

https://ithelp.ithome.com.tw/upload/images/20240925/201684683vbhQO69CL.png

  1. background-image設定背景圖片
background-image: url('https://cdn.pixabay.com/photo/2023/04/28/10/03/chapel-7956274_1280.jpg');

https://ithelp.ithome.com.tw/upload/images/20240925/201684684zhj5gS7IX.png
圖片設定透過url將圖片網址加入,background-image: url('background.jpg');,
background.jpg就是你想套用的圖片網址

  1. linear-gradient設定背景漸層
background: linear-gradient(to right, lightblue, lightpink);

https://ithelp.ithome.com.tw/upload/images/20240925/20168468IUIaPlfgJN.png
to right代表從左邊往右呈現漸層,後面兩者則是你想呈現的顏色

  1. background-repeat設定背景圖片是否重複
    如果圖片大小不符合整個視窗,可能就會有重複的問題,那這時候我們就可以使用no-repeat來改善重複的問題,
    background-repeat除了有no-repeat還有repeat-xrepeat-yrepeat
    repeat:背景圖片在水平和垂直方向上重複。
    repeat-x:背景圖片只在水平方向上重複。
    repeat-y:背景圖片只在垂直方向上重複。

  2. background-attachment是否隨著頁面内容的滾動而滾動,或是固定在頁面上
    scroll:背景圖片會隨著頁面內容滾動。
    fixed:背景圖片固定,不隨著頁面滾動。
    local:背景圖片隨元素内容滾動(不過通常用於元素内容可滾動時)。

今天的介紹就先到這啦~~~~/images/emoticon/emoticon41.gif


上一篇
Day18.CSS<align-items>屬性
下一篇
Day20.CSS<position>屬性
系列文
Web前端的探索:30天的驚奇之旅22
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言