How do I position one image directly over the other? [duplicate] - html

This question already has answers here:
How can i overlay an 10x10px image on top of another image? [duplicate]
(2 answers)
How do I position one image on top of another in HTML?
(13 answers)
Closed 5 years ago.
The aim is to have the grey images overlayed by the blue when hovered over (so that the grey image becomes the blue image).
At the moment the blue images are off centre and therefore not directly on top of the grey.
Here's how the menu currently looks when I hover over the first icon.
HTML
<div class="footerContainer">
<div class="iconContainer">
<img class="homeIcon" src="images/Home Icon.png"/> <!--grey image-->
<img class="homeIconHover" src="images/Home Icon blue.png"/> <!--blue image-->
</div>
<div class="iconContainer">
<img class="magIcon" src="images/Magazine Icon.png"/>
<img class="magIconHover" src="images/Magazine Icon blue.png"/>
</div>
<div class="iconContainer">
<img class="newsIcon" src="images/News Icon.png"/>
<img class="newsIconHover" src="images/News Icon blue.png"/>
</div>
<div class="iconContainer">
<img class="eventIcon" src="images/Event Icon.png"/>
<img class="eventIconHover" src="images/Event Icon blue.png"/>
</div>
<div class="iconContainer">
<img class="socialIcon" src="images/Social Icon.png"/>
<img class="socialIconHover" src="images/Social Icon blue.png"/>
</div>
</div>
CSS
.footerContainer{
border-top: rgba(0,0,0,0.8) 2px solid;
height: 5rem;
display: flex;
background-color: #e5e5e5;
background-size: cover;
margin: 0;
padding: 0;
text-align: center;
position: relative;
}
.iconContainer{
width: 20%;
margin: auto;
}
/* grey images */
.homeIcon{
text-align: center;
height: 71px;
margin: auto;
position: relative;
}
.magIcon{
text-align: center;
height: 58px;
margin: auto;
position: relative;
}
.newsIcon{
text-align: center;
height: 64px;
margin: auto;
position: relative;
}
.eventIcon{
text-align: center;
height: 80px;
margin: auto;
position: relative;
}
.socialIcon{
text-align: center;
height: 80px;
margin: auto;
position: relative;
}
/* HOVER */
/* blue images */
.homeIconHover{
text-align: center;
height: 71px;
margin: auto;
opacity: 0;
position: absolute;
}
.iconContainer:hover .homeIconHover{
opacity: 1;
}
.iconContainer:hover .homeIcon{
opacity: 0;
}
.magIconHover{
text-align: center;
height: 58px;
margin: auto;
opacity: 0;
position: absolute;
}
.iconContainer:hover .magIconHover{
opacity: 1;
}
.iconContainer:hover .magIcon{
opacity: 0;
}
.newsIconHover{
text-align: center;
height: 64px;
margin: auto;
opacity: 0;
position: absolute;
}
.iconContainer:hover .newsIconHover{
opacity: 1;
}
.iconContainer:hover .newsIcon{
opacity: 0;
}
.eventIconHover{
text-align: center;
height: 80px;
margin: auto;
opacity: 0;
position: absolute;
}
.iconContainer:hover .eventIconHover{
opacity: 1;
}
.iconContainer:hover .eventIcon{
opacity: 0;
}
.socialIconHover{
text-align: center;
height: 80px;
margin: auto;
opacity: 0;
position: absolute;
}
.iconContainer:hover .socialIconHover{
opacity: 1;
}
.iconContainer:hover .socialIcon{
opacity: 0;
}
Cheers in advance

