HTML基础内容详解

巴扎黑
Release: 2017-04-15 09:05:40
Original
2356 people have browsed it

HTML简介

什么是HTML

  • HTML(Htyper Text Markup Language):即超文本标记语言。

  • 超文本:指可以包含图片、链接,甚至音乐、程序等非文字元素。

  • 标记语言:由标记(标签)构成的语言。

什么是标签

  • 由一对尖括号包裹的单词构成,例如:

  • 标签不区分大小写,和一样,推荐使用小写。

  • 有些标签使用一个标签即可,叫做自闭和标签,例如:


  • 标签可以嵌套,但是不能交叉嵌套

什么是标签属性

  • 通常是以键值对形式出现的,例如 name="nick"

  • 属性只能出现在开始标签或自闭和标签中

  • 属性名字全部小写

  • 属性值必须使用双引号或单引号包裹 例如,name="nick"

  • 如果属性值和属性名完全一样.直接写属性名即可,例如:readonly

HTML5基本结构

   
   
Copy after login
Copy after login

HTML5如何指定字符集

  • 使用Content-Type指定字符集

  • 直接使用charset指定字符集


标签

</h3>

显示在浏览器的标题栏

为页面上的所有链接规定默认地址或默认目标。

    Title   
  图片加载失败。。。 my blogs  
Copy after login
Copy after login

以上代码中,的src属性时一个相对路径,因为中通过base标签设置了链接的默认地址,
所以img的src实际的地址是“https://segmentfault.com/u/je...”。
而a标签中只是指定了href,并未指定target属性,所以也会使用base中设置的target属性的值。

引用外部文档,常见于引用外部样式。重要属性有三个:rel、href、type。
rel用于规定文档与被链接文档之间的关系【注:必须】:

  • rel="dns-prefetch" 预先解析缓存文档中使用的域名,目的是为了提高网页访问速度。使用场景:在一个网页频繁使用其他域名资源时。

  • rel="shortcut icon"或rel="icon" 在收藏和标题栏上用于显示的图标。示例:

  • rel="nofollow" 用于指示搜索引擎不要追踪(爬虫不要抓取),从而减少垃圾链接。使用场景:不希望被信任或是不希望被搜索引擎录入的网站。

href用于规定资源的路径(绝对路径/相对路径)【注:必须】。
type用于规定被链接文档的MIME类型,用于明确文件的打开方式,【注:非必须】。例如:.css文件的MIME类型为text/css,而.ico文件的MIME类型为image/x-icon。

用于定义与该HTML文档相关的元数据。最常见的用途是指定当前文档所用的字符集
重要的属性有三个:http-equiv、name、content
http-equiv把content属性值关联到http头部,可能的值为:

  • content-type用于规定浏览器接受的文档类型,一般为text/html,即content的值一般设为text/html。

  • refresh用于规定网页自动刷新的频率,时间以秒为单位(切记不是毫秒),也可设定刷新后跳转的路径,即content的值一般设为刷新的间隔秒数以及跳转路径。

  • expires用于设定网页到期时间,一旦到期,必须到服务器上重传。

       
    Copy after login
    Copy after login

name为content属性值赋予一个含义或功能,可能的值为:

  • keywords将content值定义为供搜索引擎抓取信息的关键字

  • description将content值定义为搜索引擎搜索后,在搜索结果中显示的简单网页描述

  • author将content值规定为网页制作者的信息

  • generator将content值规定为网页生成工具的信息

       
    Copy after login
    Copy after login

content 定义与http-equiv或name属性相关的元信息,是必要的属性。


标签

1.块级元素(block)和内联元素(inline)

块级元素:

