码迷,mamicode.com
首页 > Web开发 > 详细

Web开发——HTML基础(HTML块 <div>/<span> )

时间:2018-10-13 18:10:28      阅读:218      评论:0      收藏:0      [点我收藏+]

标签:add   分类   使用   配置   white   code   标签   The   html   

  可以通过 <div> 和 <span> 将 HTML 元素组合起来。

1、HTML 块元素

  大多数 HTML 元素被定义为块级元素或内联元素

  编者注:“块级元素”译为 block level element,“内联元素”译为 inline element。

  块级元素在浏览器显示时,通常会以新行来开始(和结束)。

  例子:<h1>, <p>, <ul>, <table>

2、HTML 内联元素

  内联元素在显示时通常不会以新行开始。

  例子:<b>, <td>, <a>, <img>

3、HTML <div> 元素

  HTML <div> 元素是块级元素,它是可用于组合其他 HTML 元素的容器。

  <div> 元素没有特定的含义。除此之外,由于它属于块级元素,浏览器会在其前后显示折行。

  如果与 CSS 一同使用,<div> 元素可用于对大的内容块设置样式属性。

  <div> 元素的另一个常见的用途是文档布局。它取代了使用表格定义布局的老式方法。使用 <table> 元素进行文档布局不是表格的正确用法。<table> 元素的作用是显示表格化的数据。

4、HTML <span> 元素

  HTML <span> 元素是内联元素,可用作文本的容器。

  <span> 元素也没有特定的含义。

  当与 CSS 一同使用时,<span> 元素可用于为部分文本设置样式属性。

5、HTML 分组标签

标签描述
<div> 定义文档中的分区或节(division/section)。
<span>                           定义 span,用来组合文档中的行内元素。                                                                                                                                                                                                                        

6、HTML 类

  对 HTML 进行分类(设置类),使我们能够为元素的类定义 CSS 样式。

  为相同的类设置相同的样式,或者为不同的类设置不同的样式。

  举例:

 1 <!DOCTYPE html>
 2 <html>
 3     <head>
 4         <meta charset="utf-8">
 5         <title>My test page</title>
 6         
 7         <style>.cities {
 8             background-color:black;
 9             color:white;
10             margin:20px;
11             padding:20px;
12         }
13         </style>
14     </head>
15     
16     <body>
17         <!--<div>容器,设置class属性是为了在<head>中配置css样式-->
18         <div class="cities">
19             <h2>London</h2>
20             <p>
21                 London is the capital city of England. 
22                 It is the most populous city in the United Kingdom, 
23                 with a metropolitan area of over 13 million inhabitants.
24             </p>
25         </div>
26 
27     </body>
28 </html>

  输出结果:

技术分享图片

6.1 分类块级元素

  HTML <div> 元素是块级元素。它能够用作其他 HTML 元素的容器。

  设置 <div> 元素的类,使我们能够为相同的 <div> 元素设置相同的类:

 

 1 <!DOCTYPE html>
 2 <html>
 3     <head>
 4         <meta charset="utf-8">
 5         <title>My test page</title>
 6         
 7         <style>.cities {
 8             background-color:black;
 9             color:white;
10             margin:20px;
11             padding:20px;
12         }
13         </style>
14     </head>
15     
16     <body>
17         <!--<div>容器,设置class属性是为了在<head>中配置css样式-->
18         <div class="cities">
19             <h2>London</h2>
20             <p>
21                 London is the capital city of England. 
22                 It is the most populous city in the United Kingdom, 
23                 with a metropolitan area of over 13 million inhabitants.
24             </p>
25         </div>
26             
27         <div class="cities">
28             <h2>Paris</h2>
29             <p>Paris is the capital and most populous city of France.</p>
30         </div>
31 
32         <div class="cities">
33             <h2>Tokyo</h2>
34             <p>Tokyo is the capital of Japan, the center of the Greater Tokyo Area,
35             and the most populous metropolitan area in the world.</p>
36         </div>
37 
38     </body>
39 </html>

  输出结果:

技术分享图片

6.2 分类行内元素

  HTML <span> 元素是行内元素,能够用作文本的容器。

  设置 <span> 元素的类,能够为相同的 <span> 元素设置相同的样式。

 

 1 <!DOCTYPE html>
 2 <html>
 3     <head>
 4         <meta charset="utf-8">
 5         <title>My test page</title>
 6         
 7         <style>
 8             span.red{
 9                 color: red
10             }
11         </style>
12     </head>
13     
14     <body>
15 
16         <h1>My <span class="red">Important</span> Heading</h1>
17 
18     </body>
19 </html>

   输出结果:

技术分享图片

 

Web开发——HTML基础(HTML块 <div>/<span> )

标签:add   分类   使用   配置   white   code   标签   The   html   

原文地址:https://www.cnblogs.com/zyjhandsome/p/9783547.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!