Add position: relative to .iconContainer so that the absolute positioning on the overlay image will be relative to it's parent. Then use top: 0; left: 50%; transform: translateX(-50%); on the overlay image to position it in the center of the container like the other image.
.footerContainer {
border-top: rgba(0, 0, 0, 0.8) 2px solid;
height: 5rem;
display: flex;
background-color: #e5e5e5;
background-size: cover;
margin: 0;
padding: 0;
text-align: center;
position: relative;
}
.iconContainer {
width: 20%;
margin: auto;
position: relative;
}
/* grey images */
.homeIcon {
text-align: center;
height: 71px;
margin: auto;
position: relative;
}
.magIcon {
text-align: center;
height: 58px;
margin: auto;
position: relative;
}
.newsIcon {
text-align: center;
height: 64px;
margin: auto;
position: relative;
}
.eventIcon {
text-align: center;
height: 80px;
margin: auto;
position: relative;
}
.socialIcon {
text-align: center;
height: 80px;
margin: auto;
position: relative;
}
/* HOVER */
/* blue images */
.homeIconHover {
text-align: center;
height: 71px;
margin: auto;
opacity: 0;
position: absolute;
left: 50%;
top: 0;
transform: translateX(-50%);
}
.iconContainer:hover .homeIconHover {
opacity: 1;
}
.iconContainer:hover .homeIcon {
opacity: 0;
}
.magIconHover {
text-align: center;
height: 58px;
margin: auto;
opacity: 0;
position: absolute;
}
.iconContainer:hover .magIconHover {
opacity: 1;
}
.iconContainer:hover .magIcon {
opacity: 0;
}
.newsIconHover {
text-align: center;
height: 64px;
margin: auto;
opacity: 0;
position: absolute;
}
.iconContainer:hover .newsIconHover {
opacity: 1;
}
.iconContainer:hover .newsIcon {
opacity: 0;
}
.eventIconHover {
text-align: center;
height: 80px;
margin: auto;
opacity: 0;
position: absolute;
}
.iconContainer:hover .eventIconHover {
opacity: 1;
}
.iconContainer:hover .eventIcon {
opacity: 0;
}
.socialIconHover {
text-align: center;
height: 80px;
margin: auto;
opacity: 0;
position: absolute;
}
.iconContainer:hover .socialIconHover {
opacity: 1;
}
.iconContainer:hover .socialIcon {
opacity: 0;
}
<div class="footerContainer">
<div class="iconContainer">
<img class="homeIcon" src="http://kenwheeler.github.io/slick/img/lazyfonz2.png"/> <!--grey image-->
<img class="homeIconHover" src="http://kenwheeler.github.io/slick/img/lazyfonz3.png"/> <!--blue image-->
</div>
<div class="iconContainer">
<img class="homeIcon" src="http://kenwheeler.github.io/slick/img/lazyfonz2.png"/> <!--grey image-->
<img class="homeIconHover" src="http://kenwheeler.github.io/slick/img/lazyfonz3.png"/> <!--blue image-->
</div>
<div class="iconContainer">
<img class="homeIcon" src="http://kenwheeler.github.io/slick/img/lazyfonz2.png"/> <!--grey image-->
<img class="homeIconHover" src="http://kenwheeler.github.io/slick/img/lazyfonz3.png"/> <!--blue image-->
</div>
<div class="iconContainer">
<img class="homeIcon" src="http://kenwheeler.github.io/slick/img/lazyfonz2.png"/> <!--grey image-->
<img class="homeIconHover" src="http://kenwheeler.github.io/slick/img/lazyfonz3.png"/> <!--blue image-->
</div>
</div>

instead you can use css to change the color of all images to black and white. https://jsfiddle.net/z57s6quj/
img {
transition: all 200ms;
filter: grayscale(100%);
}
img:hover {
filter: none
}
take a look on compatibility
http://caniuse.com/#search=filter

Another alternative would be to use SVGs for your icons and style the fill on hover. SVGs are Scalable Vector Graphics so stay sharp at any device resolution or scale.
Here's a simple example:
svg {width:20%}
svg path {
fill: grey;
}
svg:hover path {
fill: blue;
}
<!-- Generated by IcoMoon.io -->
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
<title>home</title>
<path d="M32 18.451l-16-12.42-16 12.42v-5.064l16-12.42 16 12.42zM28 18v12h-8v-8h-8v8h-8v-12l12-9z"></path>
</svg>
<!-- Generated by IcoMoon.io -->
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
<title>book</title>
<path d="M28 4v26h-21c-1.657 0-3-1.343-3-3s1.343-3 3-3h19v-24h-20c-2.2 0-4 1.8-4 4v24c0 2.2 1.8 4 4 4h24v-28h-2z"></path>
<path d="M7.002 26v0c-0.001 0-0.001 0-0.002 0-0.552 0-1 0.448-1 1s0.448 1 1 1c0.001 0 0.001-0 0.002-0v0h18.997v-2h-18.997z"></path>
</svg>

