2016-11-18 69 views
0

任何想法爲什麼我無法更改縮略圖照片的大小?我希望他們全部是相同的:在畫廊中將所有縮略圖製作成相同大小

<h2>Book:</h2> 

    <div class="my-gallery" itemscope itemtype="http://schema.org/ImageGallery"> 

    <figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject"> 
     <a href="imgur/book/2EuGD9S.jpg" itemprop="contentUrl" data-size="900x900"> 
      <img src="imgur/book/2EuGD9S.jpg" itemprop="thumbnail" alt="Image description" height="300" width="300" /> 
     </a> 
              <figcaption itemprop="caption description">Image caption 1</figcaption> 

    </figure> 

    <figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject"> 
     <a href="imgur/book/Cmg3qMt.jpg" itemprop="contentUrl" data-size="900x900"> 
      <img src="imgur/book/Cmg3qMt.jpg" itemprop="thumbnail" alt="Image description" data-size="300x300" /> 
     </a> 
     <figcaption itemprop="caption description">Image caption 2</figcaption> 
    </figure> 

    <figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject"> 
     <a href="imgur/book/DyvInMR.jpg" itemprop="contentUrl" data-size="900x900"> 
      <img src="imgur/book/DyvInMR.jpg" itemprop="thumbnail" alt="Image description" data-size="300x300" /> 
     </a> 
     <figcaption itemprop="caption description">Image caption 3</figcaption> 
    </figure> 



    </div> 

完整代碼:https://gist.github.com/monajalal/3dace3489e20e0aeeba5351a7987065a 這是我所看到的: enter image description here

我使用這個:http://codepen.io/dimsemenov/pen/ZYbPJM

更新: 我改變了CSS然而,保證金的權利不會受到影響,如果我將它們設爲200x200,則不會有保證金。這是爲什麼? enter image description here

.my-gallery { 
    width: 100%; 
    float: left; 
} 
/* 
.my-gallery img { 
    width: 100%; 
    height: auto; 
} 
*/ 

.my-gallery img { 
    height: 150px; 
    width: 150px; 
    margin-right: 10px; 
} 
.my-gallery figure { 
    display: block; 
    float: left; 
    margin: 0 5px 5px 0; 
    width: 150px; 
} 
.my-gallery figcaption { 
    display: none; 
} 
+0

嘗試設置'從CSS像這樣'IMG {高度img'屬性的高度和寬度:10px的;寬度:10px; }'看看這是否可行 – Smit

+0

你是什麼意思的大小?你想要高度相等? –

+0

我希望它們都是200x200的正方形 –

回答

1

代替爲圖形指定寬度/高度,將其分配給圖像。

.my-gallery img { 
    width: 200px; 
    height: 200px; 
    display: block; 
} 
.my-gallery figure { 
    display: block; 
    float: left; 
    margin: 0 5px 5px 0; 
} 

息率這樣的顯示: enter image description here

+0

非常感謝!按預期工作! :) –

+0

好奇,如果你知道爲什麼有些照片有黑色邊框上方的白線? https://gist.github.com/monajalal/33d69aca1326f83f59a8e476a6aa62dc這裏是我所看到的:http://imgur.com/a/FLQ0k –

+1

是的,這是因爲顯示:內聯;默認。將其更改爲顯示:block;去除圖像下方的白色區域。 – haltersweb

0

你他們都設置爲相同的寬度,但由於它們的尺寸是不同的,他們將有不同的高度。如果您希望它們的高度相同,請將它們裁剪到相同的尺寸,或者通過設置高度來扭曲它們。您當前的height: auto只是保持相同的尺寸。

By the way, nice banana. 
+0

*關於香蕉異常的研究項目! –

0

你可以做這樣的事情,

... 

.my-gallery img { 
    ... 
    width: 100%; 
    min-height: 100%; 
} 

.my-gallery figure { 
    ... 
    overflow: hidden; 
    width: 200px; 
    height: 200px; 
} 
... 

注: - 但是,這將裁剪在右邊的圖像。所以這是你必須做出的決定。

1

您可以使用<a>中的圖像作爲<a>background-image。並刪除<figure>width: 150px;。看看這個Codepen

像:

CSS:

figure a { 
    display: block; 
    width: 150px; 
    height: 150px; 
    border: 10px solid #fff; 
    background-size: cover; 
} 

HTML:

<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject"> 
    <a href="https://farm3.staticflickr.com/2567/5697107145_a4c2eaa0cd_o.jpg" itemprop="contentUrl" data-size="1024x1024" style="background-image: url('https://farm3.staticflickr.com/2567/5697107145_3c27ff3cd1_m.jpg')"> 
    </a> 
    <figcaption itemprop="caption description">Image caption 1</figcaption> 
</figure> 

希望這有助於!

+0

^沒有更新我有更新,我看到這個http://imgur.com/a/Ama1l –

相關問題