当前位置: 首页 > 编程日记 > 正文

HTML属性说明

HTML elements can have attributes, which contain additional information about the element.

HTML元素可以具有属性,其中包含有关该元素的其他信息。

HTML attributes generally come in name-value pairs, and always go in the opening tag of an element. The attribute name says what type of information you’re providing about the element, and the attribute value is the actual information.

HTML属性通常以名称/值对的形式出现,并且总是放在元素的开始标记中。 属性名称说明您要提供的有关元素的信息类型,而属性值是实际信息。

For example, an anchor (<a>) element in an HTML document creates links to other pages, or other parts of the page. You use the href attribute in the opening <a> tag to tell the browser where the link sends a user.

例如,HTML文档中的锚点( <a> )元素创建到其他页面或页面其他部分的链接。 您可以在开始的<a>标记中使用href属性,以告诉浏览器该链接将用户发送到何处。

Here’s an example of a link that sends users to freeCodeCamp’s home page:

这是将用户发送到freeCodeCamp主页的链接的示例:

<a href="www.freecodecamp.org">Click here to go to freeCodeCamp!</a>

Notice that the attribute name (href) and value (“www.freeCodeCamp.org”) are separated with an equals sign, and quotes surround the value.

请注意,属性名称( href )和值(“ www.freeCodeCamp.org”)用等号分隔,并用引号引起来。

There are many different HTML attributes, but most of them only work on certain HTML elements. For example, the href attribute won’t work if it’s placed in an opening <h1> tag.

HTML有许多不同的属性,但是大多数属性仅适用于某些HTML元素。 例如,如果将href属性放在开头的<h1>标记中,则该属性将不起作用。

In the example above, the value supplied to the href attribute could be any valid link. However, some attributes only have a set of valid options you can use, or values need to be in a specific format. The lang attribute tells the browser the default language of the contents in an HTML element. The values for the lang attribute should use standard language or country codes, such as en for English, or it for Italian.

在上面的示例中,提供给href属性的值可以是任何有效链接。 但是,某些属性只有一组可以使用的有效选项,或者值必须采用特定格式。 lang属性告诉浏览器HTML元素中内容的默认语言。 对于值lang属性应当使用规范的语言或国家代码,如en英语,或者it意大利。

布尔属性 (Boolean Attributes)

Some HTML attributes don’t need a value because they only have one option. These are called Boolean attributes. The presence of the attribute in a tag will apply it to that HTML element. However, it’s okay to write out the attribute name and set it equal to the one option of the value. In this case, the value is usually the same as the attribute name.

一些HTML属性不需要值,因为它们只有一个选项。 这些称为布尔属性。 标签中属性的存在会将其应用于该HTML元素。 但是,可以写出属性名称并将其设置为等于值的一个选项。 在这种情况下,该值通常与属性名称相同。

For example, the <input> element in a form can have a required attribute. This requires users to fill out that item before they can submit the form.

例如,表单中的<input>元素可以具有required属性。 这就要求用户填写该项目,然后才能提交表单。

Here are examples that do the same thing:

以下是执行相同操作的示例:

<input type="text" required >
<input type="text" required="required" >

You can read more about the <a href>, <a target>, <script> src, and roll attributes here:

您可以在此处阅读有关<a href>,<a target>,<script> src和roll属性的更多信息:

<a href>属性 (<a href> Attribute)

<script> src属性 (<script> src Attribute)

滚动属性 (roll Attribute)

<目标>属性 (<a target> Attribute)

Now let's learn more about some other HTML attributes:

现在,让我们进一步了解其他一些HTML属性:

P对齐属性 (P Align Attribute)

重要 (Important)

This attribute is not supported in HTML5. It is recommended to use the text-align CSS property.

HTML5不支持此属性。 建议使用text-align CSS属性 。

To align the text inside a <p> tag, this attribute will help.

要在<p>标记内对齐文本,此属性将有所帮助。

句法 (Syntax)

<p align="position">Lorem Ipsum...</p>

