Firstly, sorry for the question, I just can't work out where I'm going wrong after many hours of trying!
I have three images, and I am trying to flip them -180 degrees using the transform:rotateY declaration.
I have managed to get them to rotate, but once they get past the -180degrees mark they disappear.
I also want the underlying divs, which contain some text, to appear after the image flips round -180 degrees - as if they were on the back of the image if that makes sense.
Here's the codepen link - http://codepen.io/skoster7/pen/KgwXgB
Here's the code
.container {
display: flex;
perspective: 700px;
}
.photo img {
transition-style: preserve-3d;
transition-property: transform;
transition-duration: 2s;
width: 300px;
height: 200px;
top: 20px;
margin: 10px;
}
.sideb {
width: 300px;
height: 200px;
background: tomato;
}
sidea:hover {
transform: rotateY(-180deg);
}
.sidea,
.sideb {
backface-visibility: hidden;
}
.sideb {
transform: rotateY(180deg);
}
<div class="container">
<div class="photo">
<img class="sidea" src="http://cdn.history.com/sites/2/2015/04/hith-
father-christmas-lights-iStock_000029514386Large.jpg">
<div class="sideb">Christmas
</div>
</div>
<div class="photo">
<img class="sidea" src="https://upload.wikimedia.org/wikipedia/commons/7/79/HalloweenPumpkin2.jpg">
<div class="sideb">Halloween
</div>
</div>
<div class="photo">
<img class="sidea" src="http://motormarks.co.uk/news/wp-content/uploads/2015/04/easter-chicks.jpg">
<div class="sideb">Easter
</div>
</div>
</div>
Thanks in advance for any help!
Modified code: http://codepen.io/anon/pen/ozgpXa
You should rotate container of sides in this case photo. And also add some values to get position from top and left to be in the same place.
You can do something like the demo below.
Recommendations:
You should also try to write semantic HTML for a cleaner code, maintainability, accessibility, SEO and many more. And make your transitions a bit faster, something between 300ms - 500ms, don't expect users to wait 2 seconds for each image they want to flip!
jsFiddle
CODE SNIPPET:
.flip-card {
width: 30%;
display: inline-block;
vertical-align: top;
margin: 0 0 1% 0;
-webkit-perspective: 700px;
perspective: 700px;
}
.flip-card figure {
width: 100%;
height: 0;
margin: 0;
padding-top: 100%;
position: relative;
transition: transform 300ms ease-out;
-webkit-perspective: 700;
perspective: 700;
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
}
.flip-card figure img {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}
.flip-card figure figcaption {
display: flex;
justify-content: center;
align-items: center;
text-align: center;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
transform: rotateY(-180deg);
}
.flip-card:hover figure,
.flip-card.hover figure {
transform: rotateY(-180deg);
}
.flip-card figure figcaption p {
font-size: 1em;
width: 100%;
padding: 0 2em;
color: white;
}
.flip-card figcaption {
background-color: dodgerblue;
}
.flip-card:nth-of-type(odd) figcaption {
background-color: tomato;
}
<ul class="container">
<li class="flip-card" ontouchstart="this.classList.toggle('hover');">
<figure>
<img src="http://fillmurray.com/200/200" alt="">
<figcaption>
<p>Text Example</p>
</figcaption>
</figure>
</li>
<li class="flip-card" ontouchstart="this.classList.toggle('hover');">
<figure>
<img src="http://fillmurray.com/300/300" alt="">
<figcaption>
<p>Text Example</p>
</figcaption>
</figure>
</li>
<li class="flip-card" ontouchstart="this.classList.toggle('hover');">
<figure>
<img src="http://fillmurray.com/400/400" alt="">
<figcaption>
<p>Text Example</p>
</figcaption>
</figure>
</li>
<li class="flip-card" ontouchstart="this.classList.toggle('hover');">
<figure>
<img src="http://fillmurray.com/500/500" alt="">
<figcaption>
<p>Text Example</p>
</figcaption>
</figure>
</li>
<li class="flip-card" ontouchstart="this.classList.toggle('hover');">
<figure>
<img src="http://fillmurray.com/600/600" alt="">
<figcaption>
<p>Text Example</p>
</figcaption>
</figure>
</li>
<li class="flip-card" ontouchstart="this.classList.toggle('hover');">
<figure>
<img src="http://fillmurray.com/100/100" alt="">
<figcaption>
<p>Text Example</p>
</figcaption>
</figure>
</li>
</ul>
To add more spacing between items just change margin property in .flip-card class.
EDIT:
How to make it flip only when someone clicks on it?
For this requirement we can create a small plugin.
It requires an 'active' class which will flip the cards in our CSS.
.flip-card.active figure {
transform: rotateY(-180deg);
}
How to use in JS:
var flipcards = new FlipCards({
cardsClass: "flip-card", //default
activeClass: "active" //default
});
(function(window) {
"use strict";
function extend(a, b) {
for (var key in b) {
if (b.hasOwnProperty(key)) {
a[key] = b[key];
}
}
return a;
}
function flipCards(options) {
this.options = extend({}, this.options);
extend(this.options, options);
this._init();
}
flipCards.prototype.options = {
cardsClass: "flip-card",
activeClass: "active"
}
flipCards.prototype._initEvents = function() {
var cards = document.getElementsByClassName(this.options.cardsClass),
i = 0,
len = cards.length,
self = this;
if (len === 0) return;
for (i, len; i < len; i++) {
cards[i].addEventListener('click', function() {
this.classList.toggle(self.options.activeClass);
});
}
}
flipCards.prototype._init = function() {
this._initEvents();
}
window.FlipCards = flipCards;
// Support for CommonJS Module format and AMD format.
if (typeof module !== "undefined" && module.exports) {
module.exports.FlipCards = flipcards;
} else if ((typeof define !== "undefined" && define !== null) && (define.amd !== null)) {
define("flipcards.js", function() {
return flipcards;
});
}
})(window);
var flipcards = new FlipCards({
cardsClass: "flip-card", //default
activeClass: "active" //default
});
.flip-card {
width: 30%;
display: inline-block;
vertical-align: top;
margin: 0 0 1% 0;
-webkit-perspective: 700px;
perspective: 700px;
}
.flip-card figure {
width: 100%;
height: 0;
margin: 0;
padding-top: 100%;
position: relative;
transition: transform 300ms ease-out;
-webkit-perspective: 700;
perspective: 700;
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
}
.flip-card figure img {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}
.flip-card figure figcaption {
display: flex;
justify-content: center;
align-items: center;
text-align: center;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
transform: rotateY(-180deg);
}
.flip-card.active figure {
transform: rotateY(-180deg);
}
.flip-card figure figcaption p {
font-size: 1em;
width: 100%;
padding: 0 2em;
color: white;
}
.flip-card figcaption {
background-color: dodgerblue;
}
.flip-card:nth-of-type(odd) figcaption {
background-color: tomato;
}
<ul class="container">
<li class="flip-card" ontouchstart="this.classList.toggle('hover');">
<figure>
<img src="http://fillmurray.com/200/200" alt="">
<figcaption>
<p>Text Example</p>
</figcaption>
</figure>
</li>
<li class="flip-card" ontouchstart="this.classList.toggle('hover');">
<figure>
<img src="http://fillmurray.com/300/300" alt="">
<figcaption>
<p>Text Example</p>
</figcaption>
</figure>
</li>
<li class="flip-card" ontouchstart="this.classList.toggle('hover');">
<figure>
<img src="http://fillmurray.com/400/400" alt="">
<figcaption>
<p>Text Example</p>
</figcaption>
</figure>
</li>
<li class="flip-card" ontouchstart="this.classList.toggle('hover');">
<figure>
<img src="http://fillmurray.com/500/500" alt="">
<figcaption>
<p>Text Example</p>
</figcaption>
</figure>
</li>
<li class="flip-card" ontouchstart="this.classList.toggle('hover');">
<figure>
<img src="http://fillmurray.com/600/600" alt="">
<figcaption>
<p>Text Example</p>
</figcaption>
</figure>
</li>
<li class="flip-card" ontouchstart="this.classList.toggle('hover');">
<figure>
<img src="http://fillmurray.com/100/100" alt="">
<figcaption>
<p>Text Example</p>
</figcaption>
</figure>
</li>
</ul>
Live Example
Related
I have a problem with text and image.
This is the design that i want it:
I already code this but I have a problem with the text and image
This is in HTML css:
here is the code :
#font-face {
src: url(source/font/SansitaSwashed-Regular.ttf);
font-family: 'Sansita';
}
/* Default Styling */
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: 'Sansita', sans-serif;
}
.container {
height: 100vh;
width: auto;
padding: 0;
}
.feature-showcase {
list-style: none;
width: 100%;
}
.feature-showcase li {
display: block;
float: left;
width: 33.3%;
/*3 li should occupy full width.*/
}
.meal-photo {
width: 100%;
margin: 0;
overflow: hidden;
/*This is to prevent spilling out of images when we scale the images.*/
background: #000;
text-align: center;
}
.meal-photo img {
opacity: 0.7;
width: 100%;
height: 50vh;
position: relative;
/*This will scale the image in proportion to the 25% width set for meals-showcase-li*/
transform: scale(1.15);
/*This is a part of our "animation" for food images.*/
transition: transform 0.5s, opacity 0.5s;
/*animation - changing from this css setting to another will take some time*/
}
.meal-photo img:hover {
opacity: 1;
transform: scale(1.03);
/*Not 1 because we want to cover some whitespace below each image.*/
}
.text {
text-align: center;
color: white;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Kemanaa</title>
</head>
<body>
<div class="container">
<ul class="feature-showcase">
<li>
<figure class="meal-photo">
<img src="source/image/oleh-oleh1.jpg" alt="">
<!-- <p class="text">Oleh oleh</p> -->
</figure>
</li>
<li>
<figure class="meal-photo">
<img src="source/image/kuliner1.jpg" alt="">
</figure>
</li>
<li>
<figure class="meal-photo">
<img src="source/image/wisata1.jpg" alt="">
</figure>
</li>
</ul>
<ul class="feature-showcase">
<li>
<figure class="meal-photo">
<img src="source/image/oleh-oleh2.jpg" alt="">
</figure>
</li>
<li>
<figure class="meal-photo">
<img src="source/image/kuliner2.jpg" alt=>
</figure>
</li>
<li>
<figure class="meal-photo">
<img src="source/image/wisata2.jpg" alt=" ">
</figure>
</li>
</ul>
</div>
</body>
</html>
if you guys have another advice or better code, it will be great.
this text is just for It looks like your post is mostly code; please add some more details.
I would suggest using the images as background for the elements instead of setting an img tag.
Check the guide here: https://www.w3schools.com/cssref/pr_background-image.asp
Instead of using
.feature-showcase li {
display: block;
float: left;
width: 33.3%;
/*3 li should occupy full width.*/
}
Try using flexbox
I suggest using this as example
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
This could be one way to do it. My example is very simple so maybe you could use it as a starting point.
Here is a Codepen.
I presumed you wanted to use actual image elements.
HTML
<div class="container">
<div class="item">
<img src="https://source.unsplash.com/random/800x600" />
<div class="text">
<p>Text in here</p>
</div>
</div>
<div class="item">
<img src="https://source.unsplash.com/random/800x600" />
<div class="text">
<p>Text in here</p>
</div>
</div>
<div class="item">
<img src="https://source.unsplash.com/random/800x600" />
<div class="text">
<p>Text in here</p>
</div>
</div>
<div class="item">
<img src="https://source.unsplash.com/random/800x600" />
<div class="text">
<p>Text in here</p>
</div>
</div>
<div class="item">
<img src="https://source.unsplash.com/random/800x600" />
<div class="text">
<p>Text in here</p>
</div>
</div>
<div class="item">
<img src="https://source.unsplash.com/random/800x600" />
<div class="text">
<p>Text in here</p>
</div>
</div>
</div>
CSS
.container {
width: 100%;
height: 100vh;
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
.item {
width: 33.3333%;
height: 50%;
position: relative;
}
.item img {
width: 100%;
height: 100%;
object-fit: cover;
}
.text {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
display: flex;
align-items: center;
justify-content: center;
}
.text p {
color: white;
}
you can use display:Grid
basic example:
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
overflow: hidden;
}
.container {
height: 100vh;
width: 100vw;
display: grid;
grid-template-columns: 1fr 1fr 1fr;
}
.container figure {
position:relative
}
.container figure img {
height: 100%;
width: 100%;
}
.container figure figcaption {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: white;
font-weight: bold;
font-size: 2em;
}
<div class="container">
<figure >
<img src="https://picsum.photos/id/251/500/300.jpg" alt="">
<figcaption>Oleh-oleh</figcaption>
</figure>
<figure >
<img src="https://picsum.photos/id/252/500/300.jpg" alt="">
<figcaption></figcaption>
</figure>
<figure >
<img src="https://picsum.photos/id/253/500/300.jpg" alt="">
<figcaption>Wisata</figcaption>
</figure>
<figure >
<img src="https://picsum.photos/id/254/500/300.jpg" alt="">
<figcaption></figcaption>
</figure>
<figure >
<img src="https://picsum.photos/id/255/500/300.jpg" alt="">
<figcaption>Kuliner</figcaption>
</figure>
<figure >
<img src="https://picsum.photos/id/256/500/300.jpg" alt="">
<figcaption></figcaption>
</figure>
</div>
I have an image gallery and would like to display text above it when hovering. I cannot set specific sizes to the image description because the grid resizes constantly. I know I could fix it with very specific media queries yet I don't want to do that. Is there a simple way for me to do it?
.figure-img {
display: block;
width: 100%;
height: 100%;
object-fit: cover;
position: relative;
}
.description {
opacity: 0;
background: black;
width: 100%;
height: 100%;
position: absolute;
overflow: hidden;
top: 0;
left: 0;
}
.img-container {
overflow: hidden;
width: 100%;
height: 100%;
}
figure:hover .description {
opacity: .8;
}
.d-name {
color: white;
font-size: 1.2em;
font-weight: 600;
}
.d-item {
color: white;
font-size: 1.1;
}
<figure class="figure3">
<img class="figure-img" src="images/propg" alt="5St.">
<div class="description text-center">
<p class="d-name">Tower</p>
<p class="d-item">Pnsulation</p>
<p class="d-item">topping</p>
</div>
</figure>
<figure class="figure4">
<img class="figure-img" src="image" alt="nehandler">
<div class="description text-center">
<p class="d-name"> Tower</p>
<p class="d-item">nsulation</p>
<p class="d-item">topping</p>
</div>
</figure>
<figure class="figure5 ">
<div class="img-container">
<img class="figure-img" src="images/pr34th-St%20rendering.jpg" alt="4h St">
<figcaption class="description text-center">
<p class="d-name"> Tower</p>
<p class="d-item">PInsulation</p>
<p class="d-item"> Firestopping</p>
</figcaption>
</div>
</figure>
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'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
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>