I got a problem with my html project. When I hoover an image it gets larger but it does not cover images next to each other. (only left one)
https://i.imgur.com/oNP4gHA.png
https://i.imgur.com/g2zIoSr.png
CSS:
.photo {
margin: 10px 0;
width: 120px;
background: white;
padding: 10px;
opacity: 1;
border-radius: 5px;
border: 1px solid silver;
box-sizing: border-box;
justify-content: space-around;
flex-wrap: wrap;
transform: rotate(5deg);
transition: 0.3s all ease-in-out;
will-change: transform;
align-items: flex-start;
display: inline-flex;
}
.photo img {
flex-basis: 100%;
width: 100px;
}
.photo figcaption {
margin-top: 10px;
}
.photo:nth-child(even) {
transform: rotate(-5deg) scale(0.8);
}
.photo:hover {
opacity: 1;
transform: scale(2.0);
z-index: 10;
}
HTML
{% for i in zdjecie %}
<figure class="photo" >
<img src="{{i.url}}"
alt="Kotek Robert">
<figcaption>
{{i.title}}
</figcaption>
</figure>
{% endfor %}
z-index won't function as expected on objects with static positioning.
Add position: relative to your .photo elements to fix the issue:
.photo {
margin: 10px 0;
width: 120px;
background: white;
padding: 10px;
opacity: 1;
border-radius: 5px;
border: 1px solid silver;
box-sizing: border-box;
justify-content: space-around;
flex-wrap: wrap;
transform: rotate(5deg);
transition: 0.3s all ease-in-out;
will-change: transform;
align-items: flex-start;
display: inline-flex;
position: relative; /* add this */
}
.photo img {
flex-basis: 100%;
width: 100px;
}
.photo figcaption {
margin-top: 10px;
}
.photo:nth-child(even) {
transform: rotate(-5deg) scale(0.8);
}
.photo:hover {
opacity: 1;
transform: scale(2.0);
z-index: 10;
}
<figure class="photo">
<img src="{{i.url}}" alt="Kotek Robert">
<figcaption>
{{i.title}}
</figcaption>
</figure>
<figure class="photo">
<img src="{{i.url}}" alt="Kotek Robert">
<figcaption>
{{i.title}}
</figcaption>
</figure>
<figure class="photo">
<img src="{{i.url}}" alt="Kotek Robert">
<figcaption>
{{i.title}}
</figcaption>
</figure>
<figure class="photo">
<img src="{{i.url}}" alt="Kotek Robert">
<figcaption>
{{i.title}}
</figcaption>
</figure>
<figure class="photo">
<img src="{{i.url}}" alt="Kotek Robert">
<figcaption>
{{i.title}}
</figcaption>
</figure>
<figure class="photo">
<img src="{{i.url}}" alt="Kotek Robert">
<figcaption>
{{i.title}}
</figcaption>
</figure>
<figure class="photo">
<img src="{{i.url}}" alt="Kotek Robert">
<figcaption>
{{i.title}}
</figcaption>
</figure>
<figure class="photo">
<img src="{{i.url}}" alt="Kotek Robert">
<figcaption>
{{i.title}}
</figcaption>
</figure>
<figure class="photo">
<img src="{{i.url}}" alt="Kotek Robert">
<figcaption>
{{i.title}}
</figcaption>
</figure>
<figure class="photo">
<img src="{{i.url}}" alt="Kotek Robert">
<figcaption>
{{i.title}}
</figcaption>
</figure>
Related
Blockquote Hello, I'm trying to make a responsive img grid with the following : 2 imgs at the top, sharing 50% of the space, and 4 imgs underneath with the same aspect ratio.
The grid works just fine, until I've decided to add a small caption. What am I doing wrong ?
Thank you, have a nice one,
Kieran.
body {
padding: 0px;
font-family: sans-serif;
background: #f2f2f2;
height: 100%;
}
.first-row {
border: 3px solid green;
float:left;
width: 100%;
}
.grid-container1 h3 {
font-size: 1rem;
padding: 5px;
float: bottom;
}
.grid-container1 {
border: 1px solid red;
}
.grid-container1 img {
display:inline-block;
vertical-align:middle;
width: 50%;
padding: 5px;
}
.grid-container2 img {
vertical-align: top;
width: 25%;
float: left;
padding: 5px;
}
.grid-container3 img {
vertical-align: top;
width: 33.33%;
float: left;
padding: 5px;
}
<div class="grid-container1">
<a href="#">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/210284/san-fransisco-768x432.jpg" alt="san francisco">
</a>
<h3>lorem ipsum</h3>
</div>
<div class="grid-container1">
<a href="#">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/210284/san-fransisco-768x432.jpg" alt="san francisco">
</a>
<h3>lorem ipsum</h3>
</div>
<div class="grid-container2">
<a href="#">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/210284/san-fransisco-768x432.jpg" alt="san francisco">
</a>
<h3>lorem ipsum</h3>
</div>
<div class="grid-container2">
<a href="#">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/210284/san-fransisco-768x432.jpg" alt="san francisco">
</a>
<h3>lorem ipsum</h3>
</div>
<div class="grid-container2">
<a href="#">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/210284/san-fransisco-768x432.jpg" alt="san francisco">
</a>
<h3>lorem ipsum</h3>
</div>
<div class="grid-container2">
<a href="#">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/210284/san-fransisco-768x432.jpg" alt="san francisco">
</a>
<h3>lorem ipsum</h3>
</div>
body {
padding: 0px;
font-family: sans-serif;
background: #f2f2f2;
height: 100%;
}
.grid-container {
display: grid;
border: 1px solid red;
grid-template-columns: repeat(4, 1fr);
grid-template-rows: 1fr, 1fr;
padding: 5px;
gap: 5px;
}
.grid-container figure {
margin: 0;
}
.grid-container figure:nth-child(1) {
grid-column: 1 / 3;
}
.grid-container figure:nth-child(2) {
grid-column: 3 / 5;
}
.grid-container img {
display: block;
width: 100%;
height: auto;
}
<div class="grid-container">
<figure>
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/210284/san-fransisco-768x432.jpg" alt="san francisco">
<figcaption>lorem ipsum</figcaption>
</figure>
<figure>
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/210284/san-fransisco-768x432.jpg" alt="san francisco">
<figcaption>lorem ipsum</figcaption>
</figure>
<figure>
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/210284/san-fransisco-768x432.jpg" alt="san francisco">
<figcaption>lorem ipsum</figcaption>
</figure>
<figure>
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/210284/san-fransisco-768x432.jpg" alt="san francisco">
<figcaption>lorem ipsum</figcaption>
</figure>
<figure>
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/210284/san-fransisco-768x432.jpg" alt="san francisco">
<figcaption>lorem ipsum</figcaption>
</figure>
<figure>
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/210284/san-fransisco-768x432.jpg" alt="san francisco">
<figcaption>lorem ipsum</figcaption>
</figure>
</div>
Try this:
body {
padding: 0px;
font-family: sans-serif;
background: #f2f2f2;
height: 100%;
}
.first-row {
border: 3px solid green;
float:left;
width: 100%;
}
.grid-container1, .grid-container2 {
display: flex;
}
.grid-container1 figcaption {
font-size: 1rem;
padding: 5px;
float: bottom;
}
.grid-container1 {
border: 1px solid red;
}
.grid-container1 img {
display:inline-block;
vertical-align:middle;
width: 100%;
}
.grid-container2 img {
vertical-align: top;
width: 100%;
float: left;
}
<div class="grid-container1">
<figure>
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/210284/san-fransisco-768x432.jpg" alt="san francisco">
<figcaption>lorem ipsum</figcaption>
</figure>
<figure>
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/210284/san-fransisco-768x432.jpg" alt="san francisco">
<figcaption>lorem ipsum</figcaption>
</figure>
</div>
<div class="grid-container2">
<figure>
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/210284/san-fransisco-768x432.jpg" alt="san francisco">
<figcaption>lorem ipsum</figcaption>
</figure>
<figure>
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/210284/san-fransisco-768x432.jpg" alt="san francisco">
<figcaption>lorem ipsum</figcaption>
</figure>
<figure>
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/210284/san-fransisco-768x432.jpg" alt="san francisco">
<figcaption>lorem ipsum</figcaption>
</figure>
<figure>
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/210284/san-fransisco-768x432.jpg" alt="san francisco">
<figcaption>lorem ipsum</figcaption>
</figure>
</div>
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>
I tried used display: inline-block and other stuff like changing the width but my images only show to be vertical.
.figure {
display: inline-block;
}
figure.item {
color: #676767;
background-color: #ffffff;
width: 100%;
margin: 0;
text-align: center;
display: inline-block;
}
.item img {
width: 100px;
height: 100px;
display: inline-block;
}
.caption {
display: block;
}
<figure class="item">
<img src="./img/facebook.png" />
<figcaption class="caption">Facebook</figcaption>
<img src="./img/insta.png" />
<figcaption class="caption">Facebook</figcaption>
<img src="./img/telefone.png" />
<figcaption class="caption">Facebook</figcaption>
<img src="./img/email.png" />
<figcaption class="caption">Facebook</figcaption>
</figure>
Right now the images are showing vertically and with text under. And i need the images to be horizontally with text under they.
Using Flex-box
I make a wrap div for every img and text.
.item {
display: flex;
flex-wrap: wrap;
justify-content: space-around;
margin: 0;
}
.item img {
width: 100px;
height: 100px;
display: inline-block;
}
.caption {
display: inline-block;
}
.wrap{
width:100px;
text-align: center;
}
<figure class="item">
<div class="wrap">
<img src="./img/facebook.png" />
<figcaption class="caption">Facebook</figcaption>
</div>
<div class="wrap">
<img src="./img/facebook.png" />
<figcaption class="caption">Facebook</figcaption>
</div>
<div class="wrap">
<img src="./img/facebook.png" />
<figcaption class="caption">Facebook</figcaption>
</div>
<div class="wrap">
<img src="./img/facebook.png" />
<figcaption class="caption">Facebook</figcaption>
</div>
</figure>
figure.item {
color: #676767;
background-color: #ffffff;
text-align: center;
}
.item img {
width: 100px;
height: 100px;
}
figure {
width: 25%;
float: left;
margin: 0;
text-align: center;
padding: 0;
}
<figure class="item">
<img src="./img/facebook.png" />
<figcaption class="caption">Facebook</figcaption>
</figure>
<figure class="item">
<img src="./img/facebook.png" />
<figcaption class="caption">Facebook</figcaption>
</figure>
<figure class="item">
<img src="./img/facebook.png" />
<figcaption class="caption">Facebook</figcaption>
</figure>
<figure class="item">
<img src="./img/facebook.png" />
<figcaption class="caption">Facebook</figcaption>
</figure>
There are several issues with your snippet:
The first line .figure is not meant to be a class but a element selector (i.e. .figure !== figure)
Block-Elements will be displayed underneath each other by default.
Try to use flex-box. https://css-tricks.com/snippets/css/a-guide-to-flexbox/
.row {
display: flex;
}
<div class="row">
<figure>
<img src="./img/facebook.png" />
<figcaption class="caption">Facebook</figcaption>
</figure>
<figure>
<img src="./img/insta.png" />
<figcaption class="caption">Facebook</figcaption>
</figure>
<figure>
<img src="./img/telefone.png" />
<figcaption class="caption">Facebook</figcaption>
</figure>
<figure>
<img src="./img/email.png" />
<figcaption class="caption">Facebook</figcaption>
</figure>
</div>
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 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>