image button with overlay - html

Almost at the bottom of the page you see 4 images with a button inside of each image. (Verona, Mono Silk, Fibre Silk and Akvarell).
I'm trying to achieve an image, with a centered (both veritically and horizontally) text inside of it. And it all needs to be responsive.
The most important thing that I need to fix with these buttons though is that when you hover over a button, I want the image to become darker (just like it is now) but I want it to stay that way even when you hold the mouse over the text inside. I don't understand which approach I need to have to achieve that.
The html code for a button is:
.product-container {
position:relative;
background-color: #000000;
}
.product-btn {
position: absolute;
top:39%;
left: 0;
right: 0;
margin: 0 auto;
background-color: rgba(0,0,0, 0.3);
width: 50%;
border: 1px solid #e1e1e1;
color: #ffffff;
padding: 5px 0;
}
.product-img {
width:100%;
height: auto;
opacity: 1;
transition:
opacity 0.1s ease-in-out;
-moz-transition: opacity 0.1s ease-in-out;
-webkit-transition: opacity 0.1s ease-in-out;
}
.product-img:hover {opacity: 0.5;}
<div class="product-container">
<img class="product-img" src="http://dev2015.proformat.se/wp-content/uploads/2016/02/monosilk.jpg"/>
<a href="http://google.se">
<p class="product-btn">Mono Silk</p>
</a>
</div>
How can I achieve this?

