How to align caption below each photo? - html

I'm trying to do a photo gallery when user can upload photos and display them. Multiple photos display in the same line but I want to add a caption under each and I can't manage it. Can someone help me with this?
Here's my HTML/PHP code:
$image_path is an uploaded photo and basename($image_path) is a caption
.container .gallery a img {
float: left;
position: relative;
height: 150px;
width: 20%;
border: 2px solid #fff;
-webkit-transition: -webkit-transform .15s ease;
-moz-transition: -moz-transform .15s ease;
-o-transition: -o-transform .15s ease;
-ms-transition: -ms-transform .15s ease;
transition: transform .15s ease;
object-fit: cover;
}
<div class="gallery">
<a href="<?= $image_path; ?>">
<img src="<?= $image_path; ?>">
</a>
<?=basename($image_path)?>
</div>

Try to add :
.container .gallery {
width: 20%;
position: relative;
float: left;
text-align: center;
}
and replace float:left; to float:none;& width:100%; in .container .gallery a img

I think you need something like this, it isn't ?
figure {
padding: 5px;
max-width: 150px;
margin: auto;
display: inline-block;
}
figcaption {
background-color: #222;
color: #fff;
font: italic smaller sans-serif;
text-align: center;
}
<div class="gallery">
<figure>
<a href="#">
<img src="https://via.placeholder.com/150"
alt="Elephant at sunset"></a>
<figcaption>An elephant at sunset</figcaption>
</figure>
<figure>
<a href="#">
<img src="https://via.placeholder.com/150"
alt="Elephant at sunset"></a>
<figcaption>An elephant at sunset</figcaption>
</figure>
<figure>
<a href="#">
<img src="https://via.placeholder.com/150"
alt="Elephant at sunset"></a>
<figcaption>An elephant at sunset</figcaption>
</figure>
<figure>
<a href="#">
<img src="https://via.placeholder.com/150"
alt="Elephant at sunset"></a>
<figcaption>An elephant at sunset</figcaption>
</figure>
<figure>
<a href="#">
<img src="https://via.placeholder.com/150"
alt="Elephant at sunset"></a>
<figcaption>An elephant at sunset</figcaption>
</figure>
</div>

Add one div for basename and try to apply this css into it.
.basename {
top: 90%;
left: 50%;
position: absolute;
transform: translate(-50%, -50%);
}
<div class="basename"><?=basename($image_path)?></div>

Related

Classic alignment difficulties between two row elements in the html vs css

