我正在開發使用CSS3移動HTML5頁面的DIV,我遇到的頁面類似下面CSS3中心與動態內容
<!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>
我想橫向中心,在類「DivToBeCentered」對齊DIV上面的代碼到它的父div。在div裏面有兩個段落標籤,對於一個段落,標籤內容是動態的,所以它的寬度可能會在加載頁面的時候發生變化,我該如何中心將div與父類的「DivToBeCentered」對齊。如果你解決這個這將是對我更有幫助,我被困在這個問題上的day.Thanks提前
您可以指定要居中的div的寬度? – Champ
div的寬度是動態的,因爲要居中的div內的段落標記具有來自數據庫的內容。 –
給出該div的最小寬度。 &應用邊距:0 auto; – SVS