Just an "outside-the-box" answer. You don't need second images in the first place, but rather can use filters to achieve the same effekt.
Below are two different approaches. filter has really good support and uses a regular image and background-blend-mode is not there yet supportwise (thanks, Microsoft!) but uses background-images.
#one{
background-image: url('http://lorempixel.com/200/100/sports/1');
background-color: blue;
background-blend-mode: screen;
width:200px;height:100px;
margin-right:10px;
float:left;
}
#one:hover{
background-color: transparent;
}
#two{
background-color: red;
height:100px; width:200px;
float:left;
}
#two img{
filter:grayscale(100%);
opacity:.5;
}
#two img:hover{
filter:grayscale(0%);
opacity:1;
}
<h3>Hover the images:</h3>
<div id="one">
</div>
<div id="two">
<img src="http://lorempixel.com/200/100/sports/1" />
</div>

Related

Why is not the navigation buttons showing under the curtain, when the images are?

Hope you all are doing well!
I'm working on a platform for a digital art exhibition, where we want a curtain to slide aside and reveal the images.
I've used this example code for creating the curtain effect:
https://css-tricks.com/creating-css-sliding-door-effect/
And for the carousel of images, I've used this example code:
https://codepen.io/SitePoint/pen/gRJWqm
Since I'm totally blind, CSS is a little challenging for me because it is a little difficult to test things out myself. :)
I've been told that the pictures show as they should when the curtain slides out to the sides, but the buttons to change pictures is not showing.
I'm not sure why, because both the images and the buttons is included in the "curtain__content" div.
I wonder if anyone maybe could look a little bit at the code and tell me what I need to do to make the buttons show up as they should?
Any help would be greatly appreciated!
Here is my style:
<style>
body {
background-color: aliceblue;
margin: 0;
font-family: "Roboto", sans-serif;
font-size: 16px;
}
h1 {
text-align: center;
margin-bottom: 1.5em;
}
h2 {
text-align: center;
color: #555;
margin-bottom: 0;
}
.carousel {
padding: 20px;
perspective: 500px;
display: flex;
flex-direction: column;
align-items: center;
}
.carousel > * {
flex: 0 0 auto;
}
.carousel figure {
margin: 0;
width: 100%;
transform-style: preserve-3d;
transition: transform 0.5s;
}
.carousel figure img {
width: 100%;
box-sizing: border-box;
padding: 0 0px;
}
.carousel figure img:not(:first-of-type) {
position: absolute;
left: 0;
top: 0;
}
.carousel nav {
display: flex;
justify-content: center;
margin: 20px 0 0;
}
.carousel nav button {
flex: 0 0 auto;
margin: 0 5px;
cursor: pointer;
color: #333;
background: none;
border: 1px solid;
letter-spacing: 1px;
padding: 5px 10px;
}
.curtain {
margin: 0 auto;
width: 100%;
height: 100vh;
overflow: hidden;
display: flex;
}
.curtain__wrapper {
width: 100%;
height: 100%;
}
.curtain__wrapper input[type=checkbox] {
position: absolute;
cursor: pointer;
width: 100%;
height: 100%;
z-index: 100;
opacity: 0;
top: 0;
left: 0;
}
.curtain__wrapper input[type=checkbox]:checked ~ div.curtain__panel--left {
transform: translateX(0);
}
.curtain__wrapper input[type=checkbox]:checked ~ div.curtain__panel--right {
transform: translateX(0);
}
.curtain__panel {
display: flex;
align-items: center;
background: orange;
color: #fff;
float: left;
position: relative;
width: 50%;
height: 100vh;
transition: all 1s ease-out;
z-index: 2;
}
.curtain__panel--left {
justify-content: flex-end;
transform: translateX(-100%);
}
.curtain__panel--right {
justify-content: flex-start;
transform: translateX(100%);
}
.curtain__content {
align-items: center;
background: #333;
color: #fff;
display: flex;
flex-direction: column;
height: 100vh;
justify-content: center;
padding: 1rem 0;
position: absolute;
text-align: center;
z-index: 1;
width: 100%;
}
.curtain__content img {
width: 50%;
}
</style>
And here is the HTML in the body tag:
<div class="curtain">
<div class="curtain__wrapper">
<input type="checkbox" checked>
<div class="curtain__panel curtain__panel--left">
<h1>Click to reveal </h1>
</div> <!-- curtain__panel -->
<div class="curtain__content">
<div class="carousel" data-gap="80">
<figure style="transform-origin: 50% 50% -899.521px; transform: rotateY(-4.71239rad);">
<img src="projekt1.png" alt="" style="padding: 80px;">
<img src="projekt2.png" alt="" style="padding: 80px; transform-origin: 50% 50% -899.521px; transform: rotateY(0.785398rad);">
<img src="projekt3.png" alt="" style="padding: 80px; transform-origin: 50% 50% -899.521px; transform: rotateY(1.5708rad);">
<img src="projekt4.png" alt="" style="padding: 80px; transform-origin: 50% 50% -899.521px; transform: rotateY(2.35619rad);">
<img src="projekt5.png" alt="" style="padding: 80px; transform-origin: 50% 50% -899.521px; transform: rotateY(3.14159rad);">
<img src="projekt6.png" alt="" style="padding: 80px; transform-origin: 50% 50% -899.521px; transform: rotateY(3.92699rad);">
<img src="projekt7.png" alt="" style="padding: 80px; transform-origin: 50% 50% -899.521px; transform: rotateY(4.71239rad);">
<img src="projekt8.png" alt="" style="padding: 80px; transform-origin: 50% 50% -899.521px; transform: rotateY(5.49779rad);">
<img src="projekt9.png" alt="" style="padding: 80px; transform-origin: 50% 50% -899.521px; transform: rotateY(5.49779rad);">
<img src="projekt10.png" alt="" style="padding: 80px; transform-origin: 50% 50% -899.521px; transform: rotateY(5.49779rad);">
</figure>
<nav>
<button class="nav prev">Prev</button>
<button class="nav next">Next
</button>
</nav>
</div>
</div>
<div class="curtain__panel curtain__panel--right">
<h1>a special reward...</h1>
</div> <!-- curtain__panel -->
</div> <!-- curtain__wrapper -->
</div> <!-- curtain -->
Thanks in advance!
All the best!
Kind regards,
Niklas
There might be a couple of issues, which I'll talk about in the order of what I think is most likely.
The text is the same color as background
At the moment, the button text and the background are the same color, namely #333. We can see this in the following two CSS declarations:
.curtain__content {
background: #333;
}
.carousel nav button {
color: #333;
}
Because of that, the buttons blend in with the background.
The buttons might be off the screen
While experimenting with cat pictures, if the images were sufficiently large then I found the nav buttons had gone off the bottom of the screen and curtain area. In other words, the pictures pushed the buttons below the viewport.
You have a couple of options depending on the desired design:
Ensure the curtain area is large enough to fit the carousel and buttons (for instance, by not using viewport dimensions)
Ensure the carousel resizes to fit within the screen
Allow the buttons to overlay the carousel

