Web开发——HTML基础(HTML布局 HTML+CSS)

  网站常常以多列显示内容(就像杂志和报纸)。

1、使用 <div> 元素的 HTML 布局

  注释:<div> 元素常用作布局工具,因为能够轻松地通过 CSS 对其进行定位。

  这个例子使用了四个 <div> 元素来创建多列布局:

  test.html代码:

 1 <!DOCTYPE html>
 2 <html>
 3     <head>
 4         <meta charset="utf-8">
 5         <title>My test page</title>
 6
 7     </head>
 8
 9     <body>
10
11         <div id="header">
12             <h1>City Gallery</h1>
13         </div>
14
15         <div id="nav">
16             London<br />
17             Paris<br />
18             Tokyo<br />
19         </div>
20
21         <div id="section">
22             <h1>London</h1>
23             <!--<p>标签会自动在其前后创建一些空白-->
24             <p>
25                 London is the capital city of England. It is the most populous city in the United Kingdom,
26                 with a metropolitan area of over 13 million inhabitants.
27             </p>
28             <p>
29                 Standing on the River Thames, London has been a major settlement for two millennia,
30                 its history going back to its founding by the Romans, who named it Londinium.
31             </p>
32         </div>
33
34         <div id="footer">
35             Copyright W3School.com.cn
36         </div>
37     </body>
38 </html>

  csstest1.css代码:

 1 #header {
 2     background-color:black;
 3     color:white;
 4     text-align:center;
 5     padding:5px;
 6 }
 7 #nav {
 8     line-height:30px;
 9     background-color:#eeeeee;
10     height:300px;
11     width:100px;
12     float:left;
13     padding:5px;
14 }
15 #section {
16     width:350px;
17     float:left;
18     padding:10px;
19 }
20 #footer {
21     background-color:black;
22     color:white;
23     clear:both;
24     text-align:center;
25     padding:5px;
26 }

  输出结果:

2、使用 HTML5 的网站布局

  HTML5 提供的新语义元素定义了网页的不同部分:

HTML5 语义元素

header 定义文档或节的页眉
nav 定义导航链接的容器
section 定义文档中的节
article 定义独立的自包含文章
aside 定义内容之外的内容(比如侧栏)
footer 定义文档或节的页脚
details 定义额外的细节
summary                                    定义 details 元素的标题                                                                                                                                                                                                                                   

  这个例子使用 <header>, <nav>, <section>, 以及 <footer> 来创建多列布局:

  test.html代码:

 1 <!DOCTYPE html>
 2 <html>
 3     <head>
 4         <meta charset="utf-8">
 5         <title>My test page</title>
 6
 7         <link rel="stylesheet" href="csstest1.css">
 8     </head>
 9
10     <body>
11
12         <header>
13             <h1>City Gallery</h1>
14         </header>
15
16         <nav>
17             London<br>
18             Paris<br>
19             Tokyo<br>
20         </nav>
21
22         <section>
23             <h1>London</h1>
24             <p>
25             London is the capital city of England. It is the most populous city in the United Kingdom,
26             with a metropolitan area of over 13 million inhabitants.
27             </p>
28             <p>
29             Standing on the River Thames, London has been a major settlement for two millennia,
30             its history going back to its founding by the Romans, who named it Londinium.
31             </p>
32         </section>
33
34         <footer>
35             Copyright W3School.com.cn
36         </footer>
37     </body>
38 </html>

  输出结果:

3、使用表格的 HTML 布局

  注释:<table> 元素不是作为布局工具而设计的。

  <table> 元素的作用是显示表格化的数据。

  使用 <table> 元素能够取得布局效果,因为能够通过 CSS 设置表格元素的样式:

  test.html代码:

 1 <!DOCTYPE html>
 2 <html>
 3     <head>
 4         <meta charset="utf-8">
 5         <title>My test page</title>
 6
 7         <link rel="stylesheet" href="csstest1.css">
 8     </head>
 9
10     <body>
11         <table class="lamp">
12             <tr>
13                 <th>
14                     <img src="baidu.jpg">
15                 </th>
16                 <td>The table element was not designed to be a layout tool.</td>
17             </tr>
18         </table>
19
20     </body>
21 </html>

  csstest1.css代码:

 1 table.lamp {
 2     width:100%;
 3     border:1px solid #d4d4d4;
 4 }
 5 table.lamp th, td {
 6     padding:10px;
 7 }
 8 table.lamp td {
 9     width:40px;
10 }

  输出结果:

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

