2011-08-15 73 views
0

我想要圖片加灰色背景居中。居中浮動

人體的樣式設置是這樣的:

body {margin-left:auto;margin-right:auto;width:1000px;} 

的圖片設置DIV是這樣的:

{width:auto;margin-left:auto;margin-right:auto;float:right;} 

的影像風格是這樣的:

{border:0px;padding:0px;margin:0px;} 

如果我刪除浮動圖像周圍的灰色邊框將填充所有頁面。我不想爲邊框指定一定的寬度,因爲有些圖像很大,有些很小。

我需要幫助集中圖像!

回答

4
  • 添加text-align: center#chpheader,並刪除float: right
  • display: inline-block加到<div style="text-align:center;background-color:#DCDEDD;margin-top:20px;border-radius: 20px;">
  • 如果您需要IE6/7兼容性,請改爲添加display: inline-block; *display: inline; zoom: 1

您不應該使用內聯樣式。

+0

我做了你所說的一切,仍然是一樣的東西! – shnisaka

+0

您是否刪除了「float:right」?我有點忘了把這個重要的部分添加到我的初始答案:) – thirtydot

+0

完美!感謝您的幫助 ! – shnisaka

0

影像風格應該是margin:0px auto不僅僅是margin: 0px