Make a paragraph appear inside a picture on picture hover

basically all i want to do is: Have a picture and when someone hovers over it i want some text to appear in its position(in the middle to be exact). What I have done so far is make the picture disappear on hover but i cannot get the text to be appeared..
Html:
<div class="container">
<img id="atp "class="atp" src="atp.jpg">
<div class="center">Some text</div>
</div>
Css:
atp{
display:block;
margin-left:auto;
margin-right:auto;
width:27%;
height:50%;}
container{
position: relative;
text-align: center;
}
.center{
position: absolute;
top:50%;
left:50%;
opacity: 0;
}
So basically, what i seek to be done is .atp:hover{opacity:0;} and what I also want is on atp's hover the .center{opacity:1;] So is there a way to put the opacity of center's to 1 when I am in the atp:hover{} code block?
Hope everything looks fine, thanks in advance!
Here is the code. Hope it will help you. if any changes please let me know.
/********* Simple or original overlay *******/
/* Main container */
.overlay-image {
position: relative;
width: 100%;
}
/* Original image */
.overlay-image .image {
display: block;
width: 100%;
height: auto;
}
/* Original text overlay */
.overlay-image .text {
color: #fff;
font-size: 30px;
line-height: 1.5em;
text-shadow: 2px 2px 2px #000;
text-align: center;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 100%;
}
/********* Overlay on hover *******/
/* New overlay on hover */
.overlay-image .hover {
position: absolute;
top: 0;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
}
/* New overlay appearance on hover */
.overlay-image:hover .hover {
opacity: 1;
}
/********* Background and text only overlay on hover *******/
.overlay-image .normal {
transition: .5s ease;
}
.overlay-image:hover .normal {
opacity: 0;
}
.overlay-image .hover {
background-color: rgba(0,0,0,0.5);
}
<div class="overlay-image">
<a href="LINK_URL">
<div class="normal">
<div class="text">Image + text ORIGINAL</div>
</div>
<div class="hover">
<img class="image" src="https://dummyimage.com/200x150/00ccff/fff.png" alt="Alt text hover" />
</div>
</a>
</div>
#atp {
position: relative;
display: block;
margin-left: auto;
margin-right: auto;
width: 27%;
height: 50%;
z-index: 50;
}
.container {
position: relative;
text-align: center;
}
.center {
position: absolute;
top: 50%;
left: 50%;
z-index: 30;
}
#atp:hover {
opacity: 0;
}
try this, using z-index. It worked with me :)

