The div tags are nested as
<div class="Site-wrapper" id="Site-wrapper">
<div id="Main-Menu-mobile" class="Main-Menu-mobile">
<div class="Site">
</div>
</div>
</div>
The logic for the menu is just these 4 CSS classes
.Site-wrapper {
position: relative;
width: 100%;
overflow: hidden;
}
.nav-open .Site {
left: auto;
transform: translate3d(70%, 0, 0);
}
.Site {
position: relative;
left: 0;
min-height: 100%;
background-color: #e4e4e4;
transition: 0.2s ease all;
}
.Main-Menu-mobile {
width: 70%;
position: absolute;
top: 0;
left: 0;
padding: 15px;
}
https://codepen.io/taufeq-orangejulius-razakh/pen/dypgjNO
Your Site-Wrapper div (The parent one) only has a height of 41px. And this stays the same even when the toggler button translates to right. This is where the implementation is a bit off.
Try removing your overflow:hidden from .Site-wrapper
.Site-wrapper {
position: relative;
width: 100%;
/* overflow: hidden; This needs to be implemented well*/
}
What you can do, is once the Hamburger icon is clicked change the overflow property value in Javascript.
I made an image that when hovered upon will change the opacity of the div on top of it. The div should be the same size as the image. I have managed to place the div on top of the image. However, when I set the width and height to 100%, the div covered the image INCLUDING the image's margin. I want to know how to fix it so that the div can only cover the image with the margin not included. Please note that I need the image to be responsive, so I do not want to set the height in pixels as much as possible.
Here's the fiddle:
https://jsfiddle.net/gsuxlzt/77vn1uyg/
Here's the code:
.margin {
margin-bottom: 10px;
}
.photo-thumbnail {
position: relative;
}
.photo-title {
width: 100%;
height: 100%;
background-color: #cbe1f4;
z-index: 10;
position: absolute;
top: 0;
left: 0;
color: #18121e;
text-align: center;
opacity: 0;
transition: opacity 0.5s linear;
}
.photo-title:hover {
opacity: .9;
}
<div class="photo-thumbnail">
<img class="img-responsive img-thumbnail margin photo-thumbnail" src="http://i36.photobucket.com/albums/e20/kingjami/photo-frame_zpsljshbjdq.jpg" />
<a href=#>
<div class="photo-title">
<h2 style="padding: 20% 0 20% 0;">Project Title</h2>
</div>
</a>
</div>
You can try this code:
Html Code:
<div class="photo-thumbnail"><img class="img-responsive img-thumbnail margin photo-thumbnail" src="http://i36.photobucket.com/albums/e20/kingjami/photo-frame_zpsljshbjdq.jpg"/><a href=#>
<div class="photo-title">
<h2 style="padding: 20% 0 20% 0;">Project Title</h2>
</div>
</a>
CSS Code:-
.margin {
margin-bottom: 10px;
}
.img-thumbnail{padding:0px;}
.photo-thumbnail {
position: relative;
}
.photo-title {
width: 100%;
height: 100%;
background-color: #cbe1f4;
z-index: 10;
position: absolute;
top: 0;
left: 0;
color: #18121e;
text-align: center;
opacity: 0;
transition: opacity 0.5s linear;
}
.photo-title:hover {
opacity: .9;
}
https://jsfiddle.net/Dhavalr/77vn1uyg/8/
first of all, don't use padding and margin for <img> instead use it for .photo-thumbnail
and use this code.
.photo-thumbnail {
position: relative;
display: inline-block;
vertical-align: top;
}
using inline-block for the parent can make image flexible as well as only occupy the necessary area as image.
try this, it will work.
In your example you are missing the closing of your "photo-thumbnail"
You are not obligated to use "Width: 100%", "Height: 100%", when you have an absolutely positioned element, instead you can make it take all of the space with
top: 0;
right: 0;
bottom: 0;
left: 0;
And in your case you can set the
bottom: 10px;
since that is how much your div gets out of the picture
here is an example in a fiddle: https://jsfiddle.net/77vn1uyg/3/
I have two divs that have an opacity less than 1. When hovering I would like to increase the opacity to 1 but can't seem to get it to work. Not sure if it is because of the z-index I have in the css. I need the z-index to prevent the whole div having reduced opacity.
This is the html
<section class="events">
<div class="events-wrapper">
<h2>Select the session you would like to attend for more information</h2>
<div class="melbourne-left">
<div class="melbourne-left-background">
<h1>Melbourne</h1>
<h3>Sunday Jan 21st 2015</h3>
</div>
</div>
<div class="sydney-right">
<div class="sydney-right-background">
<h1>Sydney</h1>
<h3>Sunday Feb 1st 2015</h3>
</div>
</div>
</div>
</section>
And this is the css for the 'melbourne' divs
.melbourne-left {
display: block;
float: left;
width: 44%;
clear: both;
margin-left: 5%
}
.melbourne-left-background {
position: relative;
z-index: 1;
min-height: 420px;
}
.melbourne-left-background::before {
content: "";
position: absolute;
z-index: -1;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: url(http://melbourne.jpg) center center;
opacity: .4;
width: 100%;
max-width: 855px;
background-repeat: no-repeat;
}
.melbourne-left-background:hover {
opacity: 1.0;
}
You are setting the opacity on the :before psuedo element of .melbourne-left-background, however you are detecting the :hover state and changing opacity for the DOM element and not the psuedo.
As such, change:
.melbourne-left-background:hover {
opacity: 1.0;
}
To
.melbourne-left-background:hover::before {
opacity: 1.0;
}
I have the css transition working when the user hovers over item however when the mouse exits the div, content is pushed below during the transition. Below is my html/css along with a jsfiddle to show what I mean.
html:
<div id="container">
<div class="item">
<div class="img">
</div>
<div class="heading">
</div>
</div>
</div>
css:
#container {
width: 100%;
height: 100%;
}
.item {
width: 100%;
height: 400px;
position: relative;
}
.img {
background: #000;
width: 40%;
height: 400px;
float: left;
transition: width 0.5s ease;
}
.heading {
width: 60%;
height: 400px;
float: right;
background: #900;
transition: width 0.5s ease;
}
.item:hover .img {
width: 100%;
}
.item:hover .heading {
width: 100%;
background:rgba(255,255,255, 0.9);
position: absolute;
top:0;
left:0;
}
JSFiddle
I am sure it is a simple position problem. However, I am not familiar enough with the transition to know where to find the answer.
Updated position to
tranform: translateY(-100%);
in order to get rid of the non-transition property. Now before/after :hover the div heading gets pushed below item. Updated JSFiddle to show.
Updated transition: all to transition: width on both img and heading which fixed heading getting pushed below img on :hover, however the original problem of heading being pushed below when user exits :hover is still an issue.
I think I found the answer:
by making heading have position:absolute;, I can have it forced to stay inside of the item div, keeping it from moving below it. So my updated css (with actual class names and production stuff) looks like;
.flight {
height: 400px;
position: relative;
}
.flight-img {
background: red;
background-size: cover;
width: 40%;
height: 400px;
float: left;
position: relative;
/* CSS Animation Effects */
transition: width 0.5s ease;
}
.flight-heading {
width: 60%;
float: left;
position: absolute;
top: 50%;
right: 0;
transform: translateY(-50%);
transition: width 0.5s ease;
}
/* Alternate img float ***
/* Probably an easier way but this works for now */
.flight:nth-of-type(4n-1) .flight-img{
float: right;
}
.flight:nth-of-type(4n-3) .flight-img{
float: left;
}
.flight:nth-of-type(4n-1) .flight-heading{
left:0;
}
.flight:nth-of-type(4n-3) .flight-heading{
float: right;
}
/* Adding hover effects for desktop */
.flight:hover .flight-img {
width: 100%;
}
.flight:hover .flight-heading {
width: 100%;
position:absolute;
top:0;
left:0;
transform: translateY(50%);
background: rgba(0,0,0,0.75);
color: #fff;
h2 {
color: #fff;
}
}
while my html looks like:
<div id="flights">
<div class="flight">
<div class="flight-img"></div>
<div class="flight-heading">
<h2>Shared Flights</h2>
<p>The shared flight option is available for 1 to 5 people. This is our most economical flight. You will fly with other passengers that are booked that day.</p>
<button>Book Now</button>
</div>
</div>
<div class="clear"></div>
</div><!-- End Flights -->
with a JSFiddle to show. I know the animation needs work, but I figure making it smooth will be easy now that the divs stay in one place.
I'm trying to add a transparent black overlay to an image whenever the mouse is hovering over the image with only CSS. Is this possible? I tried this:
http://jsfiddle.net/Zf5am/565/
But I can't get the div to show up.
<div class="image">
<img src="http://www.newyorker.com/online/blogs/photobooth/NASAEarth-01.jpg" alt="" />
<div class="overlay" />
</div>
.image {
position: relative;
border: 1px solid black;
width: 200px;
height: 200px;
}
.image img {
max-width: 100%;
max-height: 100%;
}
.overlay {
position: absolute;
top: 0;
left: 0;
display: none;
background-color: red;
z-index: 200;
}
.overlay:hover {
display: block;
}
I'd suggest using a pseudo element in place of the overlay element. Because pseudo elements can't be added on enclosed img elements, you would still need to wrap the img element though.
LIVE EXAMPLE HERE -- EXAMPLE WITH TEXT
<div class="image">
<img src="http://i.stack.imgur.com/Sjsbh.jpg" alt="" />
</div>
As for the CSS, set optional dimensions on the .image element, and relatively position it. If you are aiming for a responsive image, just omit the dimensions and this will still work (example). It's just worth noting that the dimensions must be on the parent element as opposed to the img element itself, see.
.image {
position: relative;
width: 400px;
height: 400px;
}
Give the child img element a width of 100% of the parent and add vertical-align:top to fix the default baseline alignment issues.
.image img {
width: 100%;
vertical-align: top;
}
As for the pseudo element, set a content value and absolutely position it relative to the .image element. A width/height of 100% will ensure that this works with varying img dimensions. If you want to transition the element, set an opacity of 0 and add the transition properties/values.
.image:after {
content: '\A';
position: absolute;
width: 100%; height:100%;
top:0; left:0;
background:rgba(0,0,0,0.6);
opacity: 0;
transition: all 1s;
-webkit-transition: all 1s;
}
Use an opacity of 1 when hovering over the pseudo element in order to facilitate the transition:
.image:hover:after {
opacity: 1;
}
END RESULT HERE
If you want to add text on hover:
For the simplest approach, just add the text as the pseudo element's content value:
EXAMPLE HERE
.image:after {
content: 'Here is some text..';
color: #fff;
/* Other styling.. */
}
That should work in most instances; however, if you have more than one img element, you might not want the same text to appear on hover. You could therefore set the text in a data-* attribute and therefore have unique text for every img element.
EXAMPLE HERE
.image:after {
content: attr(data-content);
color: #fff;
}
With a content value of attr(data-content), the pseudo element adds the text from the .image element's data-content attribute:
<div data-content="Text added on hover" class="image">
<img src="http://i.stack.imgur.com/Sjsbh.jpg" alt="" />
</div>
You can add some styling and do something like this:
EXAMPLE HERE
In the above example, the :after pseudo element serves as the black overlay, while the :before pseudo element is the caption/text. Since the elements are independent of each other, you can use separate styling for more optimal positioning.
.image:after, .image:before {
position: absolute;
opacity: 0;
transition: all 0.5s;
-webkit-transition: all 0.5s;
}
.image:after {
content: '\A';
width: 100%; height:100%;
top: 0; left:0;
background:rgba(0,0,0,0.6);
}
.image:before {
content: attr(data-content);
width: 100%;
color: #fff;
z-index: 1;
bottom: 0;
padding: 4px 10px;
text-align: center;
background: #f00;
box-sizing: border-box;
-moz-box-sizing:border-box;
}
.image:hover:after, .image:hover:before {
opacity: 1;
}
CSS3 filter
Although this feature is only implemented in webkit, and it doesn't have browser compatibility, but It's worth taking a look at:
.image img {
max-width: 100%;
max-height: 100%;
-webkit-transition: .2s all;
}
.image img:hover {
-webkit-filter: brightness(50%);
}
JSFiddle Demo
References
https://dvcs.w3.org/hg/FXTF/raw-file/tip/filters/index.html
http://www.html5rocks.com/en/tutorials/filters/understanding-css/
https://developer.mozilla.org/en-US/docs/Web/CSS/filter
http://davidwalsh.name/css-filters
http://net.tutsplus.com/tutorials/html-css-techniques/say-hello-to-css3-filters/
Similar topics on SO
How to Decrease Image Brightness in CSS
Convert an image to grayscale in HTML/CSS
Defined Edges With CSS3 Filter Blur
You were close. This will work:
.image { position: relative; border: 1px solid black; width: 200px; height: 200px; }
.image img { max-width: 100%; max-height: 100%; }
.overlay { position: absolute; top: 0; left: 0; right:0; bottom:0; display: none; background-color: rgba(0,0,0,0.5); }
.image:hover .overlay { display: block; }
You needed to put the :hover on image, and make the .overlay cover the whole image by adding right:0; and bottom:0.
jsfiddle: http://jsfiddle.net/Zf5am/569/
Here's a good way using :after on the image div, instead of the extra overlay div: http://jsfiddle.net/Zf5am/576/
<div class="image">
<img src="http://www.newyorker.com/online/blogs/photobooth/NASAEarth-01.jpg" alt="" />
</div>
.image {position:relative; border:1px solid black; width:200px; height:200px;}
.image img {max-width:100%; max-height:100%;}
.image:hover:after {content:""; position:absolute; top:0; left:0; bottom:0; right:0; background-color: rgba(0,0,0,0.3);}
.overlay didn't have a height or width and no content, and you can't hover over display:none.
I instead gave the div the same size and position as .image and changes RGBA value on hover.
http://jsfiddle.net/Zf5am/566/
.image { position: absolute; border: 1px solid black; width: 200px; height: 200px; z-index:1;}
.image img { max-width: 100%; max-height: 100%; }
.overlay { position: absolute; top: 0; left: 0; background:rgba(255,0,0,0); z-index: 200; width:200px; height:200px; }
.overlay:hover { background:rgba(255,0,0,.7); }
See what I've done here: http://jsfiddle.net/dyarbrough93/c8wEC/
First off, you never set the dimensions of the overlay, meaning it wasn't showing up in the first place. Secondly, I recommend just changing the z-index of the overlay when you hover over the image. Change the opacity / color of the overlay to suit your needs.
.image { position: relative; width: 200px; height: 200px;}
.image img { max-width: 100%; max-height: 100%; }
.overlay { position: absolute; top: 0; left: 0; background-color: gray; z-index: -10; width: 200px; height: 200px; opacity: 0.5}
.image:hover .overlay { z-index: 10}
You can accomplish this by playing with the opacity of the image and setting the background color of the image to black. By making the image transparent, it will appear darker.
<div class="image">
<img src="http://www.newyorker.com/online/blogs/photobooth/NASAEarth-01.jpg" alt="" />
</div>
CSS:
.image { position: relative; border: 1px solid black; width: 200px; height: 200px; background: black; }
.image img { max-width: 100%; max-height: 100%; }
.image img:hover { opacity: .5 }
You might need to set the browser-specific opacity too to make this work in other browsers too.
I would give a min-height and min-width to your overlay div of the size of the image, and change the background color on hover
.overlay { position: absolute; top: 0; left: 0; z-index: 200; min-height:200px; min-width:200px; background-color: none;}
.overlay:hover { background-color: red;}