2015-02-10 66 views
0

Example image of my code如何添加圖片

我想這樣做的HTML之間的平等空的空間,有圖像的DIV outter。 html;

<div class="posts-thumbnails"> 
         <img src="img/archive1.png"> 
         <img src="img/archive1.png"> 
         <img src="img/archive1.png"> 
         <img src="img/archive1.png"> 
         <img src="img/archive1.png"> 
         <img src="img/archive1.png"> 
</div> 

css;

.posts-thumbnails img{ 
width:100px; 
height:100px; 
margin:10px; 
} 

,但我不能管理圖像保證金或填充,如果我寫了這樣的事情,圖像有10 + 10 20空的空間,我怎麼能添加圖片

+0

你漂浮的圖像嗎?另外,每行總是會有3張圖片還是數字是靈活的? – 2015-02-10 01:59:05

+0

您可以將邊距添加到特定圖像,如第2和第5張圖像。 – 2015-02-10 02:04:41

+1

我確信會有現成的答案。一種簡單的方法是在圖像上應用右邊距和底邊距,然後在容器上使用填充物填充頂部和左邊距。 [就像這個例子(http://jsbin.com/qajaqi/1/edit?html,css,output) – misterManSam 2015-02-10 02:10:32

回答

1

看,至於你的問題的評論已經指出,有很多我們不知道你想做什麼,你想怎麼它到底看(浮動,圖像的數量,定位,包含div的寬度),但如果它真的只是你問的邊際,這個答案可能就足夠了。

.posts-thumbnails img{ 
width:100px; 
height:100px; 
margin:5px; 
} 

只要到您的樣式DIV。

這裏是什麼樣子(的jsfiddle):http://jsfiddle.net/manroo9c/

它通過每一個圖像周圍添加只爲5px保證金。由於上的圖像的右邊緣爲5並且在圖像的左邊右邊旁邊也如圖5所示,在端部之間的空間將是10px的之一。這種情況也適用於圖像彼此重疊的空間。

UPDATE:讓你保證金爲5px從圖像在任何方向包含div的邊框,雖然如此,如果你也想從圖像10px的距離,這裏邊框的一個更新的jsfiddle與5px的在包含分區填充:http://jsfiddle.net/manroo9c/1/

這裏的CSS代碼:

.posts-thumbnails img{ 
width:100px; 
height:100px; 
margin:5px; 
} 

.posts-thumbnails{ 
padding:5px; 
} 
+0

感謝你們偉大的答案是有用的,這對於邊距和補 – 2015-02-10 17:05:32

0

是,這是你想要做什麼??? JS FIDDLE - >https://jsfiddle.net/JTcGZ/1156/

<div id="blah"> 
     <a id="image1" href="#"><img src="http://dummyimage.com/150x150/444/fff" alt=""/></a> 
     <a id="image2" href="#"><img src="http://dummyimage.com/150x150/444/fff" alt=""/></a> 
     <a id="image3" href="#"><img src="http://dummyimage.com/150x150/444/fff" alt=""/></a> 
     <span class="stretch"></span> 
    </div> 
    <div id="blah"> 
     <a id="image1" href="#"><img src="http://dummyimage.com/150x150/444/fff" alt=""/></a> 
     <a id="image2" href="#"><img src="http://dummyimage.com/150x150/444/fff" alt=""/></a> 
     <a id="image3" href="#"><img src="http://dummyimage.com/150x150/444/fff" alt=""/></a> 
     <span class="stretch"></span> 
    </div> 


    #blah { 
     width: 540px; 
     margin-top:20px; 
     margin-left: auto; 
     margin-right: auto; 

     text-align: justify; 
     -ms-text-justify: distribute-all-lines; 
     text-justify: distribute-all-lines; 
    } 
    #blah a { 
     vertical-align: top; 
     display: inline-block; 
     *display: inline; 
     zoom: 1; 
    } 
    .stretch { 
     width: 100%; 
     display: inline-block; 
     font-size: 0; 
     line-height: 0 
    } 
+0

的理解非常有用嘿老兄,這是好的,但我不希望給uniq的IDS http://jsbin.com/qajaqi/1/edit?html,css,output這exapmle解決了我問題 – 2015-02-10 17:02:19