css設置背景圖片大小_如何使用CSS設置背景圖片大小?

css設置背景圖片大小

Introduction:

介紹:

As we all know that the images are a very responsive yet very creative way to display your web page or website to the users. The images also play a major role in indulging users to websites or web pages. The images are a very smart way to represent any piece of information through colors and art.

眾所周知,圖像是一種向用戶顯示您的網頁或網站的響應Swift但非常有創意的方式。 這些圖像在吸引用戶訪問網站或網頁方面也起著重要作用。 圖像是一種非常聰明的方式,可以通過顏色和藝術品來表示任何信息。

Now that we know the importance and necessity of the images, why don’t we think about the topic at hand which is how can we set the background image size using CSS on our website or web page and to answer that curiosity, keep reading!

現在我們知道了圖像的重要性和必要性,為什么不考慮手頭的話題,那就是我們如何才能在我們的網站或網頁上使用CSS設置背景圖像的大小,并回答這種好奇心,請繼續閱讀!

Method:

方法:

To set the background image size the background-size property of CSS is used.

要設置背景圖像的大小,使用CSS的background-size屬性。

Syntax:

句法:

    Element{
background-size:auto|length|cover|contain;
}

Values:

值:

Now that we have a basic idea of this property and how it helps in resizing the image on our website or web page, so let us keep moving forward in this article and get to know about the different values about this property.

現在,我們已經對該屬性有了基本的了解,以及它如何幫助調整網站或網頁上圖像的大小,因此讓我們在本文中繼續前進,并了解該屬性的不同值。

This property contains 4 values to the background-size property and is listed below,

該屬性包含background-size屬性的4個值,并在下面列出,

  1. auto

    汽車

  2. length

    長度

  3. cover

  4. contain

    包含

Let us discuss these properties one by one.

讓我們一一討論這些屬性。

1)背景大小:自動 (1) background-size:auto)

The auto value of the background-size property is useful to display the original size of the image in terms of length and width. It is also the default value.

background-size屬性的auto值對于顯示圖像的原始大小(長度和寬度)很有用。 也是默認值。

Syntax:

句法:

    Element{
background-size:auto;
}

Example:

例:

<!DOCTYPE html>
<html>
<head>
<style>
div {
padding: 25px;
background: url(img_forest.jpg);
background-repeat: no-repeat;
background-size: auto;
color: #fff;
}
</style>
</head>
<body>
<h1> Background image size</h1>
<div>
<h2>Hello World</h2>
</div>
</body>
</html>

Output

輸出量

CSS | set background image size | Example 1

In the above example, auto property value is used.

在上面的示例中,使用了自動屬性值。

2)background-size:length (2) background-size:length)

The length value of the background-size property is useful to display the width and height of the image by the user’s choice. The first value is used to set the width and the second is used to set the height of the image.

background-size屬性的length值可用于根據用戶的選擇顯示圖像的寬度和高度。 第一個值用于設置寬度,第二個值用于設置圖像的高度。

Note: If only one value is given, the second is set to auto by default.

注意 :如果僅給出一個值,則默認情況下將第二個設置為auto。

Syntax:

句法:

    Element{
background-size:width height;
}

Example:

例:

<!DOCTYPE html>
<html>
<head>
<style>
div {
padding: 25px;
background: url(img_forest.jpg);
background-repeat: no-repeat;
background-size: 600px 200px;
color: #fff;
}
</style>
</head>
<body>
<h1> Background image size</h1>
<div>
<h2>Hello World</h2>
</div>
</body>
</html>

Output

輸出量

CSS | set background image size | Example 2

In the above example, the width and length of the image are defined.

在上面的示例中,定義了圖像的寬度和長度 。

3)background-size:cover (3) background-size:cover)

The cover value of the background-size property is useful to resize the original size of the image in terms of length and width to cover the entire container. It can also stretch or cut the image to cover the entire container if needed.

background-size屬性的cover值對于調整圖像的原始大小的長度和寬度非常有用,以覆蓋整個容器。 如果需要,它也可以拉伸或剪切圖像以覆蓋整個容器。

Syntax:

句法:

    Element{
background-size:cover;
}

Example:

例:

<!DOCTYPE html>
<html>
<head>
<style>
div {
padding: 25px;
background: url(img_forest.jpg);
background-repeat: no-repeat;
background-size: cover;
color: #fff;
}
</style>
</head>
<body>
<h1> Background image size</h1>
<div>
<h2>Hello World</h2>
</div>
</body>
</html>