Hello dear stack overflow citizens. I have a boring problem with two elements (watch code snippet below) but unfortunately, I ought to resolve it. I'll be grateful for any help or advice.
I need final result like this
In the circle with background: grey I positioned a relative social media links(.social__icon>img). I can’t load svg files from assets here. You can watch the screenshot with my embarrassing acts:
I don't have enough reputation to embed screenshots, I hope you can watch it somehow.
If not, it should look something like this:
social media link img margin left:12px socila media text-name also realative link img with hover and animation effects
They both needs to work like one in a row
Example
I'm facebook svg icon in the grey ellips 12px-left Facebook
Thats result with
.social__icon {
display: inline-flex; /* Changed */
align-items: center; /* Added */
enter image description here
Active mode:
enter image description here
ol,
ul,
li,
menu {
list-style: none;
}
a {
text-decoration: none;
}
.social__list {
display: flex;
flex-direction: column;
gap: 10px;
}
.social__icon {
display: inline-block;
text-align: center;
width: 26px;
height: 26px;
border-radius: 100%;
background: rgba(196, 196, 196, 0.5);
-webkit-transition: all 0.25s linear;
-moz-transition: all 0.25s linear;
-ms-transition: all 0.25s linear;
-o-transition: all 0.25s linear;
transition: all 0.25s linear;
}
.social__icon img {
vertical-align: middle;
}
.social__icon span {}
.social__icon:active {
background: #4B9200;
color: #4B9200;
}
.social__icon:hover {
animation: shake 500ms ease-in-out forwards;
}
#keyframes shake {
0% {
transform: rotate(2deg);
}
50% {
transform: rotate(-3deg);
}
70% {
transform: rotate(3deg);
}
100% {
transform: rotate(0deg);
}
}
<div class="social">
<ul class="social__list">
<li>
<a class="social__icon" href="https://en-gb.facebook.com" target="_blank" rel="noopener">
<img src="../../assets/icons/social/fb.svg" alt="">
<span>Facebook</span>
</a>
</li>
<li>
<a class="social__icon" href="https://twitter.com" target="_blank" rel="noopener">
<img src="../../assets/icons/social/twtr.svg" alt="">
<span>Twitter</span>
</a>
</li>
<li>
<a class="social__icon" href="https://www.instagram.com" target="_blank" rel="noopener">
<img src="../../assets/icons/social/inst.svg" alt="">
<span>Instagram</span>
</a>
</li>
<li>
<a class="social__icon" href="https://www.youtube.com" target="_blank" rel="noopener">
<img src="../../assets/icons/social/youtube.svg" alt="">
<span>Youtube</span>
</a>
</li>
</ul>
</div>
Some style issues in the image
ol,
ul,
li,
menu {
list-style: none;
}
a {
text-decoration: none;
}
.social__list {
display: flex;
flex-direction: column;
gap: 10px;
}
.social__icon {
display: inline-block;
text-align: center;
-webkit-transition: all 0.25s linear;
-moz-transition: all 0.25s linear;
-ms-transition: all 0.25s linear;
-o-transition: all 0.25s linear;
transition: all 0.25s linear;
}
.social__icon img {
width: 26px;
height: 26px;
vertical-align: middle;
border-radius: 100%;
background: rgba(196, 196, 196, 0.5);
}
.social__icon:active {
background: #4b9200;
color: #4b9200;
}
.social__icon:hover {
animation: shake 500ms ease-in-out forwards;
}
#keyframes shake {
0% {
transform: rotate(2deg);
}
50% {
transform: rotate(-3deg);
}
70% {
transform: rotate(3deg);
}
100% {
transform: rotate(0deg);
}
}
<div class="social">
<ul class="social__list">
<li>
<a
class="social__icon"
href="https://en-gb.facebook.com"
target="_blank"
rel="noopener"
>
<img
src="https://cdn3.iconfinder.com/data/icons/free-social-icons/67/facebook_circle_color-512.png"
alt=""
/>
<span>Facebook</span>
</a>
</li>
<li>
<a
class="social__icon"
href="https://twitter.com"
target="_blank"
rel="noopener"
>
<img
src="https://cdn4.iconfinder.com/data/icons/social-media-icons-the-circle-set/48/twitter_circle-512.png"
alt=""
/>
<span>Twitter</span>
</a>
</li>
<li>
<a
class="social__icon"
href="https://www.instagram.com"
target="_blank"
rel="noopener"
>
<img
src="https://cdn2.iconfinder.com/data/icons/social-media-applications/64/social_media_applications_3-instagram-512.png"
alt=""
/>
<span>Instagram</span>
</a>
</li>
<li>
<a
class="social__icon"
href="https://www.youtube.com"
target="_blank"
rel="noopener"
>
<img
src="https://cdn4.iconfinder.com/data/icons/logos-and-brands/512/395_Youtube_logo-512.png"
alt=""
/>
<span>Youtube</span>
</a>
</li>
</ul>
</div>

How can I overlap an image with text, but both of them are inside the same anchor tag?

