我想让段落的文字居中,同时让背景颜色刚好覆盖文字,请问该怎么设置?背景变短后只能靠左,无法居中。。或者说设置了背景宽度后,文字居中的效果就没有了。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" /><title>无标题文档</title><body><style type="text/css">.div1{width:400px;height:400px;border:solid #000000 1px;text-align:center;margin:10px auto;}.p1{background-color:#FF0000;width:200px;text-align:center;}.p2{background-color:#FF0000;text-align:center;}</style></body><div class="div1"><p class="p1">背景宽度后如何让文字居中</p><p class="p2">背景宽度后如何让文字居中</p></div></html>
- 4 回答
- 1 关注
- 3602 浏览
相关问题推荐
添加回答
举报
0/150
提交
取消