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=utf-8" />
<meta name="author" content="Chomo" />
<link rel="start" href="http://www.14px.com" title="Home" />
<title>无标题文档</title>
<style type="text/css">
p { text-align:center;}
span { display:inline-block; text-align:left;}
</style>
</head>
<body>
<p><span>无标题文档无标题文档无标题文档无标题文档</span></p>
<p><span>无标题文档无标题文档无标题文档无标题文档无标题文档无标题文档无标题文档无标题文档无标题文档无标题文档无标题文档无标题文档无标题文档无标题文档无标题文档无标题文档无标题文档无标题文档无标题文档无标题文档无标题文档无标题文档无标题文档无标题文档无标题文档无标题文档无标题文档无标题文档无标题文档无标题文档无标题文档无标题文档无标题文档无标题文档无标题文档无标题文档无标题文档无标题文档无标题文档无标题文档无标题文档无标题文档无标题文档无标题文档无标题文档无标题文档无标题文档无标题文档</span></p>
</body>
</html>
 
ps:这个效果和display:inline-block;没关系,即使删除效果也是一样的!是因为文字作为一个整体式一直都是居中的,只是从第二行开始文字由于没有空间显示发生了折行,这个时候它就开始引用text-align:left;这个样式,其实text-align:left;才是显示的关键。。。
原文地址:https://www.cnblogs.com/my_front_research/p/2107888.html