I'm kind of new to css and html, never touched JS or jquery.
I'm building as practice a website that looks like somewhat a portfolio site where I have some photos that are clickable. One thing that I wanted to do is, when a user hovers an image, an opaque box would pop up from the photo's bottom showing some text, the problem is that I want this text to be clickable as well so I put it inside the same anchor tag, but they don't overlap instead the clickable area stretches and the text gets positioned to the side of the image.
Is there a way of doing it so the "clickable area" doesn't stretch and the text overlap the image but without using the image as a background ?
Here's what I'm trying to achieve https://theme-frsch2.tumblr.com/ .
I've tried wrapping the text in a div and moving the text so it would overlap the image but the problem is that the "clickable" area would still be stretched anyway.
And this is what I got so far.
HTML
#allimg{
display: flex;
flex-wrap: wrap;
justify-content: center;
}
#allimg a{
margin: 10px;
border: 2px solid red;
}
#allimg img{
transition: 0.1s ease;
box-shadow: 5px 5px 10px #888888;
float: left;
border: 1px solid pink;
}
#allimg img:hover{
transform: scale(1.02);
}
#allimg a p{
color: black;
position: relative;
bottom: 20px;
left: 0;
text-align: center;
}
<div id="allimg">
<a href="link1">
<img src="https://via.placeholder.com/150" alt="">
<p>
Text1
</p>
</a>
<a href="link2">
<img src="https://via.placeholder.com/150" alt="">
<p>
Text2
</p>
</a>
<a href="link3">
<img src="https://via.placeholder.com/150" alt="">
<p>
Text3
</p>
</a>
<a href="link4">
<img src="https://via.placeholder.com/150" alt="">
<p>
Text4
</p>
</a>
</div>
Here is jsfiddel link
If you want to overlap text inside an image and achieve that hover effect on the website you attached
you have to use position: absolute for your text
and set the position for your anchor tag to relative
make it hideen by setting visibility property to hidden and opacity
to 0
then on anchor tag hover, you set it back visible and 1 opacity
#allimg{
display: flex;
flex-wrap: wrap;
justify-content: center;
}
#allimg a{
margin: 10px;
border: 2px solid red;
position: relative;
}
#allimg img{
transition: 0.1s ease;
box-shadow: 5px 5px 10px #888888;
float: left;
border: 1px solid pink;
}
#allimg img:hover{
transform: scale(1.02);
}
#allimg a p{
color: black;
position: absolute;
bottom: 0;
left: 0;
margin: 0;
text-align: center;
width: 100%;
padding: 10px 0;
background: rgba(255,255,255,.5);
visibility: hidden;
opacity: 0;
transition: .2s ease-in-out;
}
#allimg a:hover p{
visibility: visible;
opacity: 1
}
<div id="allimg">
<a href="link1">
<img src="https://via.placeholder.com/150" alt="">
<p>
Text1
</p>
</a>
<a href="link2">
<img src="https://via.placeholder.com/150" alt="">
<p>
Text2
</p>
</a>
<a href="link3">
<img src="https://via.placeholder.com/150" alt="">
<p>
Text3
</p>
</a>
<a href="link4">
<img src="https://via.placeholder.com/150" alt="">
<p>
Text4
</p>
</a>
</div>
Put the image in parent container and text in child container, then in css file add 'position:relative' to the parent container and add 'position:absolute' to the child container.
This will overlap text and image.
Somewhat like this:
HTML Part:
<div class="parent">
<img src="https://via.placeholder.com/150" alt="image">
<div class="child">
<p>Text goes here</p>
</div>
</div>
CSS Part:
.parent
{
position:relative;
text-align:center;
}
.child
{
position:absolute;
top:0px;
left:0px;
}
This will overlap text on image and you make changes as you want in the position of the text.
Here's my solution with smooth transition.
#allimg{
display: flex;
flex-wrap: wrap;
justify-content: center;
}
#allimg a{
position: relative;
margin: 10px;
border: 2px solid red;
box-sizing: border-box;
transition: all 0.3s ease;
}
#allimg img{
position: abosolute;
vertical-align: bottom;
transition: 0.1s ease;
box-shadow: 5px 5px 10px #888888;
border: 1px solid pink;
transition: all 0.3s ease;
}
#allimg img:hover{
transform: scale(1.02);
}
#allimg a p{
margin: 0;
padding: 5% 0;
width: 100%;
color: black;
background-color: #fff;
box-sizing: border-box;
position: absolute;
text-align: center;
bottom: 0;
left: 0;
opacity: 0;
transition: all 0.3s ease;
}
#allimg a:hover{
transform: scale(1.1);
transition: all 0.3s ease;
}
#allimg a:hover p{
opacity: 1;
transition: all 0.6s ease;
}
<div id="allimg">
<a href="link1">
<img src="https://via.placeholder.com/150" alt="">
<p>
Text1
</p>
</a>
<a href="link2">
<img src="https://via.placeholder.com/150" alt="">
<p>
Text2
</p>
</a>
<a href="link3">
<img src="https://via.placeholder.com/150" alt="">
<p>
Text3
</p>
</a>
<a href="link4">
<img src="https://via.placeholder.com/150" alt="">
<p>
Text4
</p>
</a>
</div>

Responsive image with text overlay