To have the image darker when hover both image and text, I changed this CSS rule
.product-img:hover {opacity: 0.5;}
to this
.product-container:hover img {opacity: 0.5;}
You also had an extra closing </div> tag which I removed.
Having block level (p) element inside an inline (a) is invalid, so I changed your p to a span and added text-align: center; to its CSS rule so the text inside is centered.
Having block level element, like p, inside an inline element is in general invalid, though according to the new HTML5 specs, an a now can have block level elements inside (Thanks to #tjameswhite pointing that out), as long as there is no interactive content within (e.g. buttons or other links).
Sample snippet
.product-container {
position:relative;
background-color: #000000;
}
.product-btn {
position: absolute;
top:39%;
left: 0;
right: 0;
margin: 0 auto;
background-color: rgba(0,0,0, 0.3);
width: 50%;
border: 1px solid #e1e1e1;
color: #ffffff;
padding: 5px 0;
text-align: center;
}
.product-img {
width:100%;
height: auto;
opacity: 1;
transition:
opacity 0.1s ease-in-out;
-moz-transition: opacity 0.1s ease-in-out;
-webkit-transition: opacity 0.1s ease-in-out;
}
.product-container:hover img {opacity: 0.5;}
<div class="product-container">
<img class="product-img" src="http://dev2015.proformat.se/wp-content/uploads/2016/02/monosilk.jpg">
<a href="http://google.se">
<span class="product-btn">Mono Silk</span>
</a>
</div>

Change the Markup so that image comes after the link.
Then css will get the link to be in center of parent:
.product-container {
position:relative;
background-color: #000000;
}
.product-btn {
position: absolute;
top:50%;
left: 50%;
background-color: rgba(0,0,0, 0.3);
width: 50%;
border: 1px solid #e1e1e1;
color: #ffffff;
padding: 5px 0;
transform: translate(-50%, -50%);
}
.product-img {
width:100%;
height: auto;
opacity: 1;
transition:
opacity 0.1s ease-in-out;
-moz-transition: opacity 0.1s ease-in-out;
-webkit-transition: opacity 0.1s ease-in-out;
}
.product-container > a:hover + img {opacity: 0.5;}
<div class="product-container">
<a href="http://google.se">
<p class="product-btn">Mono Silk</p>
</a>
<img class="product-img" src="http://dev2015.proformat.se/wp-content/uploads/2016/02/monosilk.jpg"></div>
</div>

In CSS (slow the style change in product-container and make hover action for it):
.product-container {position:relative; background-color: #000000;
transition: opacity 0.1s ease-in-out;
-moz-transition: opacity 0.1s ease-in-out;
-webkit-transition: opacity 0.1s ease-in-out;
}
/*.product-img:hover {opacity: 0.5;}*/
.product-container:hover img {opacity: 0.5;}
In HTML (put link inside the .product-container div):
<div class="product-container"><img class="product-img" src="./Material _ ProFormat AB_files/monosilk.jpg"/><p class="product-btn">Mono Silk</p></div>

Adjust the markup so the image and text are inside of the link:
<div class="col-sm-3 text-center">
<a href="http://google.se" class="product-container">
<img class="product-img" src="http://dev2015.proformat.se/wp-content/uploads/2016/02/monosilk.jpg" alt="">
<div class="product-btn">Mono Silk</div>
</a>
</div>
This removes an extra container (moving the product-container class to the link). Then update styles to something like:
.product-container {
position:relative;
background-color: #000000;
display: block;
height: 426px;
width: 426px;
}
.product-img {
width: 426px;
height: 426px;
}
.product-btn {
position: absolute;
top: 39%;
left: 0;
right: 0;
margin: 0 auto;
background-color: rgba(0,0,0, 0.3);
width: 50%;
border: 1px solid #e1e1e1;
color: #ffffff;
padding: 5px 0;
text-align: center;
}
.product-container:hover .product-img {opacity: 0.5;}
.product-container:hover .product-btn {background: rgba(0,0,0,1)}
Note that the link (.product-container) has display: block; and a set width and height, as does the image. Adjust as needed.
The advantage to this is that the entire box is now one big clickable button.

A cool trick is using pseudo elements to vertically align inline blocks. This allows for multiple lines of text to also be aligned properly.
I apologise as I'm at work at the moment, so I hope this fiddle helps.
Will go into more detail in an update later if requested:
https://jsfiddle.net/pj5p0s3s/
/*Disgusting stuff for demo :) */
.product-container {
float:left;
margin-right:5px;
max-width:200px;
}
/* */
.product-container {
position:relative;
background-color: #000000;
}
.product-container a {
display:block;
}
.product-container a:after {
content:"";
background: rgba(0,0,0, 0.3);
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
}
.product-container a:hover:after {
background: rgba(0,0,0,0.6);
transition: 0.3s;
}
.product-container-overlay {
position:absolute;
top:0;
bottom:0;
left:0;
right:0;
text-align:center;
z-index:1;
}
.product-container-overlay:before {
content:"";
height:100%;
display:inline-block;
width:1px;
vertical-align:middle;
}
.product-btn {
background-color: rgba(0,0,0, 0.3);
width: 50%;
border: 1px solid #e1e1e1;
color: #ffffff;
padding: 5px 0;
display:inline-block;
vertical-align:middle;
}
.product-img {
width:100%;
height: auto;
display:block;
}
.product-img:hover {
opacity: 0.5;
}
<div class="product-container">
<a href="http://google.se">
<div class="product-container-overlay">
<p class="product-btn">Mono Silk</p>
</div>
<img class="product-img" src="http://dev2015.proformat.se/wp-content/uploads/2016/02/monosilk.jpg"/>
</a>
</div>
<div class="product-container">
<a href="http://google.se">
<div class="product-container-overlay">
<p class="product-btn">Mono Silk long title lipsum</p>
</div>
<img class="product-img" src="http://dev2015.proformat.se/wp-content/uploads/2016/02/monosilk.jpg"/>
</a>
</div>
<div class="product-container">
<a href="http://google.se">
<div class="product-container-overlay">
<p class="product-btn">Mono Silk</p>
</div>
<img class="product-img" src="http://dev2015.proformat.se/wp-content/uploads/2016/02/monosilk.jpg"/>
</a>
</div>

Related

link hover stoped by text

Help i work on hover link effect, the effect is opacity. The effect is working but it stop when i hover the caption inside it its stop the effect.
here the code of the css:
a .hover11 img {
opacity: 1;
-webkit-transition: .3s ease-in-out;
transition: .3s ease-in-out;
}
a .hover11 img:hover {
opacity: .5;
}
.imagebig {
position: relative;
width: 24%;
/* for IE 6 */
height: 60%;
background: #D9138E;
background: linear-gradient(#D9138E, rgba(0, 0, 0, 0));
border: solid 1px #FFFFFF;
display: inline-block;
}
h2 {
position: absolute;
bottom: -10px;
left: 0;
width: 100%;
display: block;
<a href="">
<div class="imagebig hover11" align="left">
<img style="width:100%; height:100%" src="//placehold.it/100" alt="" />
<h2>Kung Fu Panda</h2>
</div>
</a>
The last one is the html. Is there anyway to stop the h2 stopping the effect when hover ? I already try user-select its not work
try this
a .hover11:hover img {
opacity: .5;
}
instead of this :
a .hover11 img:hover{
opacity: .5;
}
You have given hover effect on image tag only that's the reason your hover effect don't work on text.
So instead of giving hover effect on image tag give hover effect on outer div and it will work for both image as well as text.
Use this:
a .hover11:hover img {
opacity: .5;
}
Just add pointer-events: none; this will prevent the hover effect on h2
a .hover11 img {
opacity: 1;
-webkit-transition: .3s ease-in-out;
transition: .3s ease-in-out;
}
a .hover11 img:hover {
opacity: .5;
}
.imagebig {
position: relative;
width: 24%;
/* for IE 6 */
height: 60%;
background: #D9138E;
background: linear-gradient(#D9138E, rgba(0, 0, 0, 0));
border: solid 1px #FFFFFF;
display: inline-block;
}
h2 {
position: absolute;
bottom: -10px;
left: 0;
width: 100%;
display: block;
pointer-events: none;
}
<a href="">
<div class="imagebig hover11" align="left">
<img style="width:100%; height:100%" src="//placehold.it/100" alt="" />
<h2>Kung Fu Panda</h2>
</div>
</a>

div button to slide in and off screen (depending user's mouse)

I have a div with class .side-buttons. This div will slide in and off when user's mouse hover over the div. I was wondering how can I hide the div completely and say when the user's mouse is in the area it would slide in?
I tried getting the off the screen but that wouldn't work as it would only work when my mouse on the div
This is my website - http://smati.ca/test/index.html (Don't click continue but instead click around the popup modal to get off the modal overlay. There you can see the div in action)
Here's my css code :
.side-buttons {
position: absolute;
right: -100px;
top: 55%;
-webkit-transition: all .4s ease-in-out;
-moz-transition: all .4s ease-in-out;
-ms-transition: all .4s ease-in-out;
-o-transition: all .4s ease-in-out;
transition: all .4s ease-in-out;
}
.side-buttons:hover {
right: 0px;
}
.side-buttons a {
display: block;
background: linear-gradient(to bottom, #33a9c3 15%, #b1ccbb 100%);
border-radius: 0;
box-shadow: none;
border: none;
color: #f5f5f5;
font-size: 22px;
font-family: "Lato", sans-serif;
}
.side-buttons a small {
font-size: 16px;
}
.side-buttons a:hover,
.side-buttons a:focus,
.side-buttons a:active {
background: linear-gradient(to bottom, #33a9c3 15%, #b1ccbb 100%);
color: #f5f5f5;
}
.side-buttons a:nth-child(2) {
background: linear-gradient(to left, #de3c88 15%, #f0a473 100%);
}
You could try something like this too i.e wrapping it by a div and performing that slide-in and slide-out effect on child div as below,
#bx{
width:210px;
height:120px;
position:absolute;
top:40%;
right:0;
overflow:hidden;
border:1px solid rgba(0,0,0,0.1);
}
#bx > .b{
position:absolute;
width:200px;
height:120px;
background:blue;
right:-200px;
transition:0.6s ease;
}
#bx:hover > .b{
right:0px;
}
<div id="bx">
<div class="b">
</div>
</div>
You can use a pseudo element, like this
html, body {
margin: 0;
}
div {
position: absolute;
width: 0;
right: 0;
height: 150px;
background: red;
transition: width 0.5s;
}
div::after {
content: '';
position: absolute;
width: 30px;
right: 100%;
height: 100%;
transition: width 0s 0.5s;
border: 1px dotted gray; /* added for demo purpose */
}
div:hover {
width: 100px;
transition: width 0.5s;
}
div:hover::after {
width: 0;
transition: width 0.5s;
}
<div>
</div>
Here is another option, that might be easier to add to your existing solution
html, body {
margin: 0;
}
.content {
width: 170px;
padding: 50px 30px;
background: lightgray;
}
.wrapper {
position: absolute;
right: 0;
width: 0;
padding-left: 30px;
overflow: hidden;
transition: width 0.5s, padding-left 0s 0.5s;
border: 1px dotted gray; /* added for demo purpose */
}
.wrapper:hover {
width: 200px;
padding-left: 0;
transition: width 0.5s, padding-left 0.5s;
}
<div class="wrapper">
<div class="content">
Some text and/or images<br>
or anything else needed
</div>
</div>

how to give image fade effect on hover?

How to make fade hover change on a parent div when we hover over a child div?
I want the hover to have a fade effect and change the background image of the parent div. The change is happening very fast. I want the change to happen and slowly and smoothly.
<script>
$('#hoverdiv').on('mouseover', function(){
$(this).parent().addClass('is-hover');
}).on('mouseout', function(){
$(this).parent().removeClass('is-hover');
})
</script>
.bground {
width:100%;
position:relative;
background: url(../img/bg1.jpg) no-repeat top center;
}
.bground:after {
content: url(../img/bg2.jpg);
width:0;
height:0;
display:none;
}
.is-hover {
background: url(../img/bg2.jpg) no-repeat top center;
}
#hoverdiv
{
width:auto;
height:auto;
margin:0 auto;
padding:0;
}
<section id="bground" class="bground">
<div id="hoverdiv">
<div class="display">
<img src="img/logo.png" alt="Logo">
</div>
<div class="page-scroll">
<a href="#about" class="btn btn-circle" style="color:#000000">
<i class="fa fa-angle-double-down animated"></i>
</a>
</div>
</div>
</section>
You are adding and removing class with js which cannot be slow down.
What you can do is add transition in css
.is-hover {
background: url(../img/bg2.jpg) no-repeat top center;
transition:all ease-in-out 0.3s;
-moz-transition:all ease-in-out 0.3s;
-ms-transition:all ease-in-out 0.3s;
-o-transition:all ease-in-out 0.3s;
-webkit-transition:all ease-in-out 0.3s;
}
It is important to add prefix like -moz-, -webkit- etc to let it work in all browsers.
There is no need for javascript. You can easily achieve this with css transitions:
.bground {
width: 400px;
height: 300px;
background: #aaa url("http://placehold.it/300x200/ffff00") no-repeat top center;
position: relative;
}
.bground:after {
content: "";
background: url("http://placehold.it/300x200/ff0000") no-repeat top center;
position: absolute;
left: 0;
width: 100%;
height: 100%;
visibility: hidden;
opacity: 0;
transition: all .3s;
}
.bground:hover:after {
visibility: visible;
opacity: 1;
}
<div class="bground"></div>
.bground {
width: 400px;
height: 300px;
background: #aaa url("http://placehold.it/300x200/ffff00") no-repeat top center;
position: relative;
}
.bground:after {
content: "";
background: url("http://placehold.it/300x200/ff0000") no-repeat top center;
position: absolute;
left: 0;
width: 100%;
height: 100%;
visibility: hidden;
opacity: 0;
transition: all .5s linear 0s;
}
.bground:hover:after {
visibility: visible;
opacity: 1;
color:#fff;
}
<div class="bground"></div>

Show a thumbnail caption on hover centered

I'm trying to show a thumbnail caption on hover centered: aligned horizontal and vertical, but not successful.
In the fiddle you see a responsive thumbnail grid with on hover a caption. I gave it a dashed red border so you can see that it is not same size as the thumbnail. I can't get the title caption to be centered in the thumbnail. Maybe my thumbnail grid need a different build. Hope someone can help me.
Here is the fiddle
#content {
position: relative;
display: inline-block;
margin: 110px 40px 100px 40px;
background-color: transparent;
}
.col-25 {
position: relative;
float: left;
width: 25%;
margin: 0;
}
.thumb {
display: block;
margin: 10px;
}
.col-25 img {
width: 100%;
height: auto;
}
.col-25 a:hover img {
opacity: 0.1;
}
.caption {
position: absolute;
top:0;
left:0;
border: dashed 1px red;
width:100%;
height:100%;
opacity: 0;
text-align:center;
vertical-align: middle;
z-index:2;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
-ms-transition: all 0.3s;
-o-transition: all 0.3s;
transition: all 0.3s;
}
.col-25 a:hover .caption {
opacity: 1;
}
http://jsfiddle.net/a0zwecou/14/
I have added an inner div to caption and give it a margin height of 25%. Remove the margin for extremely small width size in your media query.
<div class="caption">
<div class="inner-caption">
<h3>Untitled for now</h3>
<p>Caption</p>
</div>
</div>
CSS -
.inner-caption{margin-top:25%;}
JSFIIDLE
only by changing the height and adding padding to caption class.
.caption {
position: absolute;
padding-top:25%;
top:0;
left:0;
border: dashed 1px red;
width:100%;
height:60%;
opacity: 0;
text-align:center;
vertical-align: middle;
z-index:2;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
-ms-transition: all 0.3s;
-o-transition: all 0.3s;
transition: all 0.3s;
}
Try this,
.thumb:hover{border:1px dashed red;background-color:red;}
.caption {
position: absolute;
top:40%;
left:0;
/*border: dashed 1px red;*/ //remove it
width:100%;
/*height:100%;*/ // remove it
opacity: 0;
text-align:center;
vertical-align: middle;
z-index:2;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
-ms-transition: all 0.3s;
-o-transition: all 0.3s;
transition: all 0.3s;
}
Fiddle : http://jsfiddle.net/a0zwecou/20/
see the fiddle here:
http://jsfiddle.net/a0zwecou/13/
and add css:
.caption h3 {
margin-top: 59px;
}
You can simply wrap your caption inside another div and centered that with transate(with all prefixes of course), OR you can simply center that using tables (table + table-cell)
HERE THE PEN, hover the first.
.insideCap{
background: red;
top: 50%;
position: absolute;
width: 100%;
transform: translateY(-50%);
}
OTHER WAY:
parent{
dispaly:table;
}
son{
display: table-cell;
vertical-align: middle;
}
you can try this:
<div id="content">
HTML:
Add this div:
<div class="col-25">
<a class="thumb" href="#">
<img src="http://fakeimg.pl/500x310/999/">
<div class="caption"><div class="caption-text"><h3>Untitled for now</h3><p>Caption</p></div></div>
</a>
</div>
CSS:
add this css in your style:
.caption-text {
left: 0;
position: absolute;
right: 0;
top: 32%;
}
SEE JS Fiddle DEMO

CSS3 opacity effect

I've found a piece of CSS code that works pretty well on my website but am having troubles having the effect work exactly to specification.
What I'm trying to do: I'd like the images at default to have an opacity of 1.0, but when you scroll over any of the images then the images will go to an opacity of 0.3. This currently works, and you can view the jsfiddle here: http://jsfiddle.net/raybullard/C8NMs/
Below is the HTML and CSS:
<div id="wrap">
<div id="columns" class="columns_3">
<div class="figure">
<img src="http://i.imgur.com/ruU04I6.jpg">
</div>
<div class="figure">
<img src="http://i.imgur.com/ruU04I6.jpg">
</div>
<div class="figure">
<img src="http://i.imgur.com/ruU04I6.jpg">
</div>
<div class="figure">
<img src="http://i.imgur.com/ruU04I6.jpg">
</div>
<div class="figure">
<img src="http://i.imgur.com/ruU04I6.jpg">
</div>
#wrap{
width:240px;
}
.columns_3 .figure{
width:70px;
margin-right:0px;
}
.columns_3 .figure:nth-child(3){
margin-right: 0;
}
#columns .figure:hover{
-webkit-transform: scale(1.1);
-moz-transform:scale(1.1);
transform: scale(1.1);
}
#columns:hover .figure:not(:hover) {
opacity: 0.4;
}
div#columns .figure {
display: inline-block;
background: #FEFEFE;
border: 2px solid #FAFAFA;
box-shadow: 0 1px 2px rgba(34, 25, 25, 0.4);
margin: 3px 3px 3px 0px;
-webkit-column-break-inside: avoid;
-moz-column-break-inside: avoid;
column-break-inside: avoid;
background: -webkit-linear-gradient(45deg, #FFF, #F9F9F9);
opacity: 1;
-webkit-transition: all .3s ease;
-moz-transition: all .3s ease;
-o-transition: all .3s ease;
transition: all .3s ease;
-moz-border-radius: 5px;
border-radius: 5px;
}
div#columns .figure img {
width: 60px;
height:50px;
border-bottom: 1px solid #ccc;
margin-bottom: 0px;
}
The problem is that the entire #columns div is called out, and since I have only 5 icons if you scroll over where the sixth icon 'should be' the entire div changes opacity.
What I'd like to do is to have the non-active icons change opacity to 0.3 at the .figure level (rather than #columns level) when a user scrolls over an icon if possible.
Any help/suggestions are appreciated!
Thanks.
Just add property value of display: inline to #columns block of CSS code and you're good to go.
Solution: Adding property value of display: inline to #columns Makes it technically present only in the areas where it contains something.
#columns {
display: inline;
/* This block of CSS solves your problem */
}
#wrap {
width: 240px;
}
.columns_3 .figure {
width: 70px;
margin-right: 0px;
}
.columns_3 .figure:nth-child(3) {
margin-right: 0;
}
#columns .figure:hover {
-webkit-transform: scale(1.1);
-moz-transform: scale(1.1);
transform: scale(1.1);
}
#columns:hover .figure:not(:hover) {
opacity: 0.4;
}
div#columns .figure {
display: inline-block;
background: #FEFEFE;
border: 2px solid #FAFAFA;
box-shadow: 0 1px 2px rgba(34, 25, 25, 0.4);
margin: 3px 3px 3px 0px;
-webkit-column-break-inside: avoid;
-moz-column-break-inside: avoid;
column-break-inside: avoid;
background: -webkit-linear-gradient(45deg, #FFF, #F9F9F9);
opacity: 1;
-webkit-transition: all .3s ease;
-moz-transition: all .3s ease;
-o-transition: all .3s ease;
transition: all .3s ease;
-moz-border-radius: 5px;
border-radius: 5px;
}
div#columns .figure img {
width: 60px;
height: 50px;
border-bottom: 1px solid #ccc;
margin-bottom: 0px;
}
<div id="wrap">
<div id="columns" class="columns_3">
<div class="figure">
<a href="http://www.burton.com">
<img src="http://i.imgur.com/ruU04I6.jpg">
</a>
</div>
<div class="figure">
<a href="http://www.burton.com">
<img src="http://i.imgur.com/ruU04I6.jpg">
</a>
</div>
<div class="figure">
<a href="http://www.burton.com">
<img src="http://i.imgur.com/ruU04I6.jpg" />
</a>
</div>
<div class="figure">
<a href="http://www.burton.com">
<img src="http://i.imgur.com/ruU04I6.jpg" />
</a>
</div>
<div class="figure">
<a href="http://www.burton.com">
<img src="http://i.imgur.com/ruU04I6.jpg" />
</a>
</div>
This is happening because the columns div extend to the size to its child, and is being hovered.
If you don't need more positioning in the rest of the layout, you can cut it
.columns_3 {
height: 0px;
}
and so avoid it being hovered
demo
i dont know if you're open to jquery, but here's a solution with jquery: http://jsfiddle.net/C8NMs/6/
This solution works for all elements with class .figure, no matter where you place them on the page.
$(document).ready(function() {
$('.figure').on('mouseover', function() {
var element = $(this);
$('.figure').not(element).css('opacity', 0.4);
})
$('.figure').on('mouseout', function() {
$('.figure').css('opacity', 1);
});
});