首页 > web前端 > js教程 > 正文

自行开发构建 Web UI:部分了解 HTML

WBOY
发布: 2024-08-16 17:01:43
原创
1216 人浏览过

Web 开发是当今最受欢迎的技能之一。它涉及创建可通过浏览器访问的用户友好且引人入胜的网站。成为 Web 开发人员的第一步是了解 HTML。

Develop yourself to build Web UIs: Part  Understanding HTML

HTML超文本标记语言)是任何网页的支柱。它是用于构建网页的标准语言,决定内容在浏览器中的显示方式。虽然页面的外观由 CSS (层叠样式表) 决定,其功能由 JS (Javascript) 决定,HTML 负责基本骨架或结构。

在深入学习这部分课程之前,了解您的旅程中将使用的著名和反复出现的术语非常重要。这些将帮助您随着我们的进展理解概念(也让作者更容易解释事情;-))。


了解行话

  1. 编程语言:以计算机可以执行的特定语法(编程语言的方式)编写的一组指令。请记住,计算机只能理解二进制代码(1 或 0),现在,为了使计算机理解逻辑并找到权衡,我们(人类)创建了一种编程语言,以便可以轻松地我们编码,也让计算机理解它。
  2. 编译器:将用编程语言编写的代码翻译成计算机可以理解和执行的机器语言的工具。
  3. 语法:定义编程语言结构的规则。将其视为句子中单词的排列方式以使其有意义。
  4. 注释:代码中的注释,解释代码某些部分的作用。注释可以帮助其他开发人员(或未来的你)理解代码背后的逻辑。
  5. DOM(文档对象模型):DOM 是 HTML 文档的树状表示。 HTML 中的每个标签都成为该树中的一个节点。例如,如果您的 HTML 有一个 带有

    的标签(paragraph) 在其中,浏览器创建一个主体节点,并以段落节点作为其子节点。

  6. 孩子们:随着你的进步,你就会明白这一点。元素嵌套在另一个元素内。例如,在 HTML 中,div 标签 (
    ) 内的段落标签 (

    ) 将被视为 div 的子级。

  7. 块级元素:随着您的进步,您将了解这个术语。该术语通常描述元素的特征,即它将占据全部可用宽度。

  8. 使用 HTML 启动

    HTML 代表 超文本标记语言

    • 超文本:指 HTML 将不同文档链接在一起的能力。

    • 标记语言:使用标签来注释文本,定义文本在浏览器中的显示方式。

    这是 HTML 文档的基本结构:

    <!DOCTYPE html>
    <html>
      <head>
        <title>HTML Tutorial</title>
      </head>
      <body>
        <p>Hello, world!</p>
      </body>
    </html>
    
    登录后复制
    • 标签:在 HTML 中,标签用于定义元素。标签括在尖括号中,例如 或

    • 元素:由开始标签和结束标签组成,其中可能包含内容。例如,

      你好,世界!

      是一个段落元素。


    HTML 文档结构

    每个 HTML 文档都遵循一个基本结构:

    1. : Declares the document type and version of HTML.
    2. : The root element that encloses all other HTML elements.
    3. : Contains meta-information about the document, such as the title and links to stylesheets.
    4. : Sets the title of the webpage, displayed in the browser's title bar or tab.
    5. : Provides metadata about the HTML document, such as character set, author, and viewport settings. It's a self-closing tag.
    6. : Embeds CSS code to style the HTML elements.
    7. <script></script>: Embeds JavaScript code for adding interactivity to the webpage.
    8. : Encloses the content that will be visible to users on the webpage.

    Commonly Used HTML Elements

    Here are some basic HTML elements you’ll use frequently:

    • : Defines a paragraph.
    • : A block-level element used to group other elements together.
    • : An inline element used to group text for styling purposes.
    • : Represents the introductory content or navigational links of a section.
    • to
      : Headings, with

      being the highest level and

      the lowest.

    • : Inserts a line break (self-closing tag — meaning there is no need to close the tag).
    • : Used to create an HTML form for user input.
    • : Creates an input field, typically used within a form.
    • : Creates a dropdown list.
    • : Associates a text label with a form element.
    • : Defines a table.
    • : Defines a row in a table.
    • : Defines a cell in a table row.
    • : Defines a header cell in a table row.
      • : Defines an unordered (bulleted) list.
        1. : Defines an ordered (numbered) list.
        2. : Defines a list item.

        Creating Your First HTML File

        To create an HTML file, you can use any text editor, such as Notepad or VS Code. Here’s a simple example:

        1. Open your text editor and type the following code:
        <!DOCTYPE html>
        <html>
        <head>
          <title>HTML Tutorial</title>
        </head>
        <body>
          <h1>Example Number 1</h1>
          <p>Hello, world!</p>
        </body>
        </html>
        
        登录后复制
        1. Save the file with a .html extension (e.g., index.html)
        2. Open the file in your web browser to see your first HTML webpage in action!
        3. To inspect your code, press Ctrl + Shift + C in Google Chrome to open the Developer Tools and explore the DOM structure.
        4. Go to the network tab in the Developer Tools and refresh your browser tab.

        You can find that there is a request in the name that you have saved as in this picture.
        Develop yourself to build Web UIs: Part  Understanding HTML

        In the response tab, you will find the code that you have written as in the following picture
        Develop yourself to build Web UIs: Part  Understanding HTML

        Now, what happened is that, once you opened the file you have saved as html, the computer began running the file in browser. The browser wanted something to show, so it made a request call to the file from which it was launched. The file gave the browser your code and that was found in the response section. Since it was a html file, the browser begins reading the HTML code from the top to the bottom. This process is known as parsing. During parsing, the browser encounters different HTML tags (like , , , etc.) and starts to build a structure called DOM based on these tags. As the browser builds the DOM, it simultaneously renders the content on your screen.


        Creating a Table

        Let’s take a step further by creating a simple table in HTML:

        1. Open the same HTML file and add the following code inside the tag:
        <p>Table Example</p>
        <table>
          <tr>
            <th>Name</th>
            <th>Power</th>
            <th>Is Kurama Present</th>
          </tr>
          <tr>
            <td>Naruto</td>
            <td>Rasengan</td>
            <td>Yes</td>
          </tr>
          <tr>
            <td>Sasuke</td>
            <td>Sharingan</td>
            <td>No</td>
          </tr>
        </table>
        
        登录后复制
        1. Save the file and refresh your browser to see the table displayed.

        Notice the heading is being rendered by paragraph tag. Alternatively, you can also use tag, which will center the heading of the table. Experiment with the caption tag and refresh to see the changes.

        Note that tag should only be used immediately after the

        opening tag.

        You’ve now successfully created a basic table in HTML. Feel free to experiment with additional rows and columns to get more comfortable with HTML syntax.


        Conclusion

        Congratulations on completing your first steps into web development with HTML! The key to mastering HTML is practice. Experiment with different elements, create your own webpages, and don’t be afraid to make mistakes — every error is a learning opportunity.

        Remember, this is just the beginning. As you continue to build on this foundation, you’ll soon be able to create more complex and dynamic websites. Let’s make the web a better place, one line of code at a time.

        本文由 Anantha Krishnan 撰写,他是一位在 IT 和机械工程领域拥有丰富经验的专业人士。拥有全栈开发背景以及对机械和电气系统的热情,Anantha Krishnan 现在专注于创建教育内容,以帮助其专业领域的初学者。

        以上是自行开发构建 Web UI:部分了解 HTML的详细内容。更多信息请关注PHP中文网其他相关文章!

        来源:dev.to
        本站声明
        本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
        热门教程
        更多>
        最新下载
        更多>
        网站特效
        网站源码
        网站素材
        前端模板