时间: 2024-07-31 07:05:14

Web开发——HTML基础(HTML布局 HTML+CSS)的相关文章

0083 移动端WEB开发之响应式布局、bootstrap

移动端WEB开发之响应式布局 1. 响应式开发原理 1.1 响应式开发原理 就是使用媒体查询针对不同宽度的设备进行布局和样式的设置,从而适配不同设备的目的. 设备的划分情况: 小于768的为超小屏幕(手机) 768~992之间的为小屏设备(平板) 992~1200的中等屏幕(桌面显示器) 大于1200的宽屏设备(大桌面显示器) 1.2 响应式布局容器 响应式需要一个父级做为布局容器,来配合子级元素来实现变化效果. 原理就是在不同屏幕下,通过媒体查询来改变这个布局容器的大小,再改变里面子元素的排列

移动端WEB开发之响应式布局

1.0 响应式开发原理 1.1 响应式开发原理 就是使用媒体查询针对不同宽度的设备进行布局和样式的设置,从而适配不同设备的目的. 设备的划分情况: 小于768的为超小屏幕(手机) 768~992之间的为小屏设备(平板) 992~1200的中等屏幕(桌面显示器) 大于1200的宽屏设备(大桌面显示器) 1.2 响应式布局容器 响应式需要一个父级做为布局容器,来配合子级元素来实现变化效果. 原理就是在不同屏幕下,通过媒体查询来改变这个布局容器的大小,再改变里面子元素的排列方式和大小,从而实现不同屏幕

web开发的基础知识:http请求

引用自:http://blog.csdn.net/yefan2222/article/details/6198098 http://baike.baidu.com/view/1628025.htm?fromtitle=http&fromid=243074&type=syn 1.HTTP协议 Internate的基本协议是TCP/IP(传输控制协议和网际协议).而目前使用的FTP,HTTP都是建立在TCP/IP上的应用层协议.不同的协议对应不同的应用.而HTTP协议是Web应用所使用的主要协

Web开发——HTML基础(文件和网站结构)

参考:https://developer.mozilla.org/en-US/docs/Learn/HTML/Introduction_to_HTML/Document_and_website_structure 除了定义页面的各个部分(例如"段落"或"图像")之外,HTML还拥有许多用于定义网站区域的块级元素(例如"标题","导航"菜单","主要内容栏".)本文探讨如何规划基本网站结构,并编写H

Web开发——HTML基础(HTML中的图像)

参考:HTML中的图像 1.我们如何在网页上放置图像? 注意:元素<img>和  <video>有时被称为替换元素.这是因为元素的内容和大小由外部资源(如图像或视频文件)定义,而不是由元素本身的内容定义. 例如: 1 <img src="images/dinosaur.jpg" 2 alt="The head and torso of a dinosaur skeleton; 3 it has a large head with long sha

Web开发——HTML基础(HTML脚本)

1.HTML CSS 通过使用 HTML4.0,所有的格式化代码均可移出 HTML 文档,然后移入一个独立的样式表. 举例1(本例演示如何使用添加到 <head> 部分的样式信息对 HTML 进行格式化): 1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>My test page</title> 6 <st

Web开发——HTML基础(HTML事件属性)

1.全局事件属性 HTML 4 增加了使事件在浏览器中触发动作的能力,比如当用户点击元素时启动 JavaScript. 如需学习更多有关事件编程的知识,请访问我们的 JavaScript 教程. 下面列出了添加到 HTML 元素以定义事件动作的全局事件属性. ?= HTML5 中新的事件属性. 2.Window 事件属性 针对 window 对象触发的事件(应用到 <body> 标签): 属性 值 描述 onafterprint script 文档打印之后运行的脚本. onbeforeprin

移动WEB开发之 -- 流式布局

flex布局原理 常见的父项属性 flex-direction设置主轴方向 justify-content 设置主轴上的子元素排列方式 flex-wrap属性 align-items属性 align-content属性 flex-flow属性 常见的子项属性 align-selt属性 hj 原文地址:https://www.cnblogs.com/Rivend/p/12234661.html

web开发速查表(php,css,html5........)