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