~

    什么是标签属性

    • 通常是以键值对形式出现的,例如 name="nick"

    • 属性只能出现在开始标签或自闭和标签中

    • 属性名字全部小写

    • 属性值必须使用双引号或单引号包裹 例如,name="nick"

    • 如果属性值和属性名完全一样.直接写属性名即可,例如:readonly

    HTML5基本结构

       
       
    Copy after login
    Copy after login

    HTML5如何指定字符集

    • 使用Content-Type指定字符集

    • 直接使用charset指定字符集


    标签

    </h3>

    显示在浏览器的标题栏

    为页面上的所有链接规定默认地址或默认目标。

        Title   
      图片加载失败。。。 my blogs  
    Copy after login
    Copy after login

    以上代码中,的src属性时一个相对路径,因为中通过base标签设置了链接的默认地址,
    所以img的src实际的地址是“https://segmentfault.com/u/je...”。
    而a标签中只是指定了href,并未指定target属性,所以也会使用base中设置的target属性的值。

    引用外部文档,常见于引用外部样式。重要属性有三个:rel、href、type。
    rel用于规定文档与被链接文档之间的关系【注:必须】:

    • rel="dns-prefetch" 预先解析缓存文档中使用的域名,目的是为了提高网页访问速度。使用场景:在一个网页频繁使用其他域名资源时。

    • rel="shortcut icon"或rel="icon" 在收藏和标题栏上用于显示的图标。示例:

    • rel="nofollow" 用于指示搜索引擎不要追踪(爬虫不要抓取),从而减少垃圾链接。使用场景:不希望被信任或是不希望被搜索引擎录入的网站。

    href用于规定资源的路径(绝对路径/相对路径)【注:必须】。
    type用于规定被链接文档的MIME类型,用于明确文件的打开方式,【注:非必须】。例如:.css文件的MIME类型为text/css,而.ico文件的MIME类型为image/x-icon。

    用于定义与该HTML文档相关的元数据。最常见的用途是指定当前文档所用的字符集
    重要的属性有三个:http-equiv、name、content
    http-equiv把content属性值关联到http头部,可能的值为:

    • content-type用于规定浏览器接受的文档类型,一般为text/html,即content的值一般设为text/html。

    • refresh用于规定网页自动刷新的频率,时间以秒为单位(切记不是毫秒),也可设定刷新后跳转的路径,即content的值一般设为刷新的间隔秒数以及跳转路径。

    • expires用于设定网页到期时间,一旦到期,必须到服务器上重传。

         
      Copy after login
      Copy after login

    name为content属性值赋予一个含义或功能,可能的值为:

    • keywords将content值定义为供搜索引擎抓取信息的关键字

    • description将content值定义为搜索引擎搜索后,在搜索结果中显示的简单网页描述

    • author将content值规定为网页制作者的信息

    • generator将content值规定为网页生成工具的信息

         
      Copy after login
      Copy after login

    content 定义与http-equiv或name属性相关的元信息,是必要的属性。


    标签

    1.块级元素(block)和内联元素(inline)

    块级元素:

    ~

        行内元素:

        block元素的特点:

        • 总是在新行上开始;

        • 行高以及外边距和内边距都可控制;

        • 宽度默认是容器的100%,除非设定一个宽度;

        • 可容纳内联元素和其他块元素。

        inline(内联)元素的特点:

        • 和其他元素都在一行上;

        • 行高及外边距和内边距不可改变;

        • 宽度就是它的文字或图片的宽度,不可改变;

        • 只能容纳文本或者其他内联元素。

        行内元素,需要注意:

        • 设置宽度width无效;

        • 设置高度height无效,可以通过line-height来设置;

        • 设置margin只有左右margin有效,上下无效;

        • 设置padding只有左右padding有效,上下则无效。注意元素范围是增大了,但是对元素周围的内容是没影响的。

        2.基本标签

        ~

        : 标题标签

        : 段落标签,包裹的内容被换行,并且上下内容之间有一行空白。
            style="text-indent: 2em"可以设置样式为首行缩进两个字符。
            

        可以用来设置整个段落的缩进。
        : 加粗标签
        : 为文字加上一条中线
        : 文字下方加下划线
        : 文字变成斜体
        : 上角标 和 下角标

        : 换行

        : 水平线

        : 块标签。

        块级标签常用于布局,行级标签常用于显示内容。 p的显示通常使用id或class来标识。id为唯一的标签标识,class为标签的类标识。 p的大小是由内容来决定的,默认情况下,高度由内容的高度决定,宽度适应屏幕。
        Copy after login
        Copy after login

        : 可以容纳其他元素,是一个容器。

        3.特殊符号

        " " < < > > 空格 © © & & ¥ ¥ £ £
        Copy after login
        Copy after login

        4.超链接标签(锚标签)

        重要属性有三个:href、target、name

        • href 超链接地址:可以是Web上任意资源,包括图片,网页,样式,脚本文件等。href="#"时,表示被链接页面就是当前页面。

        • target 文档打开时要显示的目标位置,属性值一般有:_blank(新窗口中打开)、_self(默认,在超链接所在的容器中打开)、_parent(在超链接的父容器中打开)、_top(超链接所在的顶层容器中打开)、name(名称为name的框架中打开)。

        • name 锚标记名称。作用:跳转到文档的某个地方。返回首页。

        网页跳转:

        Nick Blogs
        Copy after login
        Copy after login

        锚标记跳转:

        Copy after login

        5.图片标签

        重要属性有:src、title、alt、width、height、align。

        • src 图片地址

        • title 鼠标悬浮在图片上的文字

        • alt 图片找不到时要替换的文字。如果图片资源使用的是外网资源,则不会显示要替换的文字。如果使用的是本网站的资源(相对路径给出),则找不到图片时会显示替换的文字,并保留图片设置的宽高结构。

        • align 图片周围文字的垂直对齐情况。常用的属性值有:top(与图片的顶部对齐)、middle(与图片的中部对齐)、bottom(默认,与图片的底部对齐)。

        • width 图片的宽

        • height 图片的高 (宽高两个属性,若只写一个会,自动等比缩放)

          图片加载失败。。。
          Copy after login
          Copy after login

        6.列表标签

          : 无序列表标签

        • : 列表中的每一项.
        • Copy after login
          Copy after login
          Copy after login
          Copy after login

            : 有序列表标签

          1. : 列表中的每一项.
          2. Copy after login
            Copy after login
            Copy after login
            Copy after login

          3. 主要的属性有:type、value两个:

            • type指明列表项的类型,属性值有:A,a,I,i,1,disc(实心圆),square(实心正方形),circle(空心圆)。

            • value表示序号值从几开始。

            定义列表

            • 列表标题

            • 列表项

              • A
              • B
              • C
              • Copy after login
                Copy after login


              1. 3
              2. 4
              3. Copy after login
                Copy after login


              标题
              第一项
              第二项
              第三项
              Copy after login
              Copy after login

            7.


        、、、
        表格标签
        序号 姓名
        1. Jerry
        2. Ferry
        序号 姓名
        1. Jerry
        2. Ferry
        Copy after login
        Copy after login

        table标签的主要属性:

        • border表格边框

        • align水平对齐方式

        • bgcolor背景颜色

        • cellpadding内边距,单元格与内容之间的距离

        • cellspacing外边距,单元格的间距,设置为0时,表格变为实线表格

        • width表格的宽度,可以用%或者像素,最好通过css来设置长宽

        表格的标题
        表格的行
        表格的表头名称,与不同在于文字采用加粗居中的形式显示
        单元格,用来显示表格内容
        表格头部,使结构更加分明
        表格主体部分,使结构更加分明
        rowspan单元格竖跨多少行,作用在th或者td上
        colspan单元格横跨多少列(即合并单元格),作用在th或者td上。(即横跨、竖跨都是作用在th或td上)

        8.表单标签

        表单属性
        HTML 表单用于接收不同类型的用户输入,用户提交表单时向服务器传输数据,从而实现用户与Web服务器的交互。
        属性:action、method、enctype

        • action表单要提交的地址,用于处理表单的内容(一般是提交到后台的一个接口,这个接口可以是java写成的,提交到这个接口后后台就知道如何处理这些数据了)。

        • method提交的方法,默认是get方式提交。

          • get:1.提交的键值对显示在地址栏url后面; 2.安全性相对较差; 3.对提交内容的长度有限制

          • post:1.提交的键值对不显示在地址栏; 2.安全性相对较高; 3.对提交内容的长度理论上无限制

        • enctype对表单数据进行编码

        表单元素
        type属性可能的值:

        • text文本框输入(type的默认类型)

          • autocomplete(自动完成输入的内容,要求表单元素要有name属性才有自动完成的效果,off表示自动完成不可用,on表示自动完成可用)

          • disabled(设置或者获取控件的状态,默认是false即可用,等于true时不可用,不能输入内容)

        • password密码框。(以下属性text和password共有)

          • size(指定表单元素的初始宽度。当type为text或password时,表单元素的大小以字符为单位,对于其他元素,宽度以像素为单位)

          • maxlength(type为text或password时,表示输入的最大字符数),有利于防止sql的注入攻击

          • readonly设置为只读状态

          • placeholder设置框内预置内容(灰色),焦点选中时消失

        • radio单选按钮

          • name(将name的值设置为相同值,才表示一组数据,才能实现单选功能)

          • value(必须要写,提交到服务器的key值,实际开发过程中value一般是编号)

          • checked(设置是否被默认选中)

        • checkbox复选框

          • name(将name的值设置为相同值,才表示一组数据,才能添加到同一value值列表并提交到服务器)

          • value(必须要写,提交到服务器的key值,实际开发过程中value一般是编号)

          • checked(设置是否被默认选中)

        • file文件域,用于上传文件(不同的浏览器表现形式不同)

        • submit提交按钮。用于提交表单。

        • reset重置按钮。清空表单的输入,恢复到表单默认的状态。

        • button普通按钮。一般结合javascript使用。

        • image图片按钮,用来提交表单,与submit是一样的效果。

          • src(图片路径)

        • hidden隐藏字段。

          • value(隐藏的内容)

        • color颜色标签。

          • value 指定颜色值(采用#十六进制数表示)。

        • date日期。

          • value值指定默认的日期,格式为*--*(年月日)。

        • datetime-local显示本地时间

          • value值指定默认的时间,格式为2017-04-13T23:10:10(年月日T时分秒)。

        • number数字向上或者向下滑动。可以填数字然后向上或者向下选择不同的值。

        • range滑动标签。

          • min(指定最小值)

          • max(指定最大值)

          • value(指定当前默认值)。

        • week每年的周数。

          • value指定哪一年第几周,格式为2017-W20(2017年第20周)。

        • name表单提交项的key

        • cols设置文本域宽度

        • rows设置文本域高度,即行数

        Copy after loginCopy after login对表单中的相关元素进行分组

        温馨提示

        不要忘记点赞哦 ==

        Copy after loginCopy after loginvalue: 表单提交项的值
        对于不同的输入类型,value 属性的用法也不同:type="button", "reset", "submit" - 定义按钮上的显示的文本type="text", "password", "hidden" - 定义输入字段的初始值type="checkbox", "radio", "image" - 定义与输入相关联的值
        The above is the detailed content of HTML基础内容详解. For more information, please follow other related articles on the PHP Chinese website!Related labels:htmlsource:php.cnPrevious article:Html case code to realize the report effect of dynamically displaying color blocksNext article:HTML forms and inputStatement of this WebsiteThe content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cnLatest Articles by AuthorHow to add elements to php array2023-03-14 15:58:02Example showing JS implementing a simple multiple-choice assessment system1970-01-01 08:00:00PHP solution to restrict multiple submissions of the same IP2023-03-15 07:38:01Using regular expressions to implement form validation in HTML1970-01-01 08:00:00Detailed explanation of this pointing issue in JavaScript strict mode1970-01-01 08:00:00Example code for building a tree menu (including multi-level menu) in Java1970-01-01 08:00:00Detailed explanation of examples of CSS3 implementing smooth transition when hover leaves1970-01-01 08:00:00Swiper carousel image source code sharing analysis1970-01-01 08:00:00Summarize and organize VsCode plug-ins1970-01-01 08:00:00HttpUtils request tool class code1970-01-01 08:00:00Latest IssuesLeverage VueJS components in PHPI want to mix basic HTML generated by Php and VueJS components without having to use VueJS...From 2023-11-11 00:01:4402288How to use open primitive tag in next js 13?In the recent NextJS13 update, they introduced a new way of handling meta tags that differ...From 2023-11-10 23:03:5101527PHP mailer not working: no error log, message says sent but not receivedI don't receive any error logs in my webserver's php error log. I've tried several differe...From 2023-11-10 15:02:3901218v-date-picker to select only month and yearPlease tell me if there is any other way to do this using v-date-picker. I just want the u...From 2023-11-10 14:05:0501269The rewritten title is: SweetAlert2: "onBeforeOpen" parameters are unknownI'm using Laravel5.8 and Sweetalertv2 and I'm trying to trigger this alert on Blade with: ...From 2023-11-10 09:39:0101257Related TopicsMore>html copyright symbolhtml online editorhtml web page productionhtml spacewhat is htmlHow to set html font sizehtml to txtHow to write html text box codePopular RecommendationsWhat does url mean?What does DOM mean?How to change image sizeHow to make font bold in HTMLHow to set the size of html imagesPopular TutorialsMore>Related TutorialsPopular RecommendationsLatest coursesThe latest ThinkPHP 5.1 world premiere video tutorial (60 days to become a PHP expert online training course)1394947PHP introductory tutorial one: Learn PHP in one week4206714JAVA Beginner's Video Tutorial2351299Little Turtle's zero-based introduction to learning Python video tutorial493347PHP zero-based introductory tutorial826384The latest ThinkPHP 5.1 world premiere video tutorial (60 days to become a PHP expert online training course)1394947 times of learningJAVA Beginner's Video Tutorial2351299 times of learningLittle Turtle's zero-based introduction to learning Python video tutorial493347 times of learningQuick introduction to web front-end development213423 times of learningMaster PS video tutorials from scratch843383 times of learning[Web front-end] Node.js quick start3157 times of learningComplete collection of foreign web development full-stack courses2551 times of learningGo language practical GraphQL1992 times of learning550W fan master learns JavaScript from scratch step by step465 times of learningPython master Mosh, a beginner with zero basic knowledge can get started in 6 hours10913 times of learningLatest DownloadsMore>Web EffectsWebsite Source CodeWebsite MaterialsFront End Template[form button] jQuery enterprise message form contact code[Player special effects] HTML5 MP3 music box playback effects[Menu navigation] HTML5 cool particle animation navigation menu special effects[form button] jQuery visual form drag and drop editing code[Player special effects] VUE.JS imitation Kugou music player code[html5 special effects] Classic html5 pushing box game[Picture special effects] jQuery scrolling to add or reduce image effects[Photo album effects] CSS3 personal album cover hover zoom effect[Front-end template] Home Decor Cleaning and Repair Service Company Website Template[Front-end template] Fresh color personal resume guide page template[Front-end template] Designer Creative Job Resume Web Template[Front-end template] Modern engineering construction company website template[Front-end template] Responsive HTML5 template for educational service institutions[Front-end template] Online e-book store mall website template[Front-end template] IT technology solves Internet company website template[Front-end template] Purple style foreign exchange trading service website template[PNG material] Cute summer elements vector material (EPS PNG)[PNG material] Four red 2023 graduation badges vector material (AI EPS PNG)[banner picture] Singing bird and cart filled with flowers design spring banner vector material (AI EPS)[PNG material] Golden graduation cap vector material (EPS PNG)[PNG material] Black and white style mountain icon vector material (EPS PNG)[PNG material] Superhero silhouette vector material (EPS PNG) with different color cloaks and different poses[banner picture] Flat style Arbor Day banner vector material (AI+EPS)[PNG material] Nine comic-style exploding chat bubbles vector material (EPS+PNG)[Front-end template] Home Decor Cleaning and Repair Service Company Website Template[Front-end template] Fresh color personal resume guide page template[Front-end template] Designer Creative Job Resume Web Template[Front-end template] Modern engineering construction company website template[Front-end template] Responsive HTML5 template for educational service institutions[Front-end template] Online e-book store mall website template[Front-end template] IT technology solves Internet company website template[Front-end template] Purple style foreign exchange trading service website templateAbout usDisclaimerSitemapphp.cn:Public welfare online PHP training,Help PHP learners grow quickly!