Add a Link to an Overlay Image

I would like to add a link to an image that has an overlay applied to it. When users hover over the image they get an opaque overlay and text appear. This works great, however I also need users to be able to click that image and taken to a link.
I have pasted my code below - the overlay works but the link portion does not. I believe it's because the overlay is interfering. I tried changing the placement of the link but was unable to do so. I am able to make the '+' be the link, but ideally the entire image should link.
Any thoughts?
JSFiddle
.roomphoto:hover .img__description { transform: translateY(0); }
.roomphoto .img__description_layer { top: 30px; }
.roomphoto:hover .img__description_layer { visibility: visible; opacity: 1; }
.img__description_layer {
position: absolute;
bottom: 0;
left: 0;
right: 0;
color: #cdcbca;
visibility: hidden;
opacity: 0;
display: flex;
align-items: center;
justify-content: center;
transition: opacity .2s, visibility .2s;
}
.roomphoto {
height: 166px;
}
.img__description {
transition: .2s;
transform: translateY(1em);
z-index: 999;
}
.overlay {
position: relative;
}
.overlay:after {
position: absolute;
content:"";
top:0;
left:0;
width:100%;
height:100%;
opacity:0;
}
.overlay:hover:after {
opacity: .8;
}
.blue:after {
background-color: #1a3761;
}
.img__description a {
color: #fff;
}
.roomselect {
clear: both;
float: none;
width: 100%;
max-width: 1000px;
margin: 0px auto;
padding-top: 20px;
}
.roomselect img {
width: 100%;
margin-bottom: -10px;
}
.room3 {
width: 32%;
text-align: left;
float:left;
}
<div class="roomselect"><div class="room3">
<div class="roomphoto overlay blue">
<a href="http://www.google.com">
<img src="https://cdn.mos.cms.futurecdn.net/J9KeYkEZf4HHD5LRGf799N-650-80.jpg" alt="Image Text" />
</a>
<div class="img__description_layer">
<p class="img__description">
<span style="border-radius: 50%; width: 30px; height: 30px; padding: 0px 14px; border: 1px solid #fff; text-align: center; font-size: 36px;">+</span>
</p>
</div>
</div>
</div>
You need to rearrange your html in such a way that when you click on image, you are actually clicking on the anchor tag. I have made some changes to your html, let me know if these work. You might have to increase roomphoto height.
<div class="roomselect">
<div class="room3">
<a href="http://www.google.com">
<div class="roomphoto overlay blue">
<img src="https://cdn.mos.cms.futurecdn.net/J9KeYkEZf4HHD5LRGf799N-650-80.jpg" alt="Image Text" />
<div class="img__description_layer">
<p class="img__description"><span style="border-radius: 50%; width: 30px; height: 30px; padding: 0px 14px; border: 1px solid #fff; text-align: center; font-size: 36px;">+</span></p>
</div>
</div>
</a>
</div>
</div>

How do you place text along the bottom of an image?

