时间:2021-07-01 10:21:17 帮助过:27人阅读
<!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>www.divcss5.com的CSS div的布局居中实例</title>
<style type="text/css">
<!--
body{ text-align:center; }
.waicheng {color: #0066CC; margin:5px auto; width:700px;
height:200px; border:1px solid #000000;}
-->
</style>
</head>
<body>
<div class="waicheng">我是css中的居中的实验;我的布局外层有一个边为1px黑色边,
我宽700px,高为200px,设置了与顶部内容距离为5PX</div>
</body>
</html>CSS布局居中实例浏览
2、介绍使用css属性让网页的背景居中:
这里居中就包括了左右居中与上下居中,居中代码如下:
body{BACKGROUND: #FFF url(http://www.divcss5.com/img/css-logo.gif) no-repeat center;} //这段话意思就是让css-logo.gif这个图片设置背景不重复(no-repeat ),并将居中(center)这个居中是左右居中,而垂直不需要设置,自动会居中。
3、css让介绍文字、图片内容左右上下居中方法教程:
我们知道左右就中好办,直接用text-align:center; 即可让文字与图片内容居中,但是垂直呢,假如我们在高度为120px的高度下垂直居中,图片居中是vertical-align:middle;css属性,文字居中就要靠设置行高方法居中文字内容,这里我们设置为120px的高度这需要设置个line-height:120px;这样就通过css属性类样式来实现文字与图片的上下左右居中。
整个网站居中的代码如下:
<!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>www.divcss5.com的CSS div的完整居中实例</title>
<style type="text/css">
<!--
body{ text-align:center; margin:0 auto;
background:url(http://www.divcss5.com/img/css-logo.gif) no-repeat center;}
.waicheng {color: #0066CC; margin:5px auto;
width:700px; height:120px; line-height:120px; border:1px solid #000000; }
.waicheng img {vertical-align:middle;}
-->
</style>
</head>
<body>
<div class="waicheng">我是css中的居中的完整居中实例;
我的布局外层有一个边为1px
<img src="http://www.divcss5.com/img/css-logo.gif" alt="图片内容居中" /></div>
</body>
</html>