Html内容竖直居中

针对div块:

我们可以使用类选择器;

.divcenter{ line-height:100px; height:30px; margin-top:-15px;}

需要注意的是:margin-top一定要是height属性的1/2。当然需要加上负号。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
	#center{ 
		position:absolute; top:50%; left:50%; 
		margin-top:-50px; margin-left:20px;      
		width:800px;   
		height:100px;} 
		.divcenter{ line-height:100px; height:30px; margin-top:-15px;}
</style>
</head>

<body>
<div class="divcenter">
	<form action="" method="get">
		<table width="100%" height="100%" align="center">
			<tr>
				<td width="30%" colspan="1">关键字:
			  	<input type="text" name="keyword"/></td>
				<td width="30%" colspan="1">
					范围:
					<select name="scope">
						<option value="keywords">关键字</option>
						<option value="content">内容</option>
						<option value="keywordAndcontent">关键字和内容</option>
					</select>
			  </td>
			  <td width="40%" colspan="1"><button type="submit">搜索</button></td>
			</tr>
		</table>
	</form>
</div>
</body>
</html>


写的比较好的博客:

http://www.divcss5.com/rumen/r363.shtml

http://bbs.9ria.com/thread-195134-1-1.html

http://jingyan.baidu.com/article/2d5afd69eb72d385a2e28ecb.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值