CSS hover effect with figure and figcaption overlayed - html

Looking for some styling CSS help. I want to create an image box (that should be link) with centered text that is diplaying over the image with color half-transparent overlay background. We have such given HTML:
<div class="figure">
<a href="#" class="link1">
<img src="http://www.w3schools.com/css/klematis.jpg" alt="flower Klematis">
<div class="figcaption">Klematis</div>
</a>
</div>
The code is analogical of figure/figcaption HTML5 structure.
Here's the case:
https://codepen.io/anon/pen/dYaYqV
On hover overlay background should hide (which is the case), and opacity of image increase to full.
Problem 1:
Text is not centered with such position setting (absolute).
Problem 2:
The overlay in this example is bigger (in the bottom of the image) due to some styling of , I think, element. Overlay should be exact as the image.
Problem 3:
Text should hide as well as overlay during img mouse hover
No JS if possible, only CSS. Can you help? Thanks, J.

I have edited your codepen example a bit, and i think this is exactly what you want
HTML:
<div id="1" class="figure">
<a href="#" class="link1">
<img src="http://www.w3schools.com/css/klematis.jpg" alt="flower Klematis">
<div class="figcaption"><h4>Klematis</h4></div>
</a>
</div>
CSS:
.figure {
position: relative;
float: left;
width: 10%;
margin-right: 1%;
left:20px;
}
.figure a{
display:block;
width:100%;
height:100%;
position:relative;
z-index:2;
}
.figure a img{
width:100%;
display:block;
}
.figcaption {
font-size: 0.8em;
letter-spacing: 0.1em;
text-align: center;
position: absolute;
top: 0;
left:0;
width:100%;
z-index: 2;
height:100%;
background-color:rgba(0,0,0,.4);
transition:background-color 0.4s ease;
}
.figcaption h4{
position:absolute;
top:50%;
left:50%;
padding:0;
margin:0;
-moz-transform:translate(-50%, -50%);
-webkit-transform:translate(-50%, -50%);
transform:translate(-50%, -50%);
}
.figure a:hover .figcaption {
background-color:transparent;
}
sorry, forget to hide text on hover, here is the edited codepen http://codepen.io/gopal280377/pen/QjYyLL

tested on google chrome, hope it works for you
assign width to .figcaption to enable text-align,
moved anchor tag to parent of code block (my preference)
overlay overflow is probably due to undeclared image dimensions,
<a href="#" class="link1">
<div id="1" class="figure">
<img src="http://www.w3schools.com/css/klematis.jpg" alt="flower Klematis">
<div class="figcaption">Klematis</div>
</div>
</a>
.figure {
position: relative;
width: 10%;
height: auto;
background:rgba(92,104,117,0.8);
overflow: hidden;
}
.figcaption {
position: absolute;
font-size: 0.8em;
width: 100%;
letter-spacing: 0.1em;
text-align: center;
top: 50px;
z-index: 1 !important;
}
.figure img {
width: 100%;
opacity: 0.5
}
.link1:hover img {
opacity: 1;
-webkit-transition: .3s ease-in-out;
transition: .3s ease-in-out;
}
.link1:hover .figcaption {
display: none;
background:rgba(92,104,117,0.0);
}

Related

hover appearing and disappearing

Right now I have an image that has another image absolutely positioned on top of the first one. Both images are inside an a tag.
I am trying to get it so that when I hover on any part of the first image, both the first image goes from .5 opacity to full, and the 2nd image goes from 0 opacity to full.
I've been able to make the hover work for the image but the 2nd image only activates it's opacity when I hover directly on it, rather than highlighting both when I'm on either of them.
<div class="of-volume image-column">
<a href="http://www.greatlengthshair.co.uk/hair-extensions/">
<img src="img/artistry-1-bg.jpg" alt="artisans of volume link" class="image-link">
<img src="img/artistry-1-icon.png" alt="" class="artisan-icon">
</a>
</div>
/*//////////////////////////////////////
IMAGE NAV
//////////////////////////////////////*/
.image-column {
background-color: black;
float: left;
width: 33.3333%;
position: relative;
margin-bottom: -3px;
}
.image-column a {
opacity: .5;
}
.image-column a:hover {
opacity: 1;
}
.artisan-icon {
position: absolute;
margin-right: auto;
margin-left: auto;
right: 0;
left: 0;
bottom: 25px;
}
You have mixed up most of your CSS rules. Just attach the desired effects to the correct hover state:
.image-link { opacity: 0.5; }
.artisan-icon { opacity: 0; }
a:hover .image-link { opacity: 1; }
a:hover .artistan-icon { opacity: 1; }
I put both absolute images inside a relative div, then did set the :hover selector on this container.
body {
width: 100%;
height: 100%;
margin: 0px;
}
#container {
position:relative;
width:100%;
height:200px;
}
img {
position:absolute;
top: 0px;
left:0px;
width:100%;
height:200px;
-webkit-transition: opacity 1s; /* Safari */
transition: opacity 1s;
}
#pic1 {
opacity:0.0;
}
#pic2 {
opacity:0.5;
}
#container:hover #pic1, #container:hover #pic2 {
opacity: 1;
}
<div id=container>
<img id=pic1 class=picture src="http://i.imgur.com/tMVGqP6.jpg" alt=img>
<img id=pic2 class=picture src="http://i.imgur.com/Goy7oBy.gif" alt=img>
</div>