Output

輸出量

CSS | set background image size | Example 3

In the above example, the image is cut to fit the container.

在上面的示例中,圖像被裁剪以適合容器。

4)背景尺寸:包含 (4) background-size:contain)

The contain value of the background-size property is useful to resize the original size of the image in terms of length and width to make sure the image is fully visible to the user.

background-size屬性的contain值可用于根據長度和寬度調整圖像的原始大小,以確保用戶完全可見該圖像。

Syntax:

句法:

    Element{
background-size:contain;
}

Example:

例:

<!DOCTYPE html>
<html>
<head>
<style>
div {
padding: 25px;
background: url(img_forest.jpg);
background-repeat: no-repeat;
background-size: contain;
color: #fff;
}
</style>
</head>
<body>
<h1> Background image size</h1>
<div>
<h2>Hello World</h2>
</div>
</body>
</html>

Output

輸出量

CSS | set background image size | Example 4

In the above example, the image is fully visible to the user with the help of background-size: contain.

在上面的示例中,借助background-size:contains ,用戶可以完全看到圖像。

翻譯自: https://www.includehelp.com/code-snippets/how-to-set-background-image-size-using-css.aspx

css設置背景圖片大小

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

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

相關文章

java gc的特性_Java12新特性 -- 可中斷的G1 Mixed GC

Java 12 中增強了 G1 垃圾收集器關于混合收集集合的處理策略&#xff0c;這節主要介紹在 Java 12 中同時也對 G1垃圾回收器進行了改進&#xff0c;使其能夠在空閑時自動將 Java 堆內存返還給操作系統&#xff0c;這也是 Java 12 中的另外一項重大改進。目前 Java 11 版本中包含…

在Python3中將字符串轉換為字節的最佳方法

To convert a string to bytes, there are more than one way, 要將字符串轉換為字節&#xff0c;有多種方法&#xff0c; Approach 1: use encode() method 方法1&#xff1a;使用encode()方法 test_str "include_help"print(type(test_str))test_bytes test_st…

【Java】PMD規則學習(1) --字符串比較

PMD是一款采用BSD協議發布的Java程序代碼檢查工具。該工具可以做到檢查Java代碼中是否含有未使用的變量、是否含有空的抓取塊、是否含有不必要的對象等。該軟件功能強大&#xff0c;掃描效率高&#xff0c;是Java程序員debug的好幫手。 PMD支持的編輯器包括&#xff1a;JDevelo…

php定義object數據類型,PHP數據類型(4):對象object

//創建一個類class Student{//定義屬性public $name XuGZh;public $age 20;public $sex 男;//定義方法public function getInfo(){//當前對象中訪問自己屬性用偽變量$thisreturn my name:.$this->name..my age:.$this->age..my sex:.$this->sex;}}對象初始化:要創建…

avr計數_使用8位LCD創建計數器| AVR

avr計數This type of counter may be also used in the EVM machines. A counter can be used to count the number of times a button is pressed. It can have many applications. The most widely used counter application is in EVM and also in customer feedback machin…

php將字符變為數字,數字字符怎么轉化為數字 php 怎么將字符轉成數字

java中&#xff0c;String字符串轉化為數字我現在想把一個String字符串轉化為數字&#xff0c; String s"00000123" 我直接使java中String字符串轉化為數字&#xff1a; 轉換為浮點型&#xff1a; 使用Double或者Float的parseDouble或者parseFloat方法進行轉換 Strin…

用U盤作為啟動盤做系統步驟

步驟一&#xff1a;BIOS設置U盤啟動 制作好Win10 U盤系統安裝盤之后&#xff0c;我們需要在電腦的BIOS設置中把第一啟動設備設置為U盤&#xff0c;設置后就可以從我們制作的Win10 U盤系統安裝盤啟動&#xff0c;從而顯示系統安裝界面開始安裝系統。BIOS設置U盤啟動的方法如下&a…

使用tkinter模塊在Python中進行GUI編程

GUI (Graphical User Interface): GUI(圖形用戶界面)&#xff1a; GUI is a simple application which helps the user to interact with the computer or any other electronic device through a graphical icon. This used to perform different tasks on a desktop or lapt…

php輕博客社區視頻教程,輕博客主題 - SEO極致優化的ZBLOG輕博客主題

