2016-08-26 2 views
1

Ich verwende Justified Gallery Bibliothek, um die Bilder zu rechtfertigen, ich verwende auch einen CSS-Hover-Effekt auf die Bilder, die ein FontAwesome-Symbol zeigt, wenn es überlagert.Zentrieren Sie das Symbol in der Mitte eines Bildes in einem begründeten Galerie-Layout

Das Problem ist, das Symbol erscheint an einer anderen Position über jedes Bild, weil jedes Bild eine andere Dimension hat, die durch das Justified Gallery-Plugin auf das Raster angewendet wird.

Ich möchte das Symbol an der gleichen festen Position in der Mitte jedes Bildes erscheinen lassen.

So sieht das Raster aus und wie das Symbol auf einer kleineren und größeren Miniaturansicht angezeigt wird.

JS Fiddlehttps://jsfiddle.net/halnex/3shtoyzz/3/

Hier ist mein HTML

<div id="mygallery" class="global-height scrollable"> 
    <div class="hovereffect"> 
     <img alt="Title 1" src="assets/images/posts/thumbs/post-1.jpg"/> 
     <div class="overlay"> 
      <a class="info" href="#"><i class="fa fa-info-circle fa-3x" style="color: white;"></i></a> 
     </div> 
    </div> 

    <div class="hovereffect"> 
     <img alt="Title 1" src="assets/images/posts/thumbs/post-2.jpg"/> 
     <div class="overlay"> 
      <a class="info" href="#"><i class="fa fa-info-circle fa-3x" style="color: white;"></i></a> 
     </div> 
    </div> 
    <div class="hovereffect"> 
     <img alt="Title 1" src="assets/images/posts/thumbs/post-3.jpg"/> 
     <div class="overlay"> 
      <a class="info" href="#"><i class="fa fa-info-circle fa-3x" style="color: white;"></i></a> 
     </div> 
    </div> 
</div> 

Und das ist mein CSS

.hovereffect { 
    width: 100%; 
    height: 100%; 
    float: left; 
    overflow: hidden; 
    position: relative; 
    text-align: center; 
    cursor: default; 
} 

.hovereffect .overlay { 
    width: 100%; 
    height: 100%; 
    position: absolute; 
    overflow: hidden; 
    top: 0; 
    left: 0; 
    background-color: rgba(255,255,255,0.7); 
    -webkit-transition: all 0.4s ease-in-out; 
    transition: all 0.4s ease-in-out; 
} 

.hovereffect:hover .overlay { 
    background-color: rgba(48, 152, 157, 0.1); 
} 

.hovereffect img { 
    display: block; 
    position: relative; 
} 

.hovereffect h2 { 
    text-transform: uppercase; 
    color: #fff; 
    text-align: center; 
    position: relative; 
    font-size: 17px; 
    padding: 10px; 
    background: rgba(0, 0, 0, 0.6); 
    -webkit-transform: translateY(45px); 
    -ms-transform: translateY(45px); 
    transform: translateY(45px); 
    -webkit-transition: all 0.4s ease-in-out; 
    transition: all 0.4s ease-in-out; 
} 

.hovereffect:hover h2 { 
    -webkit-transform: translateY(5px); 
    -ms-transform: translateY(5px); 
    transform: translateY(5px); 
} 

.hovereffect a.info { 
    display: inline-block; 
    text-decoration: none; 
    padding: 7px 14px; 
    text-transform: uppercase; 
    color: #fff; 
    background-color: transparent; 
    opacity: 0; 
    filter: alpha(opacity=0); 
    -webkit-transform: scale(0); 
    -ms-transform: scale(0); 
    transform: scale(0); 
    -webkit-transition: all 0.4s ease-in-out; 
    transition: all 0.4s ease-in-out; 
    font-weight: normal; 
    margin: 100px 50px; 
} 

.hovereffect:hover a.info { 
    opacity: 1; 
    filter: alpha(opacity=100); 
    -webkit-transform: scale(1); 
    -ms-transform: scale(1); 
    transform: scale(1); 
} 

.hovereffect a.info:hover { 
    /*box-shadow: 0 0 5px #fff;*/ 
} 

Die Javascript

$(document).ready(function() { 
    $("#mygallery").justifiedGallery({ 
     rowHeight : 155, 
     lastRow : 'justify', 
     margins : 0, 
     captions: false 
    }); 
}); 

enter image description here

+0

Der Code, den Sie nicht das Bild zur Verfügung gestellt überein. https://jsfiddle.net/azizn/trgLLr5h/ – Aziz

+0

Es tut mir leid, ich habe vergessen, das Javascript hinzuzufügen. Ich habe meinen Beitrag bearbeitet. Sie müssen die Justified Gallery-Bibliothek einschließen. – Halnex

Antwort

1

Versuchen Zentrierung mit display: flex

https://jsfiddle.net/ramtob/3shtoyzz/4/

ich Klassen hinzugefügt .overlay und .hovereffect diese flex Zentrierung Code:

display: flex; 
    justify-content: center; 
    align-items: center; 

Ich habe auch die Bilder (und nicht die Icons) absolut positioniert, so dass sie n tun Sie stören die Zentrierung der Icons.

+1

Vielen Dank. – Halnex

0
.info{ 
    transform: translateY(-80%); 
} 
+0