I am trying to make a grid where the images have an overlay on hover, containing text.
However, I can't seem to do this AND have responsive issues.
I've tried removing the fixed heights but this just causes the grids to loose their sizing all together. I have tried tables and absolute positioning without any joy.
Test site is here.
The markup is:
<div class="work-item clickable">
<div class="front">
<img width="460" height="380" src="http://localhost:8888/wp-content/uploads/2016/02/stock-photo-4772348-1500x1000-460x380.jpg" class="attachment-work-featured-image size-work-featured-image" alt="stock-photo-4772348-1500x1000" />
</div>
<div class="back">
<div class="inner">
<h3>Lorem ipsum dolor sit amet</h3>
</div>
</div>
</div>
CSS:
section#homepage .content article .work-item {
cursor: pointer;
border-right: 20px solid #fff;
border-bottom: 20px solid #fff;
float: left;
overflow: hidden;
position: relative;
width: 33.33%;
}
section#homepage .content article .work-item .front {
color: #fff;
width: 100%;
z-index: 50;
opacity: 1;
-webkit-transition: all 300ms ease-out;
-moz-transition: all 300ms ease-out;
-o-transition: all 300ms ease-out;
-ms-transition: all 300ms ease-out;
transition: all 300ms ease-out;
}
section#homepage .content article .work-item .back {
display: table;
width: 100%;
opacity: 0;
z-index: 25;
position: absolute;
}
section#homepage .content article .work-item .back .inner {
display: table-cell;
padding: 20px;
vertical-align: middle;
}
Here is an example layout, based on your example, which includes overlapping text on hover of an image.
The <figure> element seems good for this. It needs an image and a <figcaption>. Let's wrap it in an anchor tag so the entire image is clickable:
<a>
<figure>
<img />
<figcaption></figcaption>
</figure>
</a>
The CSS
The anchor element can line up the images. The width is 33.33% so that there are 3 images to a row. The images can be spaced with some padding here as well:
a {
display: inline-block;
width: 33.33%;
vertical-align: top;
padding: 10px;
}
The figure is made position: relative so that the position: absolute figcaption is positioned relative to it. This will ensure that the text is layered over the image. We can center it vertically with top: 50% and the transform to offset it correctly:
figure {
position: relative;
}
figcaption {
position: absolute;
text-align: center;
top: 50%;
right: 0;
left: 0;
transform: translateY(-50%);
}
The image takes up the entire width of its parent:
figure img {
width: 100%;
display: block;
}
Full example
*,
*:before,
*:after {
margin: 0;
padding: 0;
box-sizing: inherit;
}
html {
box-sizing: border-box;
}
body {
min-width: 600px;
}
a {
display: inline-block;
width: 33.33%;
vertical-align: top;
padding: 10px;
}
figure {
position: relative;
transition: opacity .2s;
}
figure:before {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: rgba(0, 0, 0, 0.4);
content: '';
opacity: 0;
transition: inherit;
}
figcaption {
position: absolute;
text-align: center;
top: 50%;
right: 0;
left: 0;
transform: translateY(-50%);
opacity: 0;
transition: inherit;
}
figcaption h2 {
font-size: 3vw;
}
figcaption p {
font-size: 2vw;
}
a {
color: #FFF;
text-decoration: none;
}
figure img {
width: 100%;
display: block;
}
figure:hover:before,
figure:hover figcaption {
opacity: 1;
}
<a href="http://dev.charlyanderson.co.uk/Testing/work-example-client-name-12/">
<figure>
<img src="http://dev.charlyanderson.co.uk/Testing/wp-content/uploads/2016/02/stock-photo-4772348-1500x1000-460x380.jpg" class="attachment-work-featured-image size-work-featured-image" alt="stock-photo-4772348-1500x1000" />
<figcaption>
<h2>Lorem ipsum dolor sit amet</h2>
<p>More text here, plenty of space</p>
</figcaption>
</figure>
</a><a href="http://dev.charlyanderson.co.uk/Testing/work-example-client-name-12/">
<figure>
<img src="http://dev.charlyanderson.co.uk/Testing/wp-content/uploads/2016/02/stock-photo-4772348-1500x1000-460x380.jpg" class="attachment-work-featured-image size-work-featured-image" alt="stock-photo-4772348-1500x1000" />
<figcaption>
<h2>Lorem ipsum dolor sit amet</h2>
<p>More text here, plenty of space</p>
</figcaption>
</figure>
</a><a href="http://dev.charlyanderson.co.uk/Testing/work-example-client-name-12/">
<figure>
<img src="http://dev.charlyanderson.co.uk/Testing/wp-content/uploads/2016/02/stock-photo-4772348-1500x1000-460x380.jpg" class="attachment-work-featured-image size-work-featured-image" alt="stock-photo-4772348-1500x1000" />
<figcaption>
<h2>Lorem ipsum dolor sit amet</h2>
<p>More text here, plenty of space</p>
</figcaption>
</figure>
</a><a href="http://dev.charlyanderson.co.uk/Testing/work-example-client-name-12/">
<figure>
<img src="http://dev.charlyanderson.co.uk/Testing/wp-content/uploads/2016/02/stock-photo-4772348-1500x1000-460x380.jpg" class="attachment-work-featured-image size-work-featured-image" alt="stock-photo-4772348-1500x1000" />
<figcaption>
<h2>Lorem ipsum dolor sit amet</h2>
<p>More text here, plenty of space</p>
</figcaption>
</figure>
</a><a href="http://dev.charlyanderson.co.uk/Testing/work-example-client-name-12/">
<figure>
<img src="http://dev.charlyanderson.co.uk/Testing/wp-content/uploads/2016/02/stock-photo-4772348-1500x1000-460x380.jpg" class="attachment-work-featured-image size-work-featured-image" alt="stock-photo-4772348-1500x1000" />
<figcaption>
<h2>Lorem ipsum dolor sit amet</h2>
<p>More text here, plenty of space</p>
</figcaption>
</figure>
</a><a href="http://dev.charlyanderson.co.uk/Testing/work-example-client-name-12/">
<figure>
<img src="http://dev.charlyanderson.co.uk/Testing/wp-content/uploads/2016/02/stock-photo-4772348-1500x1000-460x380.jpg" class="attachment-work-featured-image size-work-featured-image" alt="stock-photo-4772348-1500x1000" />
<figcaption>
<h2>Lorem ipsum dolor sit amet</h2>
<p>More text here, plenty of space</p>
</figcaption>
</figure>
</a>
Text size: The text can be made to re-size to suit the image width using vw as a font-size.
Image size: Place a min width on the body so that the images don't get too small.
Overlay background: This is provided with the figure:before element.
Note: The <a> elements have no whitespace between them, this prevents an inline gap. The box-sizing: border-box incorporates padding and borders into the width and height calculation.
maybe you could rethink your html structure about links and images, and play with absolute positionning for either image or title.
example:
body {
text-align: center;
}
.work-item {
display: inline-block;
vertical-align: top;
width: 25%;
margin: 1em;
}
a {
display: inline-table;
border: solid;
width: 100%;
color: black;
text-decoration: none;
}
figure {
position: relative;
display: table-row;
}
figure img {
width: 100%;
height: 100%;
top: 0;
position: absolute;
transition: 0.5s
}
figcaption:before {
content: '';
display: inline-block;
vertical-align: middle;
width: 0;
padding-top: 92%;
}
figcaption {
display: table-cell;
}
figure:hover img {
opacity: 0;
}
figcaption h3 {
display: inline-block;
max-width: 98%;
margin: 0 -2%;
vertical-align: middle;
}
<div class="work-item clickable">
<a href="http://dev.charlyanderson.co.uk/Testing/work-example-client-name-12/">
<figure>
<img width="460" height="380" src="http://dev.charlyanderson.co.uk/Testing/wp-content/uploads/2016/02/stock-photo-4772348-1500x1000-460x380.jpg" class="attachment-work-featured-image size-work-featured-image" alt="stock-photo-4772348-1500x1000" />
<figcaption>
<h3>Lorem ipsum dolor sit amet</h3>
</figcaption>
</figure>
</a>
</div>
<div class="work-item clickable">
<a href="http://dev.charlyanderson.co.uk/Testing/work-example-client-name-12/">
<figure>
<img src="http://dev.charlyanderson.co.uk/Testing/wp-content/uploads/2016/02/stock-photo-4772348-1500x1000-460x380.jpg" class="attachment-work-featured-image size-work-featured-image" alt="stock-photo-4772348-1500x1000" />
<figcaption>
<h3>Lorem ipsum dolor sit amet</h3>
</figcaption>
</figure>
</a>
</div>
<div class="work-item clickable">
<a href="http://dev.charlyanderson.co.uk/Testing/work-example-client-name-12/">
<figure>
<img width="460" height="380" src="http://dev.charlyanderson.co.uk/Testing/wp-content/uploads/2016/02/stock-photo-4772348-1500x1000-460x380.jpg" class="attachment-work-featured-image size-work-featured-image" alt="stock-photo-4772348-1500x1000" />
<figcaption>
<h3>Lorem ipsum dolor sit amet</h3>
</figcaption>
</figure>
</a>
</div>
<div class="work-item clickable">
<a href="http://dev.charlyanderson.co.uk/Testing/work-example-client-name-12/">
<figure>
<img width="460" height="380" src="http://dev.charlyanderson.co.uk/Testing/wp-content/uploads/2016/02/stock-photo-4772348-1500x1000-460x380.jpg" class="attachment-work-featured-image size-work-featured-image" alt="stock-photo-4772348-1500x1000" />
<figcaption>
<h3>Lorem ipsum dolor sit amet</h3>
</figcaption>
</figure>
</a>
</div>
</div>
<div class="work-item clickable">
<a href="http://dev.charlyanderson.co.uk/Testing/work-example-client-name-12/">
<figure>
<img src="http://dev.charlyanderson.co.uk/Testing/wp-content/uploads/2016/02/stock-photo-4772348-1500x1000-460x380.jpg" class="attachment-work-featured-image size-work-featured-image" alt="stock-photo-4772348-1500x1000" />
<figcaption>
<h3>Lorem ipsum dolor sit amet</h3>
</figcaption>
</figure>
</a>
</div>
<div class="work-item clickable">
<a href="http://dev.charlyanderson.co.uk/Testing/work-example-client-name-12/">
<figure>
<img width="460" height="380" src="http://dev.charlyanderson.co.uk/Testing/wp-content/uploads/2016/02/stock-photo-4772348-1500x1000-460x380.jpg" class="attachment-work-featured-image size-work-featured-image" alt="stock-photo-4772348-1500x1000" />
<figcaption>
<h3>Lorem ipsum dolor sit amet</h3>
</figcaption>
</figure>
</a>
</div>
Hope this works for you!
jsfiddle
HTML
<a href="#" class="outer">
<div class="inner"><img src="http://farm9.staticflickr.com/8311/8023199579_f52f648727_m.jpg"></div>
<div class="overlay">Text</div>
</a>
<a href="#" class="outer">
<div class="inner"><img src="http://farm9.staticflickr.com/8311/8023199579_f52f648727_m.jpg"></div>
<div class="overlay">Text</div>
</a>
<a href="#" class="outer">
<div class="inner"><img src="http://farm9.staticflickr.com/8311/8023199579_f52f648727_m.jpg"></div>
<div class="overlay">Text</div>
</a>
CSS
.outer {
width: 33.333%;
overflow: auto;
float: left;
position: relative;
}
.outer .inner {
display: block;
margin: 10px;
}
.outer .inner img {
width: 100%;
height: auto;
border: 0px;
display: block;
}
.outer .overlay {
position: absolute;
top: 0;
opacity: 0;
width:100%;
height:100%;
background-color:pink;
-webkit-transition: opacity .15s ease-in-out;
-moz-transition: opacity .15s ease-in-out;
-ms-transition: opacity .15s ease-in-out;
-o-transition: opacity .15s ease-in-out;
transition: opacity .15s ease-in-out;
}
.outer:hover .overlay {
opacity: 0.7;
}
Your outer would be of coarse your article tag

