2013-05-13 32 views
-1

我有一個圖像被拉出論壇(頭像),但每次我抓住他們,他們都不適合我的div,不管我做什麼,我想知道如何適應我的div內的圖像?如何在變量中設置圖像風格?

這裏是我談論行:

<div id="image">'.$ipbwi->member->photo($friend['friends_friend_id']).'</div> 

這裏是一個整體的foreach:

<?php 
$friends = $ipbwi->member->friendsList(false,true); 
foreach($friends as $friend){ 
echo ' 
<div class="friend"> 
<div id="image">'.$ipbwi->member->photo($friend['friends_friend_id']).'</div> 
<div class="username">'.$ipbwi->member->id2displayname($friend['friends_friend_id']).'</div> 
</div> 
'; 
} 
?> 

我使用ipbwi從IPB論壇中提取數據,我想規模所有的圖像(例如)40x40px。

編輯:

這裏是我使用的img上DIV的CSS:#friend #image IMG {寬度:40像素; height:40px;}

在此先感謝!

+0

* PHP(和變量)是不相關的。*看看HTML輸出。它是否有效/預期?而且,如果是這樣的話,HTML *怎樣才能用CSS來設計呢?由於個人資料圖片爲* data *,因此不適用於CSS,因此應該有''標記。數據通過'src'屬性提供給'' - 通過資源或數據URI。 – user2246674 2013-05-13 21:30:06

+0

我同意@ user2246674。如果您向我們展示您正在使用的輸出html和CSS,我們可能會有一些幫助。 – 2013-05-13 21:32:53

+0

看看這個:http://stackoverflow.com/questions/16352774/is-it-possible-to-render-an-image-in-two-sizes-with-correct-proportion/16352853#16352853 – Arbel 2013-05-13 21:41:02

回答

1

嘗試添加ST內yle規則

.friend img { max-width:100px; max-height:100px } 
0

我已經完成了這個過去。

.img-resize { 
    width: 200px; 
    height : auto; 
} 

.img-resize { 
    width: auto; 
    height : 300px; 
} 

創建CSS類img-resize,並給它的寬度和高度,你的願望。這將保持長寬比。使用像:<img src="http://example.com/12.jpg" class="img-resize" /> 然後你可以用數據庫中的值替換scr

0

使用此CSS來調整圖片的大小:

img { 
    max-width: 40px; 
    max-height: 40px; 
} 

另外,請記住這將aplly每img標記您的網頁上,因此要更具體一些,你可以這樣做:

.friend img { 
    max-width: 40px; 
    max-height: 40px; 
} 

這隻會重新大小的圖像,是一個div標籤與class「朋友」