给⽹页添加背景图⽚html_如何使⽤HTML将背景图像添加到⽹
页的顶部
给⽹页添加背景图⽚html
This tutorial series will guide you through creating and further customizing 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 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 <div> container to structure the top section of the webpage. We will use the style attribute to specify the height of our <div> container, apply a background image, and specify that the background image should cover the entire area of the <div> container.
在本教程中,我们将学习如何使⽤<div>容器来构造⽹页的顶部。 我们将使⽤style属性指定<div>容器的⾼度,应⽤背景图像,并指定背景图像应覆盖<div>容器的整个区域。
文件损坏怎么修复Before we get started, we’ll need a background image. You may download and use our demonstration site’s 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 from earlier in this tutorial series).
在开始之前,我们需要背景图⽚。 您可以下载并使⽤我们的演⽰站点的来完成本教程,也可以选择⼀个新图像。 (有关如何使⽤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 <body> tag and above the closing </body>:
接下来,将突出显⽰的代码段粘贴到您的index.html⽂件中,该标记在<body>标记下⽅和</body>上⽅:
梦见已故的同事. . .
<body>
<!--First section-->
<div style="background-image: url('Image_Location'); background-size: cover;; height:540px;
</div>
</body>
</html>
Make sure to switch the text that says Image_Location with the file path of your image and don’t forg
et to add the closing </div> tag.
确保⽤图⽚的⽂件路径切换表⽰Image_Location的⽂本,并且不要忘记添加结束</div>标记。冒险岛弓箭手武器
Note that we have added the comment <!--First section--> to help organize our HTML code. A comment is a piece of code that is ignored by the browser. Comments are used to help explain or organize code to developers. They are created with the opening tag <!-- and the closing tag -->.
请注意,我们添加了注释<!--First section-->以帮助组织HTML代码。 注释是浏览器会忽略的⼀段代码。 注释⽤于帮助向开发⼈员解释或组织代码。 它们是⽤开始标记<!--和结束标记--> 。
很冷Save the file and reload it in the browser. You should receive something like this:
保存⽂件并将其重新加载到浏览器中。 您应该会收到以下信息:
Alternately, you can use a background color instead of a background image. To use a background color, replace the <div> element code snippet you just created with the following highlighted <div> element code snippet like this:
或者,您可以使⽤背景⾊代替背景图像。 要使⽤的背景颜⾊,更换<div>元素的代码段,您只需⽤以下突出显⽰创建<div>元素的代码⽚段是这样的:
...
<body>
<div >
</div>
</body>
电子医保卡怎么激活使用</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 <div> container on your site with the same <div> container on the , you may notice that your webpage’s <div> 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.
如果⽐较<div>与同⼀⽹站上的容器<div>在容器 ,你可能会注意到你的⽹页的<div>容器是由⽩⾊空间⼩幅度的包围。 此裕度是由于以下事实:默认情况下,所有HTML页⾯均⾃动设置为较⼩的裕度。
To remove this margin, we need to add a style attribute to the opening <body> tag that sets the margin of the <body> element of the HTML page to 0 pixels. Locate the opening <body> in your index.html file and modify it with the highlighted code:
要删除此空⽩,我们需要在开始的<body>标记中添加⼀个style属性,以将HTML页⾯的<body>元素的空⽩设置为0像素。 在index.html⽂件中到开头的<body> ,并使⽤突出显⽰的代码对其进⾏修改:
<body style=“margin:0;”>
<body style =“ margin:0;” >
Save and reload the file in your browser. There should now be no white margin surrounding the top <div> container.
在浏览器中保存并重新加载⽂件。 现在,顶部<div>容器周围应该没有⽩边。
You should now know how to add a <div> container with a background image to structure the top section of a webpage.
现在,您应该知道如何添加带有背景图像的<div>容器来构造⽹页的顶部。
给⽹页添加背景图⽚html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论