css背景圖片添加url_CSS背景圖片–如何向您的Div添加圖片URL

css背景圖片添加url

Say you want to put an image or two on a webpage. One way is to use the background-image CSS property.

假設您要在網頁上放置一兩個圖片。 一種方法是使用background-image CSS屬性。

This property applies one or more background images to an element, like a <div>, as the documentation explains. Use it for aesthetic reasons, such as adding a textured background to your webpage.

如文檔所述此屬性將一個或多個背景圖像應用于元素,例如<div> 。 出于美學原因使用它,例如在網頁上添加帶紋理的背景。

添加圖像 (Add an Image)

It’s easy to add an image using the background-image property. Just provide the path to the image in the url() value.

使用background-image屬性添加圖像很容易。 只需在url()值中提供圖像的路徑即可。

The image path can be a URL, as shown in the example below:

圖像路徑可以是URL,如下例所示:

div {/* Background pattern from Toptal Subtle Patterns */background-image: url("https://amymhaddad.s3.amazonaws.com/morocco-blue.png");height: 400px;width: 100%;
}

Or it can be a local path. Here’s an example:

也可以是本地路徑。 這是一個例子:

body {/* Background pattern from Toptal Subtle Patterns */height: 400px;width: 100%;background-image: url("./images/oriental-tiles.png");
}

添加多個圖像 (Add Multiple Images)

You can apply multiple images to the background-image property.

您可以將多個圖像應用于background-image屬性。

div {
/* Background pattern from Toptal Subtle Patterns */height: 400px;width: 100%;background-image: url("https://amymhaddad.s3.amazonaws.com/morocco-blue.png"),url("https://amymhaddad.s3.amazonaws.com/oriental-tiles.png");background-repeat: no-repeat, no-repeat;background-position: right, left; 
}

That’s a lot of code. Let’s break it down.

那是很多代碼。 讓我們分解一下。

Separate each image url() value with a comma.

用逗號分隔每個圖像的url()值。

background-image: url("https://amymhaddad.s3.amazonaws.com/morocco-blue.png"),url("https://amymhaddad.s3.amazonaws.com/oriental-tiles.png");

Now position and enhance your images by applying additional properties.

現在,通過應用其他屬性來定位和增強圖像。

background-repeat: no-repeat, no-repeat;
background-position: right, left;

There are several sub-properties you can add to your background images, such as background-repeat and background-position, which we used in the above example. You can even add gradients to a background image.

您可以將幾個子屬性添加到背景圖像中,例如在上例中使用的background-repeatbackground-position 。 您甚至可以將漸變添加到背景圖像。

See what it looks like when we put everything together.

當我們將所有內容放在一起時,看看是什么樣子。

訂單事項 (Order Matters)

The order that you list your images in matters because of the stacking order. That means the first image listed is nearest to the user, according to the documentation. Then, the next one, and the next, and so on.

由于堆疊順序,您列出圖像的順序很重要。 根據文檔 ,這意味著列出的第一張圖像離用戶最近。 然后,下一個,下一個,依此類推。

Here’s an example.

這是一個例子。

div {
/* Background pattern from Toptal Subtle Patterns */height: 400px;width: 100%;background-image: url("https://amymhaddad.s3.amazonaws.com/morocco-blue.png"),url("https://amymhaddad.s3.amazonaws.com/oriental-tiles.png");background-repeat: no-repeat, no-repeat;
}

We’ve listed two images in the code above. The first image (morocco-blue.png) will be in front of the second (oriental-tiles.png). Both images are the same size and lack opacity, so we only see the first image.

我們在上面的代碼中列出了兩張圖片。 第一張圖片(morocco-blue.png)將位于第二張圖片(oriental-tiles.png)的前面。 兩張圖片的大小相同,并且不透明,因此我們只能看到第一張圖片。

But if we move the second image (oriental-tiles.png) over to the right by 200 pixels, then you can see part of it (the rest remains hidden).

但是,如果我們將第二個圖像(oriental-tiles.png)向右移動200像素,那么您可以看到其中的一部分(其余部分保持隱藏狀態)。

Here’s what it looks like when we put everything together.

這是我們將所有內容放在一起時的樣子。

什么時候應該使用背景圖片? (When Should You Use Background Image?)

There’s a lot to like about the background-image property. But there’s a drawback.

關于background-image屬性,有很多喜歡的地方。 但是有一個缺點。

The image may not be accessible to all users, the documentation points out, like those who use screen readers.

該文檔指出,并非所有用戶都可以訪問該圖像,就像使用屏幕閱讀器的用戶一樣。

That’s because you can’t add textual information to the background-image property. As a result, the image will be missed by screen readers.

這是因為您無法將文本信息添加到background-image屬性。 結果,屏幕閱讀器會遺漏圖像。