zblog自適應輕博客主題&#xff0c;簡潔、輕巧、極致優化~QQ群&#xff1a;457320274 (問題反饋以及其他鏈接交換等) 交流社區&#xff1a;https://www.bxiu.net/ (有問題可以求助交流)更新記錄&#xff1a;2021.02.22 v2.8 更新內容&#xff1a;1、新增分類自定義標題&#xf…

Composer學習之————Ubuntu14.04下安裝Composer

下載Composer&#xff1a; curl -sS https://getcomposer.org/installer | php 安裝Composer&#xff1a; /usr/bin/php composer.phar --version 設置全局命令&#xff1a; sudo mv composer.phar /usr/local/bin/composer 查看是否安裝與設置成功&#xff1a; composer -vers…

u盤啟動iso 開源_啟動和維護開源項目

u盤啟動iso 開源Lets talk about how to start an open-source project? The process can be classified as in three phases, 讓我們談談如何啟動一個開源項目&#xff1f; 該過程可以分為三個階段&#xff0c; Individual senses the need of the project: This is the pha…

java如何解決高并發癥,JAVA線上故障緊急處理詳細過程!

鏈接&#xff1a;https://fredal.xin/java-error-check?hmsrtoutiao.io&utm_mediumtoutiao.io&utm_sourcetoutiao.io線上故障主要會包括 CPU、磁盤、內存以及網絡問題&#xff0c;而大多數故障可能會包含不止一個層面的問題&#xff0c;所以進行排查時候盡量四個方面依…

程序員如何談加薪?

如果你對現在公司很滿意&#xff0c;只是覺得薪資太低&#xff0c;那么可以先和你的主管聊聊。 首先&#xff0c;講一講自己最近在工作上的成長&#xff0c;看主管是否認同&#xff1b; 然后&#xff0c;從能力提升角度&#xff0c;向主管要一個更大的發展空間和更大的業務挑戰…

php有多少魔術方法,PHP常用的幾個魔術方法

常用的魔術方法有&#xff1a;__Tostring () __Call() __autoLoad() __ clone() __GET() __SET() __isset() __unset()1.__Tostring()用于定義輸出對象引用時調用常用于打印一些對象的信息必須有返回值eg&#xff1a;有一個persion類Persion per new persion()Echo per; //直接…

python常用語法和示例_使用Python中的示例進行輸入和輸出操作

python常用語法和示例A Program needs to interact with the user to accomplish the desired task; this is done using Input-Output facility. Input means the data entered by the user of the program. In python, we have input() and raw_input ( ) function available…

關于node.js和npm 和nvm_byKL

關于node.js和npm 和nvm Node 是一個服務器端 JavaScript 解釋器&#xff0c;Node 本身運行 V8 JavaScript。V8 JavaScript 引擎是 Google 用于其 Chrome 瀏覽器的底層 JavaScript 引擎。 NPM是隨同NodeJS一起安裝的包管理工具&#xff0c;能解決NodeJS代碼部署上的很多問題&am…

php 查看擴展 代碼,[擴展推薦] 使用 PHP Insights 在終端查看 PHP 項目代碼質量

PHP Insights 是一個由 Nuno Maduro 發布的、可在控制臺進行 PHP 即時質量檢查的拓展包。在項目的 readme 文件中&#xff0c;可以發現 PHP Insights 的主要功能包含&#xff1a;代碼質量 與 代碼風格 分析一個針對于代碼 結構 和 復雜度 的漂亮的預覽界面在 Laravel、Symfon…

航空機票預訂c#代碼_航空公司座位預訂問題的C ++程序

航空機票預訂c#代碼Problem statement: Write a program to assign passengers seats in an airplane. Assume a small airplane with seat numbering as follows: 問題陳述&#xff1a;編寫一個程序來分配飛機上的乘客座位。 假設小型飛機的座位編號如下&#xff1a; 1 A B C…

linux命令之which

which這個命令可以說并不常用&#xff0c;它的作用是查看可執行文件的位置&#xff0c;并返回第一個搜索結果。可執行文件也就是指的某個系統命令&#xff0c;但是這個命令的位置必須是在PATH路徑里存在的。截圖中 &#xff0c;pwd的位置在/bin/pwd,當然&#xff0c;這個路徑是…

線性代數向量乘法_向量的標量乘法| 使用Python的線性代數

線性代數向量乘法Prerequisite: Linear Algebra | Defining a Vector 先決條件&#xff1a; 線性代數| 定義向量 Linear algebra is the branch of mathematics concerning linear equations by using vector spaces and through matrices. In other words, a vector is a mat…