属性 (Attributes)

  • left - Text aligns to the left

    -文本向左对齐

  • right - Text aligns to the right

    -文本对齐

  • center - Text aligns to the center

    中心 -文本与中心对齐

  • justify - All lines of text have equal width

    对齐 -文本的所有行均具有相等的宽度

(Example)

<html>
<body>
<p align="center">Paragraph align attribute example</p>
</body>
</html>

Img Src属性 (Img Src Attribute)

The <img src> attribute refers to the source of the image you want to display. The img tag will not display an image without the src attribute. However, if you set the source to the location of the image, you can display any image.

<img src>属性引用您要显示的图像的来源。 没有src属性, img标签将不会显示图像。 但是,如果将源设置为图像的位置,则可以显示任何图像。

There is an image of the freeCodeCamp Logo located at https://avatars0.githubusercontent.com/u/9892522?v=4&s=400

https://avatars0.githubusercontent.com/u/9892522?v=4&s=400上有freeCodeCamp徽标的图像。

You can set that as the image using the src attribute.

您可以使用src属性将其设置为图像。

<html><head><title>Img Src Attribute Example</title></head><body><img src="https://avatars0.githubusercontent.com/u/9892522?v=4&s=400"></body>
</html>

The above code displays like this:

上面的代码显示如下:

The src attribute is supported by all browsers.

所有浏览器都支持src属性。

You can also have a locally hosted file as your image.

您还可以将本地托管的文件作为映像。

For example, <img src="images/freeCodeCamp.jpeg> would work if you had a folder called images which had the freeCodeCamp.jpeg inside, as long as the ‘images’ folder was in the same location as the index.html file.

例如, <img src="images/freeCodeCamp.jpeg>会如果有一个文件夹中称为工作images ,其具有freeCodeCamp.jpeg内,只要该‘图像’文件夹是在相同的位置index.html文件。

../files/index.html

../files/index.html

..files/images/freeCodeCamp.jpeg

..files/images/freeCodeCamp.jpeg

字体大小属性 (Font Size Attribute)

This attribute specifies the font size as either a numeric or relative value. Numeric values range from 1 to 7 with 1 being the smallest and 3 the default. It can also be defined using a relative value, like +2 or -3, which set it relative to the value of the size attribute of the <basefont> element, or relative to 3, the default value, if none does exist.

此属性将字体大小指定为数字值或相对值。 数值范围为17其中1为最小值,默认值为3 。 也可以使用相对值来定义它,例如+2-3 ,将其相对于<basefont>元素的size属性值设置,或者相对于默认值3 (如果不存在的话)进行设置。

Syntax:

句法:

<font size="number">

<font size="number">

Example:

例:

<html><body><font size="6">This is some text!</font></body>
</html>

Note : The size attribute of <font> is not supported in HTML5. Use CSS instead.

注意: The size attribute of <font> is not supported in HTML5. Use CSS instead. The size attribute of <font> is not supported in HTML5. Use CSS instead.

字体颜色属性 (Font Color Attribute)

This attribute is used to set a color to the text enclosed in a <font> tag.

此属性用于为<font>标记中包含的文本设置颜色。

句法: (Syntax:)

html

html