Use the background-image property only when you need to add some decoration to your page. Otherwise, use the HTML <img> element if an image has meaning or purpose, as the documentation notes.

僅當需要在頁面上添加裝飾時,才使用background-image屬性。 否則,如文檔所述,如果圖像具有含義或目的,請使用HTML <img>元素。

That way, you can add text to an image element, using the alt attribute, which describes the image. The provided text will be picked up by screen readers.

這樣,您可以使用alt屬性(它描述圖像)將文本添加到圖像元素。 屏幕閱讀器將提取提供的文本。

<img class="house" src="./images/farnsworth_house.jpeg"alt="A glass house designed by Ludwig Mies van der Rohe located in Plano, Illinois.">

Think of it this way: background-image is a CSS property, and CSS focuses on presentation or style; HTML focuses on semantics or meaning.

這樣想: background-image是一個CSS屬性,而CSS專注于表示形式或樣式; HTML專注于語義或含義。

When it comes to images, you’ve got options. If an image is needed for decoration, then the background-image property may be a good choice for you.

對于圖像,您可以選擇。 如果需要裝飾圖像,那么background-image屬性可能是您的理想選擇。

I write about learning to program and the best ways to go about it (amymhaddad.com).

我寫了有關學習編程和實現它的最佳方法的文章( amymhaddad.com )。

翻譯自: https://www.freecodecamp.org/news/how-to-add-an-image-url-to-your-div/

css背景圖片添加url

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/390397.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/390397.shtml
英文地址,請注明出處:http://en.pswp.cn/news/390397.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

golang基礎01

1.環境變量&#xff1a;go env//代碼目錄和第三方庫文件set GOPATHC:\Users\hanxiaodong\go//go安裝目錄set GOROOTC:\Gopath里要配置&#xff1a;goroot/bin;和gopath/bin; gopath目錄下三個文件夾&#xff1a;pkg&#xff1a;編譯好的庫文件 .a 文件bin&#xff1a;可執行文件…

hugo 能做web開發嗎_如何自托管Hugo Web應用

hugo 能做web開發嗎After hosting with Netlify for a few years, I decided to head back to self hosting. There are a few reasons for that, but the main reasoning was that I had more control over how things worked. 在Netlify托管了幾年之后&#xff0c;我決定回到…

資源 | 深度學習課程入門與介紹

【1】Andrew NG Deep Learning.ai http://deeplearning.ai/網易云課堂&#xff08;中文字幕&#xff09;&#xff1a;http://mooc.study.163.com/smartSpec/detail/1001319001.htm推薦理由&#xff1a;Andrew Ng老師是講課的能手&#xff0c;很多人認識他是從Stanford的經典《機…

PostCSS 以及 cssnext語法

本文是對近兩天學習postcss的總結&#xff0c;在這里分享給大家。 如有錯誤&#xff0c;還請指正&#xff01; 什么是postcss postcss 一種對css編譯的工具&#xff0c;類似babel對js的處理&#xff0c;常見的功能如&#xff1a; 1 . 使用下一代css語法 2 . 自動補全瀏覽器前綴…

5187. 收集足夠蘋果的最小花園周長

給你一個用無限二維網格表示的花園&#xff0c;每一個 整數坐標處都有一棵蘋果樹。整數坐標 (i, j) 處的蘋果樹有 |i| |j| 個蘋果。 你將會買下正中心坐標是 (0, 0) 的一塊 正方形土地 &#xff0c;且每條邊都與兩條坐標軸之一平行。 給你一個整數 neededApples &#xff0c…

虛擬機 VMware Workstation12 安裝OS X 系統

Windows下虛擬機安裝Mac OS X —– VMware Workstation12安裝Mac OS X 10.11本文即將介紹WIN虛擬MAC的教程。完整詳細教程&#xff08;包含安裝中的一些問題&#xff09;【并且適用其他mac os x版本】Windows下 VM12虛擬機安裝OS X 10.11(詳細教程) 工具/原料 Mac OS X 10.11 鏡…

aws dynamodb_DynamoDB備忘單–您需要了解的有關2020 AWS認證開發人員助理認證的Amazon Dynamo DB的所有信息

aws dynamodbThe emergence of cloud services has changed the way we build web-applications. This in turn has changed the responsibilities of a Web Developer. 云服務的出現改變了我們構建Web應用程序的方式。 反過來&#xff0c;這改變了Web開發人員的職責。 We use…

北大CIO走進龍泉寺交流研討會圓滿舉行

