首页  >  文章  >  web前端  >  HTML 块元素

HTML 块元素

王林
王林原创
2024-09-04 16:18:49710浏览

Html 包含各种元素,它们将充当每个网页的构建块。每个网页都有不同的视点,前端和后端都会实现逻辑。 Html 会有用户定义或定制的要求,如 CSS、引导框架等突出显示网页。一般来说,CSS 样式根据其用途将 HTML 元素分为两类:1. 块级元素和 2. 内联元素。我们已经讨论过之前的文章,例如 span 和 div element 用于 HTML 和

中的内联元素。标签用于 HTML 中的块级元素。

语法:

<html>
<body>
<div>
----------codes------
----------------------
</div>
</body>
</html>

一般来说,每个 HTML 标签都有其预定义的结构和功能。 HTML 中的块元素具有我们将在文档中使用的不同标签。下面列出了一些标签。

标签:

,


、、、

-

、、
  • 、、、 、


      、、、

        提到的标签是 HTML 中预定义的块元素。在 HTML 文档中调用时,每个标签都具有不同的功能。最有可能的是,我们使用

        ;块级元素中的标签。代码是HTML中块级元素的通用语法,在需要时我们也会使用上面提到的预定义标签;每个标签都会有独立且独立的 HTML 内容。

        块元素在 HTML 中如何工作?

        它将使用 CSS 样式和格式化模型,并覆盖内联和块元素。最有可能的是,它会负责格式化块元素。格式化块元素是 HTML 中块级元素之一。每个 CSS 元素看起来都像一个表单;它包含一个盒子,其中包含一些组件,如内容、填充和边框;这些是 CSS 样式中的不同组件。

        • 内容:表示文本、图片、视频等HTML元素的一般内容
        • Padding:表示按格式覆盖到任何内容中的任何填充,如 padding-top、padding-left、padding-right、padding-bottom 等。这些是属性。
        • 边框:表示 HTML 内容中的任何边框和填充;我们使用 border-top、border-bottom 等设置边框

        块元素想要设置 HTML 文档中的边距和填充。因为网页需要适当的对齐才能使用户看起来更有吸引力。在某些情况下,块元素部分包含元素外部的边距;元素内部的填充将围绕内容。如果您需要元素的背景颜色或图像,您可以指定它们,它们将显示在内容和填充区域中。一般来说,边距区域是透明的并显示父元素的背景。但是,如果父元素(例如正文部分)尚未分配任何显示属性,则会发生异常。在这种情况下,边距和填充区域都显示颜色或图像。边距是指 HTML 元素外边缘之间的距离,包括内容和内边距。

        我们还设置了边框以突出网页,包括边框颜色、样式、宽度和边距。我们控制元素周围边框的外观,并可以指定各种边框类型。 CSS 的 border-style 属性使用户能够设置自己的自定义边框样式,指定的值包括 none、solid、double、hidden、dotted、dashed、groove、ridge、inset 和 outset。如果我们将文档与边框对齐,则不指定任何值意味着默认值为无;这意味着没有为您的页面分配边框。除了隐藏值外,所有这些边框样式都包含在 css1 版本中,隐藏值是在 css2 版本中添加的。

        Starting from HTML 4, the div element is a block-level element for designing documents with specified divisions. Div elements lack specific formatting characteristics by default. However, you can still use the deprecated Align attributes in HTML to the center or align content to the right side; it’s a default in deprecated elements in HTML. In

        tag was intended to take any format in CSS styles, and div has the options like nested div tags and other elements nested with div elements whatever styles, borders, and alignments we specified it would affect for those nested elements. Some basic codes for div tags with border, background image, and other user-defined format styles.

        Code:

        div.sample {width:150px;background:#FF0002;border:2px dotted black;padding:7px;}
        div.sample ul {color:green;}

        The above codes are samples to understand the CSS attributes and functionalities implemented with the div tag. We will discuss some basic examples in the below sections.

        Examples of HTML Block Elements

        Given below are the following examples:

        Example #1

        Code:

        <html>
        <head>
        <style>
        div.sample {width:150px;border:2px dotted black;padding:7px;}
        div.sample ul {color:green;}
        </style>
        </head>
        <body>
        <div class="sample" style="color:black">
        <p>Samples</p>
        <ul>
        <li>Apple</li>
        <li>Orange</li>
        <li>Pineapple</li>
        </ul>
        </div>
        </body>
        </html>

        Output:

        HTML 块元素

        Example #2

        Code:

        <html>
        <head>
        <style>
        div.sample {width:150px;border:2px dotted black;padding:7px;}
        div.sample ul {color:green;}
        </style>
        </head>
        <body>
        <p>Sample <span style = "color:green">green</span>
        <span style = "color:black">black</span></p>
        </body>
        </html>

        Output:

        HTML 块元素

        Example #3

        Code:

        <html>
        <head>
        <style>
        .first {
        background-color: green;
        list-style-type: none;
        text-align: center;
        margin: 2;
        padding: 2;
        }
        .second {
        display: inline-block;
        font-size: 30px;
        padding: 23px;
        }
        </style>
        </head>
        <body>
        <ul class="first">
        <li><a href="#home">Home</a></li>
        <li><a href="#aboutus">AboutUs</a></li>
        <li><a href="#contactus">Contact Us</a></li>
        </ul>
        </body>
        </html>

        Output:

        HTML 块元素

        In the above example, we see the different scenarios for the block-level elements first two examples, we use and align the menus or tabs or text values in the

        and tags. is used for inline elements, but

        paragraph tag will use for blocking the text or values which is to be specified in the user-level areas. A final example will be used for the

  • 以上是HTML 块元素的详细内容。更多信息请关注PHP中文网其他相关文章!

    声明:
    本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn