Position two images on top of another - html

I have some social media icons at the bottom of my page. They are png images, and I would like to replace those images with a different one when they are hovered. I want to use the first solution given here and put the two images on top of one another.
However, I'm having trouble putting the images on top of each other. I'm not sure what the right positioning is to use in order to make this work. Can someone give me a hint? (Not insterested in using JavaScript for this, I don't know how that works yet.
HTML
<div class="footer" align="center">
<ul>
<li>Follow Us:</li>
<a><img src="Images/Social Icons/Facebook-Hover.png"><img src="Images/Social Icons/Facebook.png"></a>
<a><img src="Images/Social Icons/Twitter-Hover.png"><img src="Images/Social Icons/Twitter.png"></a>
<a><img src="Images/Social Icons/Instagram-Hover.png"><img src="Images/Social Icons/Instagram.png"></a>
<a><img src="Images/Social Icons/Pinterest-Hover.png"><img src="Images/Social Icons/Pinterest.png"></a>|
<li><a>About Us</a></li> |
<li><a>Ask Us</a></li> |
<li><a>Contact Us</a></li>
</ul>
</div>
CSS:
.footer {
background-color: #061336;
padding: 15px;
padding-bottom: 25px;
position: fixed;
width: 100%;
bottom: 0px;
}
.footer li {
font-family: Roboto, Arial;
margin-left: 10px;
margin-right: 20px;
display: inline-block;
text-decoration: none;
color: #ffffff;
transition: ease-in-out all 200ms;
-moz-transition: ease-in-out all 200ms;
-webkit-transition: ease-in-out all 200ms;
-o-transition: ease-in-out all 200ms;
}
.footer li:hover {
opacity: .7;
transition: ease-in-out all 200ms;
-moz-transition: ease-in-out all 200ms;
-webkit-transition: ease-in-out all 200ms;
-o-transition: ease-in-out all 200ms;
}
.footer img {
height: 25px;
margin-left: 3px;
margin-right: 3px;
right: 13px;
top: 6px;
position: relative;
}

There's a pretty simple solution using the :first-child CSS selector.
.footer ul a {
display: block;
position: relative;
width: [your icon width]px;
height: [your icon height]px;
}
.footer ul a img {
position: absolute;
top: 0;
left: 0;
}
.footer ul a img:first-child {
opacity: 0;
z-index: 10;
position: absolute;
top: 0;
left: 0;
}
.footer ul a:hover img:first-child {
opacity: 0.7;
}

Create sprite sheet images - Here you can find tutorial how to create http://css-tricks.com/css-sprites/

This is what I would do instead, because, this way I don't have to struggle with "margin-top: -100px", or worse, javascript.
.myicon{
width:50px;
height:50px;
background:red;
-moz-transition: background .25s ease-in-out;
-webkit-transition: background .25s ease-in-out;
transition: background .25s ease-in-out;
}
.myicon:hover{
background:blue;
}
<div class='myicon'></div>

Related

Hover + to different element is not working

I found a problem with my navigation bar. Im using tag nav, ul, li for it. My intention is to make an image move according to the hover li. Not sure what is wrong with the css... I want to make the li:nth-child(3) to move position using 'top' when li:nth-child(1) is hovered.
Here is my html
<nav> <img class="nav_bar" src="images/navigation_stick.png">
<ul class="subsection">
<li class="subsection">Animation
<!--<h4 class="subsection">Modelling</h4>-->
<h4 class="subsection">Project</h4>
<!--<h4 class="subsection">Reel</h4>-->
</li>
<li class="subsection">Graphic
<h4 class="subsection">Poster</h4>
<!--<h4 class="subsection">Illustration</h4>-->
</li>
<li>
<img src="images/navigation_button.png">
</li>
</ul>
</nav>
here is my css
li h4.subsection{
font-size: 14px;
font-weight: lighter;
padding-top: 0;
display: block;
max-height: 0;
opacity: 0;
transition: visibility 0s, padding 0.3s, max-height 0.3s, opacity 0.2s ease-in;
transition: padding 0.3s, max-height 0.4s, opacity 0.2s ease-out;
}
li:hover > h4{
padding-top: 5px;
max-height: 50px;
opacity: 1;
}
li:nth-child(3){
display: block;
position: fixed;
left: 92.92%;
top: 100px;
transition: all 1000ms ease;
}
li:nth-child(1):hover + li:nth-child(3){
top: 300px;
}
thanks for your kind help!
You need to use ~ instead of + in the selector. ~ is a "general sibling", where as + is the adjacent/next sibling selector. :nth-child(1) and :nth-child(3) are general siblings, not adjacent.
li h4.subsection {
font-size: 14px;
font-weight: lighter;
padding-top: 0;
display: block;
max-height: 0;
opacity: 0;
transition: visibility 0s, padding 0.3s, max-height 0.3s, opacity 0.2s ease-in;
transition: padding 0.3s, max-height 0.4s, opacity 0.2s ease-out;
}
li:hover > h4 {
padding-top: 5px;
max-height: 50px;
opacity: 1;
}
li:nth-child(3) {
display: block;
position: fixed;
left: 92.92%;
top: 100px;
transition: all 1000ms ease;
}
li:nth-child(1):hover ~ li:nth-child(3) {
top: 300px;
}
<nav> <img class="nav_bar" src="images/navigation_stick.png">
<ul class="subsection">
<li class="subsection">Animation
<!--<h4 class="subsection">Modelling</h4>-->
<h4 class="subsection">Project</h4>
<!--<h4 class="subsection">Reel</h4>-->
</li>
<li class="subsection">Graphic
<h4 class="subsection">Poster</h4>
<!--<h4 class="subsection">Illustration</h4>-->
</li>
<li>
<img src="images/navigation_button.png">
</li>
</ul>
</nav>

Adding a rollover only works on one image div

I am creating a rollover on an image div where once you roll over, the image opacity goes down and text over the top appears. This works fine for just one image, but when trying it on more then one image the opacity doesn't work correctly and the text doesn't seem to appear on the other images.
HTML:
<div class="worklongdiv" style="padding-top:111px";>
<img src="images/Vividworklong.jpg"/>
<div class="work-text-content-long">
<header>VIVID VAPOURS</header>
<p style="font-size:17px; font-family:GothamRoundedBold;">Branding • Product Dev • Web Dev</p>
</div>
</div>
<div class="worklongdiv" >
<img src="images/Vividworklong.jpg"/>
<div class="work-text-content-long">
<header>VIVID VAPOURS</header>
<p style="font-size:17px; font-family:GothamRoundedBold;">Branding • Product Dev • Web Dev</p>
</div>
</div>
CSS:
.worklongdiv{
width: 100%;
min-height: 120px;
max-height:auto
position: relative;
background-color: black;
}
.worklongdiv:hover img {
opacity: 0.3;
}
.worklongdiv:hover .work-text-content-long {
opacity: 1;
}
.worklongdiv img {
padding: 0;
width: 100%;
display: block;
opacity: 1;
}
.worklongdiv img,
.work-text-content-long {
-webkit-transition: opacity 0.5s ease-out;
-moz-transition: opacity 0.5s ease-out;
-o-transition: opacity 0.5s ease-out;
transition: opacity 0.5s ease-out;
}
.work-text-content-long {
height:100px;
position: absolute;
color: white;
left: 0;
top: 25%;
right: 0%;
left:101px;
bottom: 0;
font-size: 24px;
text-align: left;
opacity: 0;
}
You're missing a ; in one of your CSS rules.
.worklongdiv{
width: 100%;
min-height: 120px;
max-height:auto;
position: relative;
background-color: black;
}

How to make div fall beside previous div

Hello all I have two images that switch on hover. in the divs they are currently in the images overlap, both starting at the top of the div as opposed to beside it.example
<div class="storyboard">
<div class="storycard" >
<img src="Images/Articles/Index/world%20cup2.jpg" class="primary">
<img src="Images/Articles/Index/world%20cup.jpg" class="secondary">
</div>
<div class="storycard">
<img src="Images/Articles/Index/ntci2.jpg" class="primary">
<img src="Images/Articles/Index/ntci1.jpg" class="secondary">
</div>
and my css
.storyboard{
width: 100%;
padding: 30px;
}
.storycard{
position: relative;
float: left;
}
.storycard img{
position: absolute;
margin: 0 auto;
}
.storycard .secondary:hover {
position: absolute;
top: 0;
-webkit-transition: all 200ms ease-in-out;
-moz-transition: all 200ms ease-in-out;
-o-transition: all 200ms ease-in-out;
-ms-transition: all 200ms ease-in-out;
transition: all 200ms ease-in-out;
-webkit-opacity: 0;
-moz-opacity: 0;
opacity: 0;
display: block;
}
Due to the .storycard .secondry:hover as it is I cant make the .storycard img relative other wise I get this. Thanks.
First of all enclose your all div elements in a #wrapper.
and set the display of #wrapper to display:inline-block;
#wrapper{
width: 100%;
padding: 30px;
display:inline-block;
}
Then give different class to both div elements inside the #wrapper
See the Demo

CSS Drop Down List Hover mouse not work

i have a code HTML CODE:
<div class="wrapper-demo">
<div id="dd" class="wrapper-dropdown-2" tabindex="1">Sign in with
<ul class="dropdown">
<li><i class="icon-twitter icon-large"></i>Twitter</li>
<li><i class="icon-github icon-large"></i>Github</li>
<li><i class="icon-facebook icon-large"></i>Facebook</li>
</ul>
</div>
</div>
AND CSS:
.wrapper-dropdown-2 {
position: relative;
width: 200px;
margin: 0 auto;
padding: 10px 15px;
background: #fff;
border-left: 5px solid orange;
cursor: pointer;
text-align: left;
cursor: pointer;
outline: none;
}
.wrapper-dropdown-2:after {
content: "";
width: 0;
height: 0;
position: absolute;
right: 16px;
top: 50%;
margin-top: -3px;
border-width: 6px 6px 0 6px;
border-style: solid;
border-color: grey transparent;
}
.dropdown {
display:none;
}
.wrapper-dropdown-2:hover ul.dropdown {
position: absolute;
display:block;
top: 100%;
left: -5px;
right: 0px;
background: white;
-webkit-transition: all 0.3s ease-out;
-moz-transition: all 0.3s ease-out;
-ms-transition: all 0.3s ease-out;
-o-transition: all 0.3s ease-out;
transition: all 0.3s ease-out;
list-style: none;
opacity: 0;
pointer-events: none;
}
.wrapper-dropdown-2 .dropdown li a {
display: block;
text-decoration: none;
color: #333;
border-left: 5px solid;
padding: 10px;
-webkit-transition: all 0.3s ease-out;
-moz-transition: all 0.3s ease-out;
-ms-transition: all 0.3s ease-out;
-o-transition: all 0.3s ease-out;
transition: all 0.3s ease-out;
}
http://jsfiddle.net/pvt3e/
and i try, in hover mouse to: Sign in with open the drop down but its not work !
i cant work with js. Because I have a problem with 1.8.2, but I think we can find a solution with CSS
try this
.wrapper-dropdown-2:hover ul{
display:block;
}
updated jsFiddle File
also remove .dropdown:hover from your style
You are missing to add hover code to see drop down when hover over. add css for hover.
.wrapper-dropdown-2:hover .dropdown
{
display:block;
}
Live Demo
Just Replace Your This CSS
.dropdown:hover {
/* Size & position */
position: absolute;
display:block;
top: 100%;
left: -5px;
right: 0px;
/* Styles */
background: white;
-webkit-transition: all 0.3s ease-out;
-moz-transition: all 0.3s ease-out;
-ms-transition: all 0.3s ease-out;
-o-transition: all 0.3s ease-out;
transition: all 0.3s ease-out;
list-style: none;
/* Hiding */
opacity: 0;
pointer-events: none;
}
To My CSS and Get Result
.wrapper-dropdown-2:hover > .dropdown {
position: absolute;
display:block;
left: -45px;
background: white;
top:24px;
}
You will need to initialize your javascript as well as link to jquery. I see you are using a dropdown from Codrops why dont you just download the source?

Transition on position:absolute header and background

I'm trying to apply a hover state to some portfolio navigation. It's a horizontally and vertically centered header on top of an image. The centering works as I need it to (there are reasons for it being as complicated as it is, or believe me, I would do it some other way).
But the hover state is giving me problems. I'm trying to do something like this: http://jsfiddle.net/kmjRu/33/. Which is a transition of the h2 and its background on hover of the image. I can get it almost working by fiddling with opacity or the z-index of the h2, but especially the change of the background color is not working (because there are no elements exactly covering the image, of which I can change the background). Does anyone know how to get the hover state working properly?
This is the code I have and on which I'm trying to get this hover effect to work:
(Also posted here: http://jsfiddle.net/kmjRu/34/)
HTML
<article>
<div class="img-crop">
<h2>Title</h2>
<img src="http://bit.ly/gUKbAE" />
</div>
</article>
CSS
* {
box-sizing: border-box;
-moz-box-sizing: border-box;
}
article {
overflow: hidden;
}
.img-crop {
display: inline-block;
position: relative;
overflow: hidden;
max-width: 100%;
}
h2 {
margin: 0;
padding: 0;
z-index: 1;
line-height: 0;
position: absolute;
top: 50%;
left: 0;
width: 100%;
text-align: center;
}
h2 {
margin: 0;
padding: 0;
z-index: 1;
line-height: 0;
position: absolute;
display: block;
top: 50%;
left: 0;
width: 100%;
text-align: center;
opacity: 0;
transition: all 0.3s ease-out;
-moz-transition: all 0.3s ease-out;
-webkit-transition: all 0.3s ease-out;
-o-transition: all 0.3s ease-out;
}
h2:hover {
opacity: 1;
}
This could be it!
Basically, you need to make sure following things.
your h2 should be exactly equal to the container behind, only then it will perform a total overlay.
set the default opacity of h2 to be 0. and change/transition it to some mid value say 0.6 upon hover.
now also, you need to make the background-color of the h2 black, or different than the parent container, only then it will appear.
and then give appropriate padding to the h2 element, to make the text appear in the middle.
set h2 like this:
h2 {
margin: 0;
z-index: 1;
padding-top:20%;
line-height: 0;
position: absolute;
top: 0%;
left: 0;
width: 100%;
text-align: center;
vertical-align:middle;
height:100%;
opacity:0;
}
and set your h2:hover like this:
h2:hover
{
padding-top:20%;
color:white;
background-color:Black;
opacity:0.6;
-webkit-transition: opacity 0.25s, background-color 0.25s;
-o-transition: opacity 0.25s, background-color 0.25s;
-moz-transition: opacity 0.25s, background-color 0.25s;
-ms-transition: opacity 0.25s, background-color 0.25s;
-kthtml-transition: opacity 0.25s, background-color 0.25s;
transition: opacity 0.25s, background-color 0.25s;
}
see this fiddle
So, I solved the question by doing it like this:
HTML
<article>
<div class="item">
<h2>Title</h2>
<img src="http://placehold.it/350x150" />
</div>
</article>
CSS
article {
overflow: hidden;
}
h2 {
font-weight: normal;
z-index: 2;
line-height: 0;
position: absolute;
top: 50%;
width: 100%;
text-align: center;
left: 0;
margin: 0;
padding: 0;
color: rgba(255,255,255,0);
-webkit-transition: color 0.2s linear;
-moz-transition: color 0.2s linear;
-o-transition: color 0.2s linear;
transition: color 0.2s linear;
}
.title {
display: inline-block;
position: absolute;
overflow: hidden;
z-index: 1;
width: 100%;
height: 100%;
background: rgba(0,0,0,0);
text-decoration: none;
-webkit-transition: background-color 0.2s linear;
-moz-transition: background-color 0.2s linear;
-o-transition: background-color 0.2s linear;
transition: background-color 0.2s linear;
}
.title:hover {
text-decoration: none;
}
.item {
display: inline-block;
position: relative;
max-width: 100%;
}
.item:hover .title {
background: rgba(0,0,0,0.6);
}
.item:hover h2 {
color: rgba(255,255,255,1);
}
img {
border: 0;
vertical-align: top;
max-width: 100%;
}
See this fiddle. That way it's dynamic (the image is fluid and there are no fixed heights or widths to it) and the headline is automatically centered vertically and horizontally.