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)奠定坚实的基础。

HTML attributes can be used to change the color, size, and other features of HTML elements. For example, you can use an attribute to change the color or size of a font for a text element or the width and height for an image element. In this tutorial, we’ll learn how to use HTML attributes to set values for the size and color properties of HTML text elements.

HTML 属性可用于更改HTML元素的颜色,大小和其他功能。 例如,您可以使用属性来更改文本元素的字体的颜色或大小,或图像元素的宽度和高度。 在本教程中,我们将学习如何使用HTML属性设置HTML文本元素的大小和颜色属性的值。

An HTML attribute is placed in the opening tag like this:

将HTML属性放置在开始标记中,如下所示:

<element attribute=”property:value;”>

One common attribute is style, which allows you to add style properties to an HTML element. While it’s more common to use a separate stylesheet to determine the style of an HTML document, we will use the style attribute in our HTML document for this tutorial.

一个常见的属性是style ,它允许您将样式属性添加到HTML元素。 虽然通常使用单独的样式表来确定HTML文档的样式,但在本教程中,我们将使用HTML文档中的style属性。

使用样式属性 (Using the Style Attribute)

We can change multiple properties of an <h1> element with the style attribute. Clear your “index.html” file and paste the code below into your browser. (If you have not been following the tutorial series, you can review instructions for setting up an index.html file in our tutorial Setting Up Your HTML Project.

我们可以使用style属性更改<h1>元素的多个属性。 清除“ index.html”文件,然后将以下代码粘贴到浏览器中。 (如果您还没有按照教程系列进行操作,则可以在我们的教程设置HTML项目中查看有关设置index.html文件的说明。

<h1 style=”font-size:40px;color:green;”> This text is 40 pixels and green.</h1>

Before we load the file in our browser, let’s review each of the parts of this HTML element:

在将文件加载到浏览器中之前,让我们回顾一下此HTML元素的每个部分:

  • h1 is the name of the tag. It refers to the largest-sized Heading element.

    h1是标签的名称。 它是指最大的标题元素。

  • style is the attribute. This attribute can take a variety of different properties.

    style是属性。 此属性可以采用各种不同的属性。

  • font-size is the first property we’re setting for the style attribute.

    font-size是我们为style属性设置的第一个属性。

  • 40px; is the value for the property font-size, which sets the text content of the element to 40 pixels.

    40px;font-size属性的值,该属性将元素的文本内容设置为40像素。

  • color is the second property we’re setting for the style attribute.

    color是我们为style属性设置的第二个属性。

  • green is the value for the property color, which sets the text content color to green

    green是属性color的值,它将文本内容颜色设置为绿色

Note that the properties and values are contained by quotation marks, and that each property:value pair ends with a semicolon ;.

请注意,属性和值包含在引号中,并且每个property:value对均以分号结尾;

Save the file and reload it in your browser. (For instructions on loading the file in your browser, see our tutorial here.) You should receive something like this:

保存文件并将其重新加载到浏览器中。 (有关在浏览器中加载文件的说明,请参见此处教程 。)您应该收到类似以下内容的信息:

此文本为40像素,为绿色。 ( This text is 40 pixels and green. )

You have now learned how to use the style attribute to change the font size and font color of a text element. Note that certain elements require attributes, such as the <a> element which allows you to add a link to a text or image, and the <img> element, which allows you to add an image to the document. We’ll cover those two elements in the next tutorials and learn about additional attribute usage for <div> containers and other HTML elements later on in the tutorial series.

您现在已经了解了如何使用style属性来更改文本元素的字体大小和字体颜色。 请注意,某些元素需要属性,例如<a>元素(允许您添加到文本或图像的链接)和<img>元素(允许您将图像添加到文档)。 我们将在接下来的教程中介绍这两个元素,并在本系列教程后面的部分中了解<div>容器的其他属性用法以及其他HTML元素。

翻译自: https://www.digitalocean.com/community/tutorials/how-to-use-html-attributes

html 属性中使用变量

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值