1. 利用fireworks还原盒子
<!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" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Document</title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
body{
font-family: "微软雅黑";
}
.news{
width: 260px;
height: 444px;
border-top: 1px solid gray;
margin: 100px;
}
.news h3{
color: red;
font-size: 16px;
line-height: 50px;
padding-left: 1px;
}
.news ul{
list-style: none;
padding-top: 1px;
}
.news ul li{
line-height: 24px;
font-size: 12px;
}
.news ul li a{
text-decoration: none;
color: black;
}
</style>
</head>
<body>
<div class="news">
<h3>时评</h3>
<ul>
<li><a href="#">新京报:钱理群卖房养老与你我有多大关系?</a></li>
<li><a href="#">新京报:“低收入男人共妻论”有多么荒谬</a></li>
<li><a href="#">京华时报:杂技演员当市委书记有何不可</a></li>
<li><a href="#">南都:谭嗣同真圣母,康有为圣母病?</a></li>
</ul>
</div>
</body>
</html>
效果:
2. 文字可以将父亲标签撑出高度
<!DOCTYPE html>
<html lang="en">
<!--css3选择器-->
<head>
<meta charset="UTF-8">
<title>Title</title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
p{
width: 200px;
border: 1px solid black;
margin: 100px;
line-height: 40px;
/*background-color: green;*/
}
/*行高属性是真实物理存在的,为了严格保证字在行里面居中,行高和字号都为偶数*/
</style>
</head>
<body>
<p>文字文字文字文字文字文字文字文字文字文字文字文字文字文字文字文字文字文字文字文字文字文字文字文字文字文字文字
</p>
</body>
</html>
效果:
盒子高度:
3. 单行文字在行高里是居中的(行高等于盒子高只适用于单行文本居中)
<!DOCTYPE html>
<html lang="en">
<!--css3选择器-->
<head>
<meta charset="UTF-8">
<title>Title</title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
p{
width: 400px;
height: 60px;
margin: 100px;
background-color: yellowgreen;
line-height: 60px;
}
/*文字在行高里是居中的*/
</style>
</head>
<body>
<div id="box1">
<p class="p1">文字在行高里是居中的</p>
</div>
</body>
</html>
效果
4. 多行文本居中需要设置盒子的padding
<!DOCTYPE html>
<html lang="en">
<!--css3选择器-->
<head>
<meta charset="UTF-8">
<title>Title</title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
p{
width: 400px;
height: 140px;
margin: 100px;
background-color: yellowgreen;
font-size: 16px;
line-height: 20px;
padding-top: 60px;
}
/*文字在行高里是居中的*/
</style>
</head>
<body>
<div id="box1">
<p class="p1">文字在行高里是居中的文字在行高里是居中的文字在行高里是居中的文字在行高里是居中的
文字在行高里是居中的文字在行高里是居中的文字在行高里是居中的文字在行高里是居中的</p>
</div>
</body>
</html>
效果