這使我絕對瘋狂。我不是最有經驗的CSS,所以我希望它是簡單的。將兩張圖片並排並以Wordpress爲中心集中在一起
我用「The Morning After」主題運行Wordpress 2.9.2。
我想寫一篇文章,我想要顯示兩個小圖片,標題,並排和居中在頁面中間。
下面是HTML代碼我用來顯示圖像:
[caption align="alignnone" width="150" caption="Protein rest"]
<a href="http://www.mysite.com/wp-content/uploads/2008/06/protein-rest.jpg">
<img title="Mash during protein rest" src="http://www.mysite.com/wp-content/uploads/2008/06/protein-rest-150x144.jpg" alt="Mash during protein rest" width="150" height="144" />
</a>[/caption]
[caption align="alignnone" width="143" caption="Saccharification rest" captionalign="center"]
<a href="http://www.mysite.com/wp-content/uploads/2008/06/saccharification-rest.jpg">
<img title="Mash during saccharification rest" src="http://www.mysite.com/wp-content/uploads/2008/06/saccharification-rest-143x150.jpg" alt="Mash during saccharification rest" width="143" height="150" />
</a>[/caption]
我試圖用「aligncenter」和「alignleft」爲標題對齊 - 如果我使用「alignleft」的照片一字排開完美,但一直到頁面的左側。如果我使用「aligncenter」,則圖片位於中心,但是會一個疊在另一個的上面。
我首先想到的是用包裹在一個div圖像:
<div style="text-align:center;">image code</div>
,但不起作用。現在,如果我用這樣的中心div來包裝並省略[caption]標籤,它就可以工作,但我需要標題。這些標題標籤由Wordpress翻譯成它自己的wp-caption類。我也嘗試在父級居中的div包裝器中的每個單獨的圖像中包裝它自己的div。
以下是style.css的相關部分 - 請讓我知道如果您需要任何其他信息,並且如果您可以幫助我,我會推遲從最近的橋跳下!
謝謝!
的style.css:
.aligncenter, div.aligncenter { display: block; margin: 14px auto; }
.alignleft { float: left; margin: 0 14px 10px 0; }
.alignright { float: right; margin: 0 0 10px 14px; }
.wp-caption { border: 1px solid #ddd; text-align: center; background-color: #f3f3f3; padding-top: 4px; /* optional rounded corners for browsers that support it */ -moz-border-radius: 3px; -khtml-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 3px; }
.wp-caption img { margin: 0; padding: 0; border: 0 none; }
.wp-caption p.wp-caption-text { font-size: 11px; line-height: 14px; padding: 5px 4px 5px 5px; margin: 0; }
PS - 我知道在WordPress的可用的庫功能的,但想避免它,很想知道爲什麼包裝在一個div不動整個套件到中心。
最後,只是爲了完整起見,這裏是頁面的源代碼使用上述股利包裝和形象代碼加載時(所以你可以看到的WordPress如何轉化的標題標籤):
<div style="text-align:center;">
<div class="wp-caption alignnone" style="width: 160px">
<a href="http://www.mysite.com/wp-content/uploads/2008/06/protein-rest.jpg">
<img title="Mash during protein rest" src="http://www.mysite.com/wp-content/uploads/2008/06/protein-rest-150x144.jpg" alt="Mash during protein rest" width="150" height="144" />
</a>
<p class="wp-caption-text" style="text-align:center">Protein rest</p>
</div>
<div class="wp-caption alignnone" style="width: 153px">
<a href="http://www.mysite.com/wp-content/uploads/2008/06/saccharification-rest.jpg">
<img title="Mash during saccharification rest" src="http://www.mysite.com/wp-content/uploads/2008/06/saccharification-rest-143x150.jpg" alt="Mash during saccharification rest" width="143" height="150" />
</a>
<p class="wp-caption-text" style="text-align:center">Saccharification rest</p>
</div>
</div>
男人,我試過類似的東西,我知道的關於網頁設計和CSS的一切尖叫,這應該工作得很好。剛剛嘗試過,並且沒有去 - 圖片集中在一起,但堆疊在一起。我必須假設我的主題style.css中有一些東西阻止了這些東西的運行。有趣的是,當我添加「margin:0 auto」時,我的答案會導致居中的div。在包裝div聲明中,如果我省略它是左對齊的。這是正常的行爲嗎?我剛開始使用這個主題,看到我將不得不花費一些時間來選擇樣式表和php – Jim 2010-05-20 14:00:35
選擇這個作爲答案,因爲我發現它適用於MOST瀏覽器,而不是我們在工作中使用的那些(IE v7.0.5730.11) - 謝謝,我已經使用這些div標籤簡化了我的新功能(顯示在我的答案中),它非常好(除非在工作中,lol) – Jim 2010-06-09 17:54:04