Das hat nichts geändert. – Halnex

+0

versuchen Sie setzen! Wichtig –

+0

Es funktioniert auf einige, aber nicht auf andere, das gleiche Problem. http://i.imgur.com/bTRDSTc.jpg – Halnex

0

Ändern Sie Ihre margin value für class .info zu auto. D. H. Für margin-left und margin-right.

.hovereffect a.info { 
    display: inline-block; 
    text-decoration: none; 
    padding: 7px 14px; 
    text-transform: uppercase; 
    color: #fff; 
    background-color: transparent; 
    opacity: 0; 
    filter: alpha(opacity=0); 
    -webkit-transform: scale(0); 
    -ms-transform: scale(0); 
    transform: scale(0); 
    -webkit-transition: all 0.4s ease-in-out; 
    transition: all 0.4s ease-in-out; 
    font-weight: normal; 
    margin: 100px auto;/*Made changes over-here*/ 
} 

$(document).ready(function() { 
 
    $("#mygallery").justifiedGallery({ 
 
     rowHeight : 155, 
 
     lastRow : 'justify', 
 
     margins : 0, 
 
     captions: false 
 
    }); 
 
});
.hovereffect { 
 
    width: 100%; 
 
    height: 100%; 
 
    float: left; 
 
    overflow: hidden; 
 
    position: relative; 
 
    text-align: center; 
 
    cursor: default; 
 
} 
 

 
.hovereffect .overlay { 
 
    width: 100%; 
 
    height: 100%; 
 
    position: absolute; 
 
    overflow: hidden; 
 
    top: 0; 
 
    left: 0; 
 
    background-color: rgba(255, 255, 255, 0.7); 
 
    -webkit-transition: all 0.4s ease-in-out; 
 
    transition: all 0.4s ease-in-out; 
 
} 
 

 
.hovereffect:hover .overlay { 
 
    background-color: rgba(48, 152, 157, 0.1); 
 
} 
 

 
.hovereffect img { 
 
    display: block; 
 
    position: relative; 
 
} 
 

 
.hovereffect h2 { 
 
    text-transform: uppercase; 
 
    color: #fff; 
 
    text-align: center; 
 
    position: relative; 
 
    font-size: 17px; 
 
    padding: 10px; 
 
    background: rgba(0, 0, 0, 0.6); 
 
    -webkit-transform: translateY(45px); 
 
    -ms-transform: translateY(45px); 
 
    transform: translateY(45px); 
 
    -webkit-transition: all 0.4s ease-in-out; 
 
    transition: all 0.4s ease-in-out; 
 
} 
 

 
.hovereffect:hover h2 { 
 
    -webkit-transform: translateY(5px); 
 
    -ms-transform: translateY(5px); 
 
    transform: translateY(5px); 
 
} 
 

 
.hovereffect a.info { 
 
    display: inline-block; 
 
    text-decoration: none; 
 
    padding: 7px 14px; 
 
    text-transform: uppercase; 
 
    color: #fff; 
 
    background-color: transparent; 
 
    opacity: 0; 
 
    filter: alpha(opacity=0); 
 
    -webkit-transform: scale(0); 
 
    -ms-transform: scale(0); 
 
    transform: scale(0); 
 
    -webkit-transition: all 0.4s ease-in-out; 
 
    transition: all 0.4s ease-in-out; 
 
    font-weight: normal; 
 
    margin: 100px auto; 
 
} 
 

 
.hovereffect:hover a.info { 
 
    opacity: 1; 
 
    filter: alpha(opacity=100); 
 
    -webkit-transform: scale(1); 
 
    -ms-transform: scale(1); 
 
    transform: scale(1); 
 
} 
 

 
.hovereffect a.info:hover { 
 
    /*box-shadow: 0 0 5px #fff;*/ 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="https://miromannino.github.io/Justified-Gallery/bower_components/justified-gallery/dist/js/jquery.justifiedGallery.min.js"></script> 
 
<link rel="stylesheet" href="https://miromannino.github.io/Justified-Gallery/bower_components/justified-gallery/dist/css/justifiedGallery.min.css"> 
 
<link rel="stylesheet" href=" 
 
https://miromannino.github.io/Justified-Gallery/bower_components/font-awesome/css/font-awesome.min.css 
 
"> 
 

 
<div id="mygallery" class="global-height scrollable"> 
 
    <div class="hovereffect"> 
 
    <img alt="Title 1" src="http://placehold.it/242x172" /> 
 
    <div class="overlay"> 
 
     <a class="info" href="#"><i class="fa fa-info-circle fa-3x" style="color: white;"></i></a> 
 
    </div> 
 
    </div> 
 

 
    <div class="hovereffect"> 
 
    <img alt="Title 1" src="http://placehold.it/256x172" /> 
 
    <div class="overlay"> 
 
     <a class="info" href="#"><i class="fa fa-info-circle fa-3x" style="color: white;"></i></a> 
 
    </div> 
 
    </div> 
 
    <div class="hovereffect"> 
 
    <img alt="Title 1" src="http://placehold.it/115x172" /> 
 
    <div class="overlay"> 
 
     <a class="info" href="#"><i class="fa fa-info-circle fa-3x" style="color: white;"></i></a> 
 
    </div> 
 
    </div> 
 
</div>

Verwandte Themen