div height 100% with content

Would I like to know how I can put in a div 100% height?
I have a div with an image and a div with content.
The image has a width 100%, and the same content but does not fill the entire image div.
I copied the code if you can help.
Thank you,
#carta div{
position: relative;
display: table;
}
#carta div .overlay{
width: 100%;
height: 100%;
background: rgba(0,0,0,.7);
position: absolute;
top:0;
text-align: center;
color:white;
cursor: pointer;
opacity: 0;
-webkit-transition:all .4s ease-out;
transition:all .4s ease-out;
}
#carta .overlay:hover{
opacity: 1;
width: 100%;
height: 100%;
}
#carta .col-1-4{
padding: 0;
margin:0;
}
#carta div img{
width: 100%;
display: table;
}
#carta .overlay p{
font-style: oblique;
font-size: 20px;
padding-top: 50px;
text-align: center;
border-top: 1px solid white;
-webkit-transition:all .4s ease-out;
transition:all .4s ease-out;
}
#carta .overlay h5{
font-size: 30px;
margin: 50px;
}
<div class="clearFix">
<div class="col-1-4">
<img src="img/carta/atun.jpg" alt="atún revuelto"/>
<div class="overlay">
<h5>Atun revuelto</h5>
<p>15€</p>
</div>
</div>
<div class="col-1-4">
<img src="img/carta/especialidaditaliana.jpg" alt="especialidad italiana"/>
<div class="overlay">
<h5>Especialidad Italiana</h5>
<p>15€</p>
</div>
</div>
</div>
Thank you very much for your responses.
I have solved by adding "display: table-cell" in the css class ".overlay"
Thus occupies the div, which occupies the image.
Many thanks
Use background in css,something like this: background: url(img/carta/especialidaditaliana.jpg);
You also can use div to set background
Like this: <div class="img">content</div> but you also need css background.
Something like this?It should work in .html document...
<style>
.img {
position: relative;
width: 200px;
height: 100%;
background: url(http://goo.gl/ytbJn8);
color: white;
}
</style>
<div class="img">This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text.</div>
<div class="box"></div>

Image hover caption with zoom effect in bootstrap

I am unable to align image to the width of caption with maintaining the gutter width. I am using bootstrap and also the image is flowing outside the div on hover. Can anybody help me out ?
This is what i am trying to achive : https://awwapp.com/s/43b68655-83a6-4133-ab28-0ec9a4152316/
Pen : http://codepen.io/anon/pen/XbxOMq
HTML :
HOTSPOT TEXTf
<div class="col-md-4 hotspot-wrapper">
<img src="https://newevolutiondesigns.com/images/freebies/hd-widescreen-wallpaper-3.jpg" alt="..." class="img-responsive">
<div class="hotspot-text">
HOTSPOT TEXTf
</div>
</div>
</div>
<div class="col-md-4 hotspot-wrapper">
<img src="https://newevolutiondesigns.com/images/freebies/hd-widescreen-wallpaper-3.jpg" alt="..." class="img-responsive">
<div class="hotspot-text">
HOTSPOT TEXTf
</div>
</div>
</div>
CSS:
.hotspot-wrapper {
position: relative;
overflow: hidden;
margin-bottom:20px;
}
.hotspot-text {
width:100%;
height: 102px;
position: absolute;
bottom: -50px;
transition: all .2s linear;
background: rgba(0,0,0,.7);
color:#fff;
}
.hotspot-wrapper:hover .hotspot-text {
bottom: 0;
}
.hotspot-wrapper img {
-webkit-transition: all 0.7s ease;
transition: all 0.7s ease;
}
.hotspot-wrapper:hover img {
-webkit-transform:scale(1.3);
transform:scale(1.3);
}
You should make your CSS for these two classes like this, so the hotspot for the text will be aligned with the image :
.hotspot-text {
height: 102px;
position: absolute;
bottom: -50px;
right:0px;
left:0px;
transition: all .2s linear;
background: rgba(0,0,0,.7);
color:#fff;
}
.hotspot-wrapper:hover .hotspot-text {
bottom: 0;
left:0;
right:0;
}
And you should overwrite the padding on the left and on the right set there by default with bootstrap. Like that, the image will have the full width of the div.
.col-lg-4 ,.col-md-4,col-sm-4,col-xs-4{
padding-left:0px;
padding-right:0px;
}
Here's a Fiddle

rotated text that is aligned to the top left corner outside of the image?

I was wondering what would be the most efficient way to place a rotated text directly outside the image's top left corner? Please keep in mind that I would like it if the height of the text box aligns with the height of the image, and the image scale will vary (tall images, short image, wide images, etc.)
Here is a visual of what I would like to achieve:
How might I do this? Thank you in advance!
Whoops, forgot to add the jsfiddle. You can view it here!
.image.information {
display:block;
position:absolute;
margin:0;
top:45%;
left:100%;
height:100%;
-webkit-transition:all 250ms linear;
-o-transition:all 250ms linear;
transition:all 250ms linear;
transform:rotate(-90deg);
-webkit-transform:rotate(-90deg);
-moz-transform:rotate(-90deg);
-ms-transform:rotate(-90deg);
-o-transform:rotate(-90deg);
filter:progid:DXImageTransform.Microsoft.BasicImage(rotation=3);
}
.image-wrap {
height: 100%;
width: 100%;
display: block;
}
.image-inner img {
width: 500px;
height: auto;
display: block;
}
<div class="image-wrap">
<img class="image-inner" src="http://i.stack.imgur.com/YyMHW.jpg" alt="" />
<div class="image information">
information<br/>
informa<br/>
info
</div>
</div>
This is possible using CSS3 transforms, but requires an extra element in your DOM:
<div class="image-wrap">
<img class="image-inner" src="http://media.creativebloq.futurecdn.net/sites/creativebloq.com/files/images/2013/08/korea5b.jpg" alt="" />
<div class="image information">
<div class="info-inner">
information
<br/>informa
<br/>info
</div>
</div>
</div>
Now with some absolute-positioning magic:
.image.information {
position:absolute;
left: 0;
top: 0;
bottom: 0;
width: 75px;
background: #ccc;
}
.info-inner {
text-align: center;
position: absolute;
top: 50%;
left: 50%;
margin-top:-75px;
margin-left: -75px;
height:55px;
width: 150px;
vertical-align: bottom;
transform: rotate(90deg);
}
.image-wrap {
height: 100%;
width: 100%;
position: relative;
}
img.image-inner {
width: 300px;
margin-left: 75px;
}
Note that there's no simple way to have vertically-centered text without specifying an explicit text height. In this case I have chosen 55px. It will stretch to match the height of any image you specify.
JSFiddle: http://jsfiddle.net/zephod/ckqcLsbv/2/

Thumbnail rollover with text

I'm using the following CSS code to do a rollover effect with text:
.thumb {
position:relative;
}
.thumb img:hover {
filter:alpha(opacity=0);
-moz-opacity:0;
-khtml-opacity:0;
opacity:0;
}
.thumb:hover {
background:#f00;
}
.thumb span {
z-index:-10;
position:absolute;
top:10px;
left:10px;
}
.thumb:hover span {
z-index:10;
color:#fff;
}
HTML code:
<div class="thumb">
<img src="thumbnail.jpg" />
<span>Text</span>
</div>
Everything is working well except when I hover over the text: the rollover effect disappears and I can see the image again.
Any ideas?
Thanks in advance
I guess that is too much of styles for simple overlay effect, if you are interested to see a demo I've made from scratch than here you go
Demo
HTML
<div class="wrap">
<img src="http://images.google.com/intl/en_ALL/images/logos/images_logo_lg.gif" />
<div class="overlay">Hello This Is So Simple</div>
</div>
CSS
.wrap {
position: relative;
display: inline-block;
}
.overlay {
opacity: 0;
background: rgba(0,0,0,.8);
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
transition: opacity 1s;
color: #fff;
text-align: center;
}
.wrap:hover .overlay {
opacity: 1;
}