I want to merge two cells together in the proposed html layout

I'm using this layout and as you can see there is a section with 8 pictures on the bottom of the page - each of them is a hyperlink to the bigger image. It works pretty neat, esp. when you resize the page to smaller size, then the 4 cells becomes 2 and it looks like this. I want to change it a little, so that two first pictures are merged together, so the layout could look like this, and when the user resizes it, it would show him a proper layout like this. So far the html code for that specific part of the page looks like this:
<section class="screenshots" id="screenshots">
<div class="container-fluid">
<div class="row">
<ul class="grid">
<li>
<figure>
<img src="img/02-screenshot.jpg" alt="Screenshot 01">
<figcaption>
<div class="caption-content">
<a href="img/large/02.jpg" class="single_image">
<i class="fa fa-search"></i><br>
<p>User Centric Design</p>
</a>
</div>
</figcaption>
</figure>
</li>
<li>
<figure>
<img src="img/03-screenshot.jpg" alt="Screenshot 01">
<figcaption>
<div class="caption-content">
<a href="img/large/03.jpg" class="single_image">
<i class="fa fa-search"></i><br>
<p>Responsive and Adaptive</p>
</a>
</div>
</figcaption>
</figure>
</li>
<li>
<figure>
<img src="img/04-screenshot.jpg" alt="Screenshot 01">
<figcaption>
<div class="caption-content">
<a href="img/large/04.jpg" class="single_image">
<i class="fa fa-search"></i><br>
<p>Absolutely Free</p>
</a>
</div>
</figcaption>
</figure>
</li>
</ul>
</div>
<div class="row">
<ul class="grid">
<li>
<figure>
<img src="img/06-screenshot.jpg" alt="Screenshot 01">
<figcaption>
<div class="caption-content">
<a href="img/large/06.jpg" class="single_image">
<i class="fa fa-search"></i><br>
<p>Exclusive to Codrops</p>
</a>
</div>
</figcaption>
</figure>
</li>
<li>
<figure>
<img src="img/07-screenshot.jpg" alt="Screenshot 01">
<figcaption>
<div class="caption-content">
<a href="img/large/07.jpg" class="single_image">
<i class="fa fa-search"></i><br>
<p>Made with Love</p>
</a>
</div>
</figcaption>
</figure>
</li>
<li>
<figure>
<img src="img/08-screenshot.jpg" alt="Screenshot 01">
<figcaption>
<div class="caption-content">
<a href="img/large/08.jpg" class="single_image">
<i class="fa fa-search"></i><br>
<p>In Sydney, Australia</p>
</a>
</div>
</figcaption>
</figure>
</li>
</ul>
</div>
</div>
</section>
and the css code looks like this:
/* ==========================================================================
Screenshots Intro
========================================================================== */
.screenshots-intro {
padding: 170px 0 100px 0;
background-color: #f6f7f9;
}
.screenshots-intro h1 {
margin-bottom: 20px;
color: #24374b;
font-weight: 400;
font-size: 22px;
}
.screenshots-intro p {
margin-bottom: 25px;
color: #778899;
}
/* ==========================================================================
Screenshots
========================================================================== */
.screenshots ul {
margin: 0;
padding: 0;
width: 100%;
}
.screenshots ul li {
float: left;
min-height: 100%;
width: 25%;
background-color: #000;
list-style: none;
}
.screenshots figure {
position: relative;
overflow: hidden;
}
.screenshots figure img {
width: 100%;
height: 100%;
-webkit-transition: all 300ms ease-in-out;
transition: all 300ms ease-in-out;
}
.screenshots figure:hover img, .screenshots figure:focus img {
-webkit-transform: scale(1.1);
-ms-transform: scale(1.1);
transform: scale(1.1);
}
.screenshots figcaption {
position: absolute;
top: 0;
left: 0;
padding: 25% 0;
width: 100%;
height: 100%;
background-color: rgba(63, 97, 132, 0.85);
text-align: center;
font-size: 15px;
opacity: 0;
-webkit-transition: all 300ms ease-in-out;
transition: all 300ms ease-in-out;
}
.screenshots figcaption a {
color: #fff
}
.screenshots figcaption a:hover, .screenshots figcaption a:focus {
color: #73d0da
}
.screenshots figure:hover figcaption, .screenshots figure:focus figcaption {
opacity: 1
}
.visible {
opacity: 1
}
.screenshots figure.cs-hover figcaption {
opacity: 1
}
.screenshots figcaption i {
font-size: 35px
}
.screenshots figcaption p {
margin-bottom: 0;
text-transform: uppercase;
font-weight: 400;
}
.screenshots figcaption .caption-content {
position: absolute;
top: 50%;
left: 50%;
margin-top: -40px;
margin-left: -100px;
width: 200px;
-webkit-transform: translate(0px, 15px);
-ms-transform: translate(0px, 15px);
transform: translate(0px, 15px);
-webkit-transition: all 300ms ease-in-out;
transition: all 300ms ease-in-out;
}
.screenshots figure:hover figcaption .caption-content, .screenshots figure:focus figcaption .caption-content {
-webkit-transform: translate(0px, 0px);
-ms-transform: translate(0px, 0px);
transform: translate(0px, 0px);
}
I know it's a lot of code, but maybe anyone of you have the idea of how to change this particular part of the layout to have it as I included in the pictures? Thanks.
This is the updated answer.
I am attaching the code and jsfiddle link with it.
Just replace the src of the images with yours to see the results.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<style type="text/css">
.container {
width: 100%;
margin: 0 auto;
}
img {
max-width: 100%;
}
/* this css is just for understanding */
.a {
background-color: red;
}
.b {
background-color: green;
}
.c {
background-color: blue;
}
.d {
background-color: black;
}
/* this css is just for understanding */
/* this is the logic to change the positions of image */
#media (min-width: 320px) {
.a,
.b,
.c,
.d {
width: 100%;
float: left;
}
}
#media (min-width: 768px) {
.a,
.b,
.c,
.d {
width: 50%;
float: left;
}
}
</style>
<body>
<div class="container">
<div class="a">
<img src="img/1.png" height="222" width="581">
</div>
<div class="b">
<img src="img/2.jpg" height="222" width="581">
</div>
<div class="c">
<img src="img/3.jpg" height="222" width="581">
</div>
<div class="d">
<img src="img/4.png" height="222" width="581">
</div>
</div>
</body>
</html>
this is the jsfiddle link

