我正在使用 css3 开发一个移动 HTML5 页面,我有如下页面
<!DOCTYPE html>
<html>
<head>
<title>Starter page</title>
<style>
.float-right{float:right}
.float-left{float:left}
.clear{clear:both}
</style>
</head>
<body>
<div class="content" id="home">
<div class=" ">
<!--START: Div to be centered to page-->
<div class="DivToBeCentered">
<div class="float-left">
<!--START: This paragraph content is dynamic from database, i want to center align the div with the class
DivToBeCentered with reference to its parent-->
<p class="">dynamic para 1 with background image</p>
<!--END: This paragraph content is dynamic from database, i want to center align the div with the class
DivToBeCentered with reference to its parent-->
</div>
<div class=" float-left">
<p class="">static para 2 without background image</p>
</div>
<div class="clear"></div>
</div>
<!--END: Div to be centered to page-->
</div>
</div>
</body>
</html>
我想将 div 与上面代码中的“DivToBeCentered”类水平居中对齐到它的父 div。在那个 div 里面有两个段落标签,因为一个段落标签的内容是动态的,所以它的宽度在加载页面时可能会改变,我如何将该 div 与“DivToBeCentered”类居中对齐到它的父级。如果你解决了这个问题,对我会更有帮助,我今天陷入了这个问题。在此先感谢