緣起 2016年4月16日&#xff0c;北京大學信息化與信息管理研究中心秘書長姚樂博士與國家非物質文化遺產蔚縣剪紙傳承人周淑英女士一起在龍泉寺拜見了中國佛教協會會長、龍泉寺主持學誠法師。在拜見學誠法師時&#xff0c;姚樂博士與學誠法師聊到了“賢二機器僧”和人工智能。姚…

負載均衡種類

http://blog.csdn.net/zhoudaxia/article/details/23672319DNS DNS輪詢是最簡單的負載均衡方式。以域名作為訪問入口&#xff0c;通過配置多條DNS A記錄使得請求可以分配到不同的服務器。DNS輪詢沒有快速的健康檢查機制&#xff0c;而且只支持WRR的調度策略導致負載很難“均衡”…

代碼流星雨是什么形式_為什么要在2020年與流星合作

代碼流星雨是什么形式Meteor, an allegedly dead development platform, is still alive and can bring massive value to your everyday coding experience.Meteor&#xff0c;據稱已失效的開發平臺&#xff0c;仍然有效&#xff0c;可以為您的日常編碼體驗帶來巨大的價值。 …

Centos7 Docker私有倉庫搭建

Centos7 Docker私有倉庫搭建 倉庫&#xff1a;集中存放鏡像的地方&#xff0c;可分為公共倉庫和私有倉庫&#xff08;公共倉庫"http://hub.docker.com"或國內的"http://www.daocloud.io"&#xff09; Registry&#xff1a;注冊服務器才是存放倉庫具體的服務…

MySQL觸發器使用詳解

MySQL包含對觸發器的支持。觸發器是一種與表操作有關的數據庫對象&#xff0c;當觸發器所在表上出現指定事件時&#xff0c;將調用該對象&#xff0c;即表的操作事件觸發表上的觸發器的執行。 創建觸發器在MySQL中&#xff0c;創建觸發器語法如下&#xff1a; 代碼如下: CREATE…

java中訪問修飾符_Java中的訪問修飾符介紹

java中訪問修飾符什么是訪問修飾符&#xff1f; (What are Access Modifiers?) Have you ever wanted to define how people would access some of your properties? You would not want anyone using your underwear. However, your close friends and relatives can use yo…

VIM 編輯器

2019獨角獸企業重金招聘Python工程師標準>>> VIM 相對于VI 的提升 VIM 支持多級撤銷VIM 可以跨平臺運行VIM 支持語法高亮VIM 支持圖形界面VIM 編輯器的操作模式 Command Mode -命令模式Insert Mode -輸入模式Last Lin Mode -底行模式#使用yum 命令安裝vim 軟件&…

/etc/profile、/etc/bashrc、~/.bash_profile、~/.bashrc 文件的作用

轉載自&#xff1a;http://blog.csdn.net/u013968345/article/details/21262033 /etc/profile:此文件為系統的每個用戶設置環境信息,當用戶第一次登錄時,該文件被執行. 并從/etc/profile.d目錄的配置文件中搜集shell的設置. /etc/bashrc:為每一個運行bash shell的用戶執行此文件…

python初學者_終極Python初學者手冊

python初學者Python has become one of the fastest-growing programming languages over the past few years. 在過去的幾年中&#xff0c;Python已成為增長最快的編程語言之一。 Not only it is widely used, it is also an awesome language to tackle if you want to get …

z-index

z-index 這個東西非常簡單&#xff0c;它有四大特性&#xff0c;每個特性你記住了&#xff0c;頁面布局就不會出現找不到盒子的情況。 z-index 值表示誰壓著誰&#xff0c;數值大的壓蓋住數值小的&#xff0c;只有定位了的元素&#xff0c;才能有z-index,也就是說&#xff0c;不…

大型運輸行業實戰_day12_1_權限管理實現

1.業務分析 權限說的是不同的用戶對同一個系統有不同訪問權限,其設計的本質是:給先給用戶分配好URL,然后在訪問的時候判斷該用戶是否有當前訪問的URL. 2.實現 2.1數據庫設計標準5表權限結構 2.2.sql語句實現,根據用戶id查詢該用戶所有的資源 sql語句: SELECT ur.user_id, r.u…

aws python庫_如何使用Python,AWS和IEX Cloud創建自動更新股市數據的Excel電子表格

aws python庫Many Python developers in the financial world are tasked with creating Excel documents for analysis by non-technical users.金融界的許多Python開發人員的任務是創建Excel文檔&#xff0c;以供非技術用戶進行分析。 This is actually a lot harder than i…

37)智能指針(就是自動delete空間)

1&#xff09;問題引入&#xff1a; 在java或者在C中&#xff0c;一旦你new一個東西&#xff0c;那么必然有一個delete與之對應&#xff0c;比如&#xff1a; 1 int main&#xff08;&#xff09;2 {3 int* p new int&#xff08;&#xff09;&#xff1b;4 5 *…