How do you place text above an image, such that it runs across the bottom of the image.
i.e.
<div class="i_have_an_image">
<h2>I appear on top of the image, but aligned along the bottom</h2>
</div>
I am struggling to work it out, to see what I mean, The following web site, has a great example of this. I've seen it before on sites, heres an example snapshot of what I mean:
Wrap the image in an inline-block div which has position:relative.
Position the h2 absolutely with bottom:0 and width:100% and the height of the h2 will adjust automatically to the content of the positioned element.
.i_have_an_image {
display: inline-block;
position: relative;
}
.i_have_an_image img {
display: block;
}
.i_have_an_image h2 {
position: absolute;
margin: 0;
bottom: 0;
left: 0;
width:100%;
padding: 1em;
background: rgba(255, 255, 255, 0.5);
color: white;
}
<div class="i_have_an_image">
<img src="http://www.fillmurray.com/460/300" alt="">
<h2>I appear on top of the image, but aligned along the bottom</h2>
</div>
.i_have_an_image{
position:relative;
width:200px;
height:200px;
}
h2{
position:absolute;
bottom:0px;
background:rgba(0,0,0,0.5);
color:#fff;
margin:0px;
}
<div class="i_have_an_image">
<img src="http://i-cdn.phonearena.com/images/article/32854-image/First-samples-from-Sonys-new-13MP-stacked-camera-sensor-capable-of-HDR-video-show-up.jpg">
<h2>I appear on top of the image, but aligned along the bottom</h2>
</div>
.butFrame {
width: 32%;
position: relative;
cursor: pointer;
}
.butFrame .butHeading {
position: absolute;
left: 0;
right: 0;
bottom: 0;
padding: 10px 0;
display: block;
background: rgba(0, 0, 0, 0.5);
margin: 0;
font-family: inherit;
font-size: 1.2em;
color: #fff;
text-align: center;
text-transform: uppercase;
font-weight: 400;
}
<div class="butFrame">
<img src="https://unsplash.it/g/380/210?random">
<div class="butHeading">Heading</div>
https://jsfiddle.net/n0aLts9w/
Another solution of image with heading and sub heading. (As per your given image)
Demo Here
.i_have_an_image{
position: relative;
background-image: url(http://i.imgur.com/McIDx6g.jpg);
background: url((http://i.imgur.com/McIDx6g.jpg) no-repeat center center;
height: 400px;
width: 400px;
}
.title_wrap{
position: absolute;
background-color: rgba(0, 0, 0, 0.5);
bottom: 0;
left: 0;
right: 0;
padding: 15px;
color: #ffffff;
}
.title_wrap h2 {
font-size: 20px;
margin: 0;
}
.title_wrap h6 {
font-size: 12px;
margin: 0;
}
<div class="i_have_an_image">
<div class="title_wrap">
<h2>Heading goes here</h2>
<h6>I appear on top of the image, but aligned along the bottom</h6>
</div>
</div>
You can make it like this:
I added only the "wrap" div
.wrap {
max-width: 300px;
}
h2 {
position: relative;
top: -78px;
opacity: 0.8;
background: #222222;
color: #fff;
}
<div class="i_have_an_image">
<div class="wrap">
<img src="http://www.theage.com.au/content/dam/images/g/p/o/1/v/l/image.related.homepagePortrait.300x370.gpnu1x.2f8s9.png/1466499504473.jpg" alt="Angelika Graswald in court with her lawyers. " width="300" height="370">
<h2>I appear on top of the image, but aligned along the bottom</h2>
</div>
</div>
This is how I've been doing it recently. It's using the new html5 tag figcaption
It doesn't matter how big the image is or what you put in the figcaption it should just work.
figure.overlay {
display: inline-block;
position: relative;
margin: 0;
}
figure.overlay figcaption {
position: absolute;
background: rgba(0, 0, 0, .5);
color: #fff;
bottom: 4px;
width: calc(100%-10px);
padding: 5px;
}
<figure class="overlay">
<img src="http://www.dogbreedinfo.com/images/germanshepherdface.jpg">
<figcaption>
<h3>
'Some header of some sort!'
</h3> Words that make up a sentance! Or maybe 2 sentances.
<br />
<br />Even with a new line
</figcaption>
</figure>
Ho you can do it with flexbox simply like this:
.imageWrapper {
width: 200px;
height: 300px;
display: flex;
flex-direction: column;
justify-content: flex-start;
border: 1px solid black;
background-image: url("https://upload.wikimedia.org/wikipedia/commons/a/a8/Tour_Eiffel_Wikimedia_Commons.jpg");
background-size: 100%;
}
.textAboveImage {
width: 100%;
height: 50px;
background-color: grey;
z-index: 200;
opacity: 0.5;
}
<div class="imageWrapper">
<div class="textAboveImage">I'm text</div>
</div>
Cheers.
You can make it like this:
I added only the "wrap" div
HTML:
<div class="i_have_an_image">
<div class="wrap">
<img src="http://www.theage.com.au/content/dam/images/g/p/o/1/v/l/image.related.homepagePortrait.300x370.gpnu1x.2f8s9.png/1466499504473.jpg" alt="Angelika Graswald in court with her lawyers. " width="300" height="370">
<h2>I appear on top of the image, but aligned along the bottom</h2>
</div>
</div>
CSS:
.wrap {
max-width: 300px;
}
h2 {
position: relative;
top: -78px;
opacity: 0.8;
background: #222222;
color:#fff;
}

Hover event taking place outside of area I am wanting

I have a small bug that I can't seem to locate. In my snippet you can see how whenever you hover over the image, opactiy and an image scale takes place, as well as a box comes over the image. That is perfect, but my issue is whenever you hover over the text below it, the hover effect takes place over the image.
I can't seem to figure out how for the hover effect to only take place when the mouse is hovering over the image.
Any suggestions would be appreciated.
$('.home-img-block img').addClass(function() {
return (this.width / this.height > 1) ? 'wide' : 'tall';
});
#home-img-block-section {
width: 100%;
height: 900px;
}
#home-img-blocks {
width: 100%;
height: 750px;
}
.home-img-block {
width: 33.33%;
float: left;
display: block;
overflow: hidden;
position: relative;
}
.home-img-container {
position: relative;
overflow: hidden;
cursor: pointer;
}
.home-img-block:hover .overlay {
background: rgba(0, 0, 0, 0.6);
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
}
.home-img-container:after {
content: attr(data-content);
color: #fff;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
opacity: 0;
transition: all 0.5s;
border: 1px solid #fff;
padding: 20px 25px;
text-align: center;
}
.home-img-container:hover:after {
opacity: 1;
}
.home-img-block img {
display: block;
transition: all 1s ease;
}
.home-img-block:hover img {
transform: scale(1.25);
background: rgba(0, 0, 0, 0.3);
width: 33.33%;
max-height: 100%;
overflow: hidden;
}
.home-img-block img.wide {
max-width: 100%;
max-height: 100%;
height: auto;
width: 100%;
}
.home-img-block img.tall {
max-width: 100%;
max-height: 100%;
width: auto;
}
#home-img-block-wording-container {
width: 100%;
height: 300px;
}
.home-img-wording-blocks {
width: 100%;
height: 100%;
text-align: center;
display: inline-block;
vertical-align: top;
}
.home-img-wording-block-title {
padding-top: 30px;
font-size: 1.7em;
}
.home-img-wording-block-description {
padding: 25px 50px 0 50px;
font-size: 1.1em;
color: #5d5d5d;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="home-img-block-section">
<div id="home-img-blocks">
<div class="home-img-block fadeBlock1">
<div data-content="FIND OUT MORE" class='home-img-container'>
<img src="http://optimumwebdesigns.com/images/test1.jpg">
<div class="overlay"></div>
</div>
<div class="home-img-wording-blocks">
<div class="home-img-wording-block-title">WEB DESIGN</div>
<div class="home-img-wording-block-description">The OD team can see your web design visions brought
to life, creating a site that promotes your uniqueness through specific functionalities and features.</div>
</div>
</div>
<div class="home-img-block fadeBlock2">
<div data-content="FIND OUT MORE" class='home-img-container'>
<img src="http://optimumwebdesigns.com/images/test2new.jpg">
<div class="overlay"></div>
</div>
<div class="home-img-wording-blocks">
<div class="home-img-wording-block-title">ECOMMERCE</div>
<div class="home-img-wording-block-description">Custom built solutions catered towards you end goal.
gfdgfdsg greg reg regrfesg fdsg gretswtgy tgreswt treswt trgegfd gsvbd fbgre greasgv drfdg greaag gredr</div>
</div>
</div>
<div class="home-img-block fadeBlock3">
<div data-content="FIND OUT MORE" class='home-img-container'>
<img src="http://optimumwebdesigns.com/images/test3new.jpg">
<div class="overlay"></div>
</div>
<div class="home-img-wording-blocks">
<div class="home-img-wording-block-title">MARKETING STRATEGIES</div>
<div class="home-img-wording-block-description">MARKETING STRATEGIES gfdgf fdggs gfsg gfsg gf sgf g
gfdsg sdfggfs gfdsgssdfg fdggfds gfdsg gfds gfdgs gf dsgfdsgfgs gfdgfs gtrg resg reg rgesgresrgrg</div>
</div>
</div>
</div>
</div>
.home-img-block:hover .overlay
and
.home-img-block:hover img
replace them with
.home-img-container:hover .overlay
.home-img-container:hover img
otherwise you're triggering when you hover over the whole container instead of only wheen hovering the img one.