Why all my styles go wrong when I add figcaption?

I have a gallery on my site, but when I add figcaption it all goes wrong and each picture becomes central. What have I done incorrectly? I really can not imagine how to improve it.
#image{
position: inherit;
width:300px;
-webkit-transition:all 1s;
transition:all 1s;
margin-top:10px;
}
#image:hover{
position: inherit;
-webkit-transform:scale(3);
transform:scale(3);
margin: 0 auto;
highslide: auto;
}
figure.img img {
max-width: 300px;
height: auto;
}
figure.img figcaption {
padding: 5px;
font: bold italic 90% Georgia,serif;
color: #17432e;
width: 300px;
margin-left: 0px;
}
.pictures {
margin: 100px auto;
width: 980px;
}
.clear {
clear: both;
}
Then in body I have after all changes according to your advice
<div align="center">
<figure class="img">
<img id="image" src="pics/1.jpg" class="passe-partout">
<figcaption>In the village</figcaption>
</figure>
<figure class="img">
<img id="image" src="pics/2.jpg" class="passe-partout">
<figcaption>August</figcaption>
</figure>
<figure class="img">
<img id="image" src="pics/3.jpg" class="passe-partout">
<figcaption>The bridge</figcaption>
</figure>
<figure class="img">
<img id="image" src="pics/4.jpg" class="passe-partout">
<figcaption>A cute house</figcaption>
</figure>
<div class="clear"></div>
</div>
Here is the working solution.
---CSS Code--
figure img{
position: inherit;
width:300px;
-webkit-transition:all 1s;
transition:all 1s;
margin-top:10px;
}
figure img:hover{
position: inherit;
-webkit-transform:scale(3);
transform:scale(3);
margin: 0 auto;
highslide: auto;
}
figure> figcaption {
padding: 5px;
font: bold italic 90% Georgia,serif;
color: #17432e;
width: 300px;
margin-left: 0px;
}
/----HTML Code -----/
<div align=center class="pictures">
<figure class="img">
<img id="image" src="http://lorempixel.com/200/200" class="passe-partout">
<figcaption>In the village</figcaption>
</figure>
<figure class="img">
<img id="image" src="http://lorempixel.com/200/200" class="passe-partout">
<figcaption>In the village</figcaption>
</figure>
<figure class="img">
<img id="image" src="http://lorempixel.com/200/200" class="passe-partout">
<figcaption>In the village</figcaption>
</figure>
</div>
Here is a Working Demo. http://jsbin.com/musovipo/1/
I've made the code more valid by removing the multiple identical id's
and wrapping each img/figcaption pair with a figure element. To show the figures on same line, display: inline-block was added to the figure elements
CSS
div.img img {
width: 300px;
max-width: 300px;
height: auto;
position: inherit;
-webkit-transition: all 1s;
transition: all 1s;
margin-top: 10px;
}
div.img img:hover {
position: inherit;
-webkit-transform: scale(3);
transform: scale(3);
margin: 0 auto;
highslide: auto;
}
div.img figcaption {
padding: 5px;
font: bold italic 90% Georgia,serif;
color: #17432e;
width: 300px;
margin-left: 0px;
}
div.img figure {
display: inline-block;
}
HTML
<div class="img">
<div align=center class="pictures">
<figure>
<img src="pics/1.jpg" class="passe-partout">
<figcaption>In the village</figcaption>
</figure>
<figure>
<img src="pics/2.jpg" class="passe-partout">
<figcaption>August</figcaption>
</figure>
<figure>
<img src="pics/3.jpg" class="passe-partout">
<figcaption>The bridge</figcaption>
</figure>
<figure>
<img src="pics/4.jpg" class="passe-partout">
<figcaption>A cute house</figcaption>
</figure>
<div class="clear"></div>
</div>
</div>