### Important:
This attribute is not supported in HTML5. Instead, this [freeCodeCamp article](https://guide.freecodecamp.org/css/colors) specifies a CSS method, which can be used.### Note:
A color can also be specified using a 'hex code' or an 'rgb code', instead of using a name.### Example:
1. Color name attribute
```html
<html><body><font color="green">Font color example using color attribute</font>
</body>
</html>

Hex code attribute

十六进制代码属性

<html>
<body>
<font color="#00FF00">Font color example using color attribute</font>
</body>
</html>

RGB attribute

RGB属性

<html>
<body>
<font color="rgb(0,255,0)">Font color example using color attribute</font>
</body>
</html>

自动对焦属性 (Autofocus Attribute )

The autofocus attribute is a boolean attribute.

自动对焦属性是布尔属性。

When present, it specifies that the element should automatically get input focus when the page loads.

如果存在,它指定元素在页面加载时应自动获得输入焦点。

Only one form element in a document can have the autofocus attribute. It cannot be applied to <input type="hidden">.

文档中只有一个表单元素可以具有自动对焦属性。 它不能应用于<input type="hidden">

适用于 (Applies to)

ElementAttribute<button>autofocus<input>autofocus<select>autofocus<textarea>autofocus

ElementAttribute <button>自动对焦<input>自动对焦<select>自动对焦<textarea>自动对焦

(Example)

<form><input type="text" name="fname" autofocus><input type="text" name="lname">
</form>

兼容性 (Compatibility)

This is an HTML5 attribute.

这是HTML5属性。

Onclick事件属性 (Onclick Event Attribute)

When the element is clicked fires a event.

单击该元素时将触发一个事件。

It works just like the onclick method or addEventListener('click') to the element.

就像onclick方法或元素的addEventListener('click')

<element onclick="event"></element>

event can be a JavaScript function or you can write raw JavaScript

event可以是JavaScript函数,也可以编写原始JavaScript

例子 (Examples)

Changing the color of a <p> element when clicked

单击时更改<p>元素的颜色

<p id="text" onclick="redify()">Change my color</p><script>
function redify(){let text = document.querySelector('#text');text.style.color = "red";
}
</script>

Using raw JavaScript onclick attribute:

使用原始JavaScript onclick属性:

<button onclick="alert('Hello')">Hello World</button>

图对齐属性 (Img Align Attribute)

The align attribute of an image specifies where the image should be aligned according to the surrounding element.

图像的align属性指定应根据周围元素将图像对齐的位置。

Attribute Values:right - Align image to the right left - Align image to the lefttop - Align image to the topbottom - Align image to the bottommiddle - Align image to the middle

属性值:右-将图像左对齐-将图像左对齐-将图像对齐到底部-将图像对齐到底部-将图像对齐到中间

For example:

例如:

<!DOCTYPE html>
<html lang="en"><head><title>Img Align Attribute</title></head>
<body><p>This is an example. <img src="image.png" alt="Image" align="middle"> More text right here<img src="image.png" alt="Image" width="100"/></body>
</html>

We can also align in right if we want:

如果需要,我们也可以右对齐:

<p>This is another example<img src="image.png" alt="Image" align="right"></p>

Please note the align attribute is not supported in HTML5, and you should use CSS instead. However, it is still supported by all the major browsers.

请注意,HTML5不支持align属性,而应使用CSS。 但是,所有主要浏览器仍支持该功能。

输入类型属性 (Input Type Attribute)

The input type attribute specifies the type of the input the user should put in your form.

输入类型属性指定用户应在表单中输入的输入类型。

文本 (text)

One line of a text.

一行文本。

<form><label for="login">Login:</label><input type="text" name="login"></form>

密码 (password)

One line of a text. Text is automatically displayed as a series of dots or asterisks (depends on the browser and OS).

一行文本。 文本将自动显示为一系列的点或星号(取决于浏览器和OS)。

<form><label for="password">Password:</label><input type="password" name="password"></form>

电子邮件 (email)

The HTML checks if the input matches the e-mail address format (something@something).

HTML检查输入的内容是否与电子邮件地址格式(something @ something)相匹配。

<form><label for="email">E-mail address:</label><input type="email" name="email"></form>

(number)

Allow only numeric input. You can also specify the min and max value allowed. The example below check that the input is number between 1 and 120.

仅允许数字输入。 您还可以指定允许的最小值和最大值。 下面的示例检查输入的数字是否在1到120之间。

<form><label for="age">Age:</label><input type="number" name="age" min="1" max="120"></form>

无线电 (radio)

Only one option can be selected by the user. The group of radio buttons need to have the same name attribute. You can select automatically one option by using checked property (in example below the value Blue is selected).

用户只能选择一个选项。 单选按钮组必须具有相同的名称属性。 您可以通过使用checked属性来自动选择一个选项(例如,在下面的“蓝色”值中被选中)。

<form><label><input type="radio" name="color" value="red">Red</label><label><input type="radio" name="color" value="green">Green</label><label><input type="radio" name="color" value="blue" checked>Blue</label></form>

复选框 (checkbox)

User can select zero or more options from the group of checkboxes. You can use checked property here too for one or more options.

用户可以从复选框组中选择零个或多个选项。 您也可以在此处将checked属性用于一个或多个选项。

<form><label><input type="checkbox" name="lang" value="english">english</label><label><input type="checkbox" name="lang" value="spanish">spanish</label><label><input type="checkbox" name="lang" value="french">french</label></form>

纽扣 (button)

The input is displayed as button, the text which should be displayed in the button is in value attribute.

输入显示为按钮,应在按钮中显示的文本在value属性中。

<form><input type="button" value="click here"></form>

提交 (submit)

Displays the submit button. The text which should be displayed in the button is in value attribute. After clicking on the button, the HTML do the validation and if it passes, the form is submitted.

显示提交按钮。 按钮中应显示的文本位于value属性中。 单击按钮后,HTML进行验证,如果通过,则提交表单。

<form><input type="submit" value="SUBMIT"></form>

重启 (reset)

Displays the reset button. The text which should be displayed in the button is in value attribute. After clicking on the button, all values from the form are deleted.

显示重置按钮。 按钮中应显示的文本位于value属性中。 单击按钮后,将删除表单中的所有值。

<form><input type="reset" value="CANCEL"></form>

There are more types elements.

类型元素更多。

其他HTML属性: (Other HTML Attributes:)

<script> src属性 (<script> src attribute)

滚动属性 (roll attribute)

<a href>属性 (<a href> attribute)

<目标>属性 (<a target> attribute)

翻译自: https://www.freecodecamp.org/news/html-attributes-explained/

相关文章:

css中的选择器

1.在html中引入css的方法&#xff1a;四种方式: a.行内式(也称内联式) 如: <h1 style"color:red;test</h1> b.内嵌式 <style type"text/css"> h1{ color:red; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal; widow…

javascript的call()方法与apply()方法的理解

先看一段代码 function cat() {} cat.prototype{food:fish,say:function () {console.log(I love this.food);} };var blackCat new cat(); blackCat.say(); 这时&#xff0c;控制台输出 I love fish若此时&#xff0c;有另一个对象 Dog{food:bones and shit}; dog对象没有say…

java排序算法(冒泡,插入,选择,快速,堆,归并,希尔,基数)

import java.util.Arrays; import java.util.LinkedList;/*** * * 各种排序: 冒泡&#xff0c;插入&#xff0c;选择&#xff0c;快速&#xff0c;堆&#xff0c;归并&#xff0c;希尔&#xff0c;基数*/ public class Sorts {//1. 冒泡&#xff1a;//时间复杂度:n(n-1)/2O(n^2…

边界填充算法讲解_边界填充算法

边界填充算法讲解Boundary fill is the algorithm used frequently in computer graphics to fill a desired color inside a closed polygon having the same boundary color for all of its sides.边界填充是在计算机图形学中经常使用的算法&#xff0c;用于在其所有边都具有…

使用Git管理源代码

git是个了不起但却复杂的源代码管理系统。它能支持复杂的任务&#xff0c;却因此经常被认为太过复杂而不适用于简单的日常工作。让我们诚实一记吧&#xff1a;Git是复杂的&#xff0c;我们不要装作它不是。但我仍然会试图教会你用&#xff08;我的&#xff09;基本的Git和远程代…

[.Net跨平台]部署DTCMS到Jexus遇到的问题及解决思路---Linux环境搭建

最近朋友托我帮忙研究如何把一个DTCMS部署到Linux下&#xff0c;经过1天的研究&#xff0c;部署基本成功&#xff0c;可能有些细节还未注意到&#xff0c;现在把心得分享一下。过程比预期的要简单 身为.Net程序员&#xff0c;这个问题的第一步可能就是如何搭建一个Linux环境来测…

Sequence point 中文

摘自维基百科&#xff1a; In C[4] and C,[5] sequence points occur in the following places. (In C, overloaded operators act like functions, and thus operators that have been overloaded introduce sequence points in the same way as function calls.) Between ev…

python中pop函数_Python中的Pop函数

python中pop函数什么是弹出功能&#xff1f; (What is the pop function?) The method pop() removes and returns the last element from a list. There is an optional parameter which is the index of the element to be removed from the list. If no index is specified…

第六周学习进度条

日期 任务 听课 编程 阅读 准备考试 日总计 周日 周一 120 300 0 0 420 100 周二 0 120 0 0 120 周三 0 0 0 0 0 周四 0 0 0 0 0 周五 0 0 0 0 0 周六 0 120 100 0 …

1071. 小赌怡情(15)

常言道“小赌怡情”。这是一个很简单的小游戏&#xff1a;首先由计算机给出第一个整数&#xff1b;然后玩家下注赌第二个整数将会比第一个数大还是小&#xff1b;玩家下注t个筹码后&#xff0c;计算机给出第二个数。若玩家猜对了&#xff0c;则系统奖励玩家t个筹码&#xff1b;…

关于年长程序员的5个误传

原文链接&#xff1a;http://kb.cnblogs.com/page/150932/ 英文原文&#xff1a;Five Pervasive Myths About Older Software Developers 最近我刚过完40岁生日&#xff0c;一个朋友向我开玩笑地说“嘿&#xff0c;你已经老了&#xff0c;不适合做程序员了&#xff01;”我虽然…

java中getter_Java中的Getter和Setters解释了

java中getterGetters and setters are used to protect your data, particularly when creating classes. Getter和Setter用于保护数据&#xff0c;尤其是在创建类时。 For each instance variable, a getter method returns its value while a setter method sets or updates…

Loadrunner手动关联详解

Loadrunner手动关联详解 一、关联的含义&#xff1a; 关联&#xff08;correlation&#xff09;&#xff1a;在脚本回放过程中&#xff0c;客户端发出请求&#xff0c;通过关联函数所定义的左右边界值&#xff08;也就是关联规则&#xff09;&#xff0c;在服务器所响应的内容中…

解决Visual Studio禁止使用strlen函数的问题

问题描述&#xff1a; 在学习C的复制构造函数以及复制赋值运算符的重载时&#xff0c;需要用到使用C风格的字符串作为引入&#xff0c;由于我用的是VS2015&#xff08;社区版&#xff09;&#xff0c;在编译时出错。编译器提醒strcpy函数是不安全的&#xff0c;建议改用strlen_…

求整型数组所有子串的和中的最大值

#include <iostream> using namespace std;const int MIN_INT -2147483647;int maxSum(const int *arr, int len){int my_max MIN_INT;int tmp 0;for(int i 0; i < len; i){//从头到尾。。tmp arr[i];//遍历相加。if(my_max < tmp){//更新my_maxmy_max tmp;}…

c语言中的if语句_If ... C中的其他语句解释

c语言中的if语句Conditional code flow is the ability to change the way a piece of code behaves based on certain conditions. In such situations you can use if statements.条件代码流是根据某些条件更改一段代码的行为的能力。 在这种情况下&#xff0c;可以使用if语句…

设计模式之笔记--装饰模式(Decorator)

装饰模式&#xff08;Decorator&#xff09; 定义 装饰模式&#xff08;Decorator&#xff09;&#xff0c;动态地给一个对象添加一些额外的职责&#xff0c;就增加功能来说&#xff0c;装饰模式比生成子类更为灵活。 类图 描述 Component&#xff1a;被装饰者和装饰者共有的基…

整型数组负数放左面,其他放右面,要求时空复杂度:O(n), O(1)。

例如&#xff1a;处理前&#xff1a;{5 -3 6 -7 -6 1 8 -4 0 0}&#xff0c;处理后&#xff1a;{-3 -7 -6 -4 5 6 1 8 0 0}. #include <iostream> #include <algorithm> using namespace std;const int LEN 10; void printInt(int c){cout<<c<<"…

[bzoj] 1176 Mokia || CDQ分治

原题 给出WW的矩阵&#xff08;S没有用&#xff0c;题目有误&#xff09;&#xff0c;给出无限次操作&#xff0c;每次操作的含义为&#xff1a; 输入1:你需要把(x,y)(第x行第y列)的格子权值增加a 输入2:你需要求出以左下角为(x1,y1),右上角为(x2,y2)的矩阵内所有格子的权值和,…

sql子查询示例_SQL更新查询示例说明

sql子查询示例In this article, were going to learn how to use the SQL update statement - what it is, what it can do, and what you need to be aware of before using it.在本文中&#xff0c;我们将学习如何使用SQL更新语句-它是什么&#xff0c;它可以做什么以及在使用…

keepalived+nginx安装

安装keepalivednginx做为公司服务器前端高可用反向代理安装nginx 1、yum install -y pcre pcre-devel gcc-c zlib zlib-devel openssl openssl-devel 2、cd /usr/local/soft 3、wget http://nginx.org/download/nginx-1.12.2.tar.gz 4、tar -zxvf nginx-1.12.2.tar.gz 5、cd ng…

Nexus Repository Manager 3.0 发布

著名仓库管理工具Nexus&#xff0c;在2016年4月6日发布3.0版本&#xff08;包括OSS版&#xff09;&#xff0c;相较2.*版本有很大的改变&#xff1a; 1. 从底层重构&#xff0c;从而提高性能&#xff0c;增强扩展能力&#xff0c;并改善用户体验 2. 升级界面&#xff0c;增加更…

计算整型数的二进制中包含多少个1

方法很多啊&#xff0c;比如&#xff1a;//1.靠循环&#xff1a; int calculate(unsigned int n){int count 0;unsigned int mark 0x1;for(int i 0; i < 32; i){if(n&mark){count;mark<<1;}}return count; }//2. 据说不用循环就能算出来的牛叉方法。木有测试。…

nvm npm不是内部命令_npm作弊表-最常见的命令和nvm

nvm npm不是内部命令npm or the Node Package Manager, is one of the most used tools for any Node.js developer. Heres a list of the most common commands youll use when working with npm.npm或Node Package Manager是Node.js开发人员最常用的工具之一。 这是使用npm时…

快速排序的实现与注意点

先上实现了的C代码&#xff1a; 1 #include <ctime>2 #include <cstdio>3 #include <cstdlib>4 #include <iostream>5 using namespace std;6 const int maxn 100;7 int a[maxn], n;8 void quick_sort(int left, int right) {9 if(left > …

iOS 线程之GCD的高级使用方法

之前的一篇关于线程的blog已经为大家介绍了GCD的简单使用方式及样例说明&#xff0c;今天因为项目中有特殊的应用GCD的实例&#xff0c;为大家介绍两种特殊需求的使用GCD的方法。 目的&#xff1a;实现一件事情做完&#xff0c;再做下一件事情。确保函数的运行周期。 解决方式…

构造次优查找树

似乎有些错误&#xff0c;但是错在哪了呢&#xff1f; #include <iostream> #include <cmath> using namespace std;const int NUM 9;int value[NUM] {1,2,3,4,5,6,7,8,9}; float weight[NUM] {1,1,2,5,3,4,4,3,5}; float sum_weight[NUM]; void init_sum_weigh…

同步等待 异步等待_异步/等待和承诺的解释

同步等待 异步等待The async / await operators make it easier to implement many async Promises. They also allow engineers to write clearer, more succinct, testable code.async / await 运算符使实现许多异步Promises变得更加容易。 它们还允许工程师编写更清晰&#…

使用 GDB 调试多进程程序

使用 GDB 调试多进程程序 来源 https://www.ibm.com/developerworks/cn/linux/l-cn-gdbmp/index.html GDB 是 linux 系统上常用的 c/c 调试工具&#xff0c;功能十分强大。对于较为复杂的系统&#xff0c;比如多进程系统&#xff0c;如何使用 GDB 调试呢&#xff1f;考虑下面这…

理解Lucene索引与搜索过程中的核心类

理解索引过程中的核心类 执行简单索引的时候需要用的类有&#xff1a; IndexWriter、Directory、Analyzer、Document、Field 1、IndexWriter IndexWriter&#xff08;写索引&#xff09;是索引过程的核心组件&#xff0c;这个类负责创建新的索引&#xff0c;或者打开已有的索引…