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

HTML的div和span

时间:2014-07-26 15:23:11      阅读:472      评论:0      收藏:0      [点我收藏+]

标签:div   table   span   

 抄自:http://www.w3school.com.cn/html/html_forms.asp


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

  • 块级元素在浏览器显示时,通常会以新行来开始(和结束)。例子:<h1>, <p>, <ul>, <table>
  • 内联元素在显示时通常不会以新行开始。例子:<b>, <td>, <a>, <img>

【注】块级元素译为 block level element内联元素译为 inline element

1.div元素

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

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

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

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

2.span元素

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

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

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

3.使用div进行布局的例子

bubuko.com,布布扣

<!DOCTYPE html>
<html>
<head>
<style type="text/css">
	div#container{width:500px}
	div#header {background-color:#99bbbb;}
	div#menu {background-color:#ffff99;height:200px;width:150px;float:left;}
	div#content {background-color:#EEEEEE;height:200px;width:350px;float:left;}
	div#footer {background-color:#99bbbb;clear:both;text-align:center;}
	h1 {margin-bottom:0;}
	h2 {margin-bottom:0;font-size:18px;}
	ul {margin:0;}
	li {list-style:none;}
</style>
</head>

<body>
	<div id="container">
		<div id="header">
			<h1>Main Title of Web Page</h1>
		</div>
		<div id="menu">
			<h2>Menu</h2>
			<ul>
				<li>HTML</li>
				<li>CSS</li>
				<li>JavaScript</li>
			</ul>
		</div>
		<div id="content">Content goes here</div>
		<div id="footer">Copyright W3School.com.cn</div>
	</div>
</body>
</html>

 

4.使用table进行布局

<!DOCTYPE html>
<html>
<body>

	<table width="500" border="0">
		<tr>
			<td colspan="2" style="background-color:#99bbbb;">
				<h1>Main Title of Web Page</h1>
			</td>
		</tr>

		<tr valign="top">
			<td style="background-color:#ffff99;width:100px;text-align:top;">
				<b>Menu</b><br />
				HTML<br />
				CSS<br />
				JavaScript
			</td>
			<td style="background-color:#EEEEEE;height:200px;width:400px;text-align:top;">
			Content goes here</td>
		</tr>

		<tr>
			<td colspan="2" style="background-color:#99bbbb;text-align:center;">
			Copyright W3School.com.cn</td>
		</tr>
	</table>

</body>
</html>

 

HTML的div和span,布布扣,bubuko.com

HTML的div和span

标签:div   table   span   

原文地址:http://blog.csdn.net/lsjseu/article/details/38140553

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