您好,登錄后才能下訂單哦!
本篇內(nèi)容主要講解“css怎么設(shè)置導(dǎo)航條背景圖片”,感興趣的朋友不妨來看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“css怎么設(shè)置導(dǎo)航條背景圖片”吧!
在css中,可以利用“background-image”屬性來設(shè)置導(dǎo)航條的背景圖片,該屬性主要用于為元素添加背景圖像,只需要給導(dǎo)航條元素添加“background-image:url(圖片路徑);”樣式即可。
本教程操作環(huán)境:windows7系統(tǒng)、CSS3&&HTML5版、Dell G3電腦。
css如何設(shè)置導(dǎo)航條背景圖片
在css中,可以利用background-image屬性來設(shè)置導(dǎo)航條背景圖片,background-image 屬性為元素設(shè)置背景圖像。
元素的背景占據(jù)了元素的全部尺寸,包括內(nèi)邊距和邊框,但不包括外邊距。
默認(rèn)地,背景圖像位于元素的左上角,并在水平和垂直方向上重復(fù)。
下面我們通過示例來看一下怎樣利用background-image屬性來設(shè)置背景圖片,示例如下:
首先我們創(chuàng)建一個(gè)導(dǎo)航條
<!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>Document</title> <style type="text/css"> *{margin:0;padding: 0;} ul{ list-style-type: none; overflow: hidden; position: fixed; top: 0; width: 100%; } li { float: left; } li a { display: block; color: white; text-align: center; padding: 14px 16px; text-decoration: none; } li a:hover{ background-color: red; } </style> </head> <body> <ul> <li><a href="#home">首頁(yè)</a></li> <li><a href="#news">新聞動(dòng)態(tài)</a></li> <li><a href="#contact">聯(lián)系我們</a></li> <li><a href="#about">關(guān)于我們</a></li> </ul> <div style="background-color:pink;height:1500px;"></div> </body> </html>
輸出結(jié)果:
此時(shí)導(dǎo)航條并沒有背景圖片,只需要給導(dǎo)航條元素添加“background-image:url(圖片路徑);”樣式即可,示例如下:
ul{ list-style-type: none; overflow: hidden; background-image:url(1118.02.png); position: fixed; top: 0; width: 100%; }
輸出結(jié)果:
到此,相信大家對(duì)“css怎么設(shè)置導(dǎo)航條背景圖片”有了更深的了解,不妨來實(shí)際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。