给网页添加背景图片html_如何使用HTML将背景图像添加到网页的顶部

给网页添加背景图片html

How To Build a Website With HTML 如何使用HTML构建网站

This tutorial series will guide you through creating and further customizing this website using HTML, the standard markup language used to display documents in a web browser. No prior coding experience is necessary but we recommend you start at the beginning of the series if you wish to recreate the demonstration website.

本教程系列将指导您使用HTML(用于在Web浏览器中显示文档的标准标记语言)创建和进一步自定义此网站 。 不需要任何编码经验,但是如果您希望重新创建演示网站,建议您从本系列的开头开始 。

At the end of this series, you should have a website ready to deploy to the cloud and a basic familiarity with HTML. Knowing how to write HTML will provide a strong foundation for learning additional front-end web development skills, such as CSS and JavaScript.

在本系列的最后,您应该拥有一个可以部署到云的网站,并且对HTML有了基本的了解。 知道如何编写HTML将为学习其他前端Web开发技能(例如CSS和JavaScript)奠定坚实的基础。

In this tutorial we’ll learn how to use a

container to structure the top section of the webpage. We will use the style attribute to specify the height of our
container, apply a background image, and specify that the background image should cover the entire area of the
container.

在本教程中,我们将学习如何使用

容器来构造网页的顶部。 我们将使用style属性指定
容器的高度,应用背景图像,并指定背景图像应覆盖
容器的整个区域。

Before we get started, we’ll need a background image. You may download and use our demonstration site’s background image for the purpose of the tutorial, or you can choose a new image. (For a refresher on how to add images to webpages using HTML, please visit our tutorial HTML Images from earlier in this tutorial series).

在开始之前,我们需要背景图片。 您可以下载并使用我们的演示站点的背景图像来完成本教程,也可以选择一个新图像。 (有关如何使用HTML向网页添加图像的更新,请访问本系列教程前面的HTML图像教程)。

Once you’ve chosen your background image, save the image in your images folder as background-image.jpg.

选择背景图像后,将图像另存为images文件夹中的background-image.jpg

Next, paste the highlighted code snippet into your index.html file below the opening tag and above the closing :

接下来,将突出显示的代码段粘贴到您的index.html文件中,该标记在标记下方和上方:

. . .


...

Save the file and reload it in the browser to check your results. The background image should now be replaced with a container that is the same size but has a solid yellow color.

保存文件,然后将其重新加载到浏览器中以检查结果。 现在应使用大小相同但颜色为黄色的容器替换背景图片。

If you compare the

container on your site with the same
container on the demonstration site, you may notice that your webpage’s
container is surrounded by a small margin of white space. This margin is due to the fact that all HTML pages are automatically set to have a small margin by default.

如果比较

与同一网站上的容器
在容器示范点 ,你可能会注意到你的网页的
容器是由白色空间小幅度的包围。 此裕度是由于以下事实:默认情况下,所有HTML页面均自动设置为较小的裕度。

To remove this margin, we need to add a style attribute to the opening tag that sets the margin of the element of the HTML page to 0 pixels. Locate the opening in your index.html file and modify it with the highlighted code:

要删除此空白,我们需要在开始的标记中添加一个style属性,以将HTML页面的元素的空白设置为0像素。 在index.html文件中找到开头的 ,并使用突出显示的代码对其进行修改:

Save and reload the file in your browser. There should now be no white margin surrounding the top

container.

在浏览器中保存并重新加载文件。 现在,顶部

容器周围应该没有白边。

You should now know how to add a

container with a background image to structure the top section of a webpage.

现在,您应该知道如何添加带有背景图像的

容器来构造网页的顶部。

翻译自: https://www.digitalocean.com/community/tutorials/how-to-add-a-background-image-to-the-top-section-of-your-webpage-with-html

给网页添加背景图片html

你可能感兴趣的:(给网页添加背景图片html_如何使用HTML将背景图像添加到网页的顶部)