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.mzph.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…