2014-03-07 37 views
2

如何在不影響帖子內部任何其他圖像的情況下如何調整CSS中的第一個圖像。如果我使用以下代碼:使用CSS調整文章中的第一個圖像,而不會影響任何其他圖像

#content div.single:nth-of-type(n) img { 
width: 448px !important; 
height: 252px !important; 
padding: 0 !important; 
margin-top: 0; 

它調整了帖子內所有圖像的大小。

我也曾嘗試第n個孩子,但沒有成功:

#content div.single img:nth-child(1){ 
width: 448px !important; 
height: 252px !important; 
padding: 0 !important; 
margin-top: 0;} 

這裏是the Demo

+0

':first-child'僞選擇器應該可以工作......順便說一句,你在該頁面上每個帖子只有1張圖片,因此你頁面內的所有圖片都會受到影響 - 如果你的確在瞄準第一張圖片每篇文章......你有沒有想過在頁面上的第一篇文章中的第一個圖像? – zoranc

+0

你想更改GTA標誌嗎? – Siyah

回答

1

與CSS容易解決這樣的:

.single p:nth-child(2) > img { 
width: 448px !important; 
height: 252px !important; 
padding: 0 !important; 
margin-top: 0; 
} 
1

爲什麼沒有目標,你需要一個這樣的形象:

.alignnone.size-full.wp-image-35095 { 
width: 448px !important; 
height: 252px !important; 
padding: 0 !important; 
margin-top: 0; 
} 

當你有一個有空間的類你在css中定位類,但是你用點來改變每個空間。

如果你想永遠的目標在後第一個圖像,然後你可以運行的Jquery:

$("#content img").first().attr('width', '150'); 

順便說一句,你有一個重要的在你的第一個形象,我掙扎着,爲什麼這是行不通的:P

+0

他希望每篇文章。如果你這樣做,這只是一個特定的職位,這是錯誤的。 – Siyah

+0

好吧,我編輯了我的答案,謝謝 – vaskort

+0

你現在批准了嗎? – vaskort

1

你可以試試這個:

#content div.single img:first-child { 
width: 448px !important; 
height: 252px !important;  
padding: 0 !important; 
margin-top: 0; 
} 
相關問題