How do I make a component that resembles an open desktop application - html

I'm trying create a portfolio web page where you can open up modals that resemble windows xp desktop apps. So the outer div has a background image of the outside boundary/border with the close button etc and the inside is another div which is my resume which should be scrollable but stay fixed inside the outer div.
Here's my code so far:
import React, { Component } from 'react';
import Draggable from 'react-draggable';
import './modal.css'
import res from '/Users/anthonychoi98/Documents/GitHub/portfolio/src/images/resumetemp.jpg';
class Modal extends Component {
displayInfo () {
switch(this.props.modalInfo) {
case 'Modal A':
return <div className="modal-info">This is Modal A</div>
case 'Modal B':
return(
<div className="resume-container">
<div className="modal-resume" style={{backgroundImage: `url('${res}')`}}>
</div>
</div>
);
default:
return null
}
}
closeModal = (e) => {
e.stopPropagation()
this.props.closeModal()
}
render(){
const divStyle = {
display: this.props.displayModal ? 'block' : 'none'
};
return (
<>
<div>
<Draggable
axis="both"
handle=".modal"
defaultPosition={{x: 0, y: 0}}
position={null}
grid={[25, 25]}
scale={1}
onStart={this.handleStart}
onDrag={this.handleDrag}
onStop={this.handleStop}>
<div
className="modal"
style={divStyle}>
<div className="modal-content"
onClick={ e => e.stopPropagation() }>
<span
className="close"
onClick={ this.closeModal }>x
</span>
<div class="modal-flex">
{this.displayInfo()}
</div>
</div>
</div>
</Draggable>
</div>
</>
);
}
}
export default Modal;
and heres the css:
/* MODAL */
/* Background effect. It covers the entire site */
.modal {
z-index: 1; /* Overlay effect: positioned over other containers */
width: 55%; /* Full width */
height: 90%; /* Full height */
top: 0;
left: 0;
overflow: hidden; /* Enable scroll if needed -> use auto */
}
/* Modal content */
.modal-content {
overflow-y: auto;
overflow-x: hidden;
background-color: white;
width: 100%; /* Width in proportion to its parent container*/
max-width: 640px; /* Max width where it stops expanding */
height: 100%; /* Height in proportion to its parent container */
margin: auto; /* Auto margin according to the element width */
padding: 10px;
/* border: 1px solid black; */
z-index: 1;
position: fixed;
border-radius:10px;
background-size: cover;
background-image: url('https://www.zwodnik.com/media/images/adobe-reader_windows.png')
}
/* Close button */
.close {
color: black;
float: right; /* Positioned to the right of the parent container whichever size it is */
float: top;
font-size: 30px !important;
font-weight: bold;
}
.close:hover,
.close:focus {
color: #000;
text-decoration: none;
cursor: pointer;
}
div.modal-flex {
/* overflow: auto; */
background-size: contain;
background-color: white;
width: 100%; /* Width in proportion to its parent container*/
height: 100%; /* Height in proportion to its parent container */
margin-top: 20px!important;
margin: auto;
border: 1px solid black;
z-index: 1;
overflow: contain;
display: flex;
flex-direction: column;
flex-wrap: nowrap;
justify-content: flex-start;
align-content: center;
align-items: flex-start;
}
div.resume-container{
overflow: auto;
position: absolute;
}
div.modal-resume{
/* background-size: contain; */
margin-bottom:45px;
position: relative;
min-width: 100%;
min-height: 100%;
padding-bottom: 50px;
order: 0;
/* flex: 1 1 auto; */
align-self: stretch;
background-repeat: no-repeat;
/* background-image: url('/Users/anthonychoi98/Documents/GitHub/portfolio/src/images/resumetemp.jpg'); */
}
span.close{
padding-right:20px;
padding-bottom:35px;
margin-top:-8px;
}
Is there a better way to make this? I know it will probably look wrong on different sized screens or if the page is minimized/maximized. I could just photoshop the resume into the background but i would not be able to scroll

Related

div containing resized image, width are not resized to width of image

I have a div with a fixed position containing an image that I have set to max-width:20% so it is scaled down. The height of the div is scaled to match the image but the width isn't, it looks like it's the same width of the initial size of the image.
I might be missing something fundamental but can't really understand this.
#logo {
max-width: 20%;
}
#logoholder {
position: fixed;
left: 10px;
top: 120px;
background: rgb(47 47 47 / 36%);
text-align: center;
}
#logo2 {
max-width: 77px;
}
#logoholder2 {
position: fixed;
width: 77px;
height: 77px;
left: 10px;
top: 30px;
background: rgb(47 47 47 / 36%);
text-align: center;
}
<div id="logoholder">
<img id="logo" src="https://www.google.com/gmail/about/static-2.0/images/logo-gmail.png">
</div>
<-- Expected result -->
<div id="logoholder2">
<img id="logo2" src="https://www.google.com/gmail/about/static-2.0/images/logo-gmail.png">
</div>
#logo{
max-width:100px;
}
#logoholder {
position: fixed;
left:0;
top:0;
background: rgb(47 47 47 / 36%);
}
<div id="logoholder">
<img id="logo" src="https://www.google.com/gmail/about/static-2.0/images/logo-gmail.png">
</div>
The max-width using a percentage is causing weird behaviour, changed it to px.
I set some margins and borders for clarity - and left the original images in place (the first one is the one in play here)
I would suggest using a flex display for simplicity then we can set the container to a size and the height of the image to what we want relative to that (see comments in the CSS)
I set the button at the "top" but it could be relative position also and work around that "fixed" position issue.
body {
margin: 0;
}
#logoholder {
position: relative;
left: 10px;
top: 1rem;
/* background: rgb(47 47 47 / 36%);*/
/* light violet background */
background-color: #8080FF20;
}
#logo {
max-width: 20%;
}
#logoholder2 {
position: relative;
left: 10px;
top: 30px;
*/ width: 77px;
height: 77px;
/* light cyan background */
background-color: #20E0E020;
}
#logo2 {
max-width: 77px;
}
/* set up the blocks to keep the "gray" one at the top */
.container-all {
display: flex;
align-items: cemter;
justify-content: cemter;
/*stack then for this demo */
flex-direction: column;
/* the "lime" border around all the content */
border: solid 1px #88ff88;
}
.container-all .content-container {
margin: 0.5rem;
/* get our logo (first container) at the top if we want to */
/* margin-top:0;*/
}
.logo-container {
/* keep logo/button at top when scrolling for this demo */
align-self: flex-start;
position: sticky;
top: 0;
/* set up this containers display */
display: flex;
justify-content: center;
align-items: center;
}
.logo-container .content-item {
/* controls the height of the image on the button */
/* these should be the same since the "default" is 16px font-size == 1rem */
font-size: 1rem;
/* font-size:16px;*/
}
.logo-image {
/* controlled by container font size as these have em */
/* so if 1rem = 16px this 4em would be 16 X 5=80px */
height: 5em;
}
.content-container {
text-align: center;
border: 1px solid blue;
object-fit: contain;
}
.content-container:first-of-type {
/* light gray background for this demo */
/* alpha transparency information into the hex format for colors 2E as this has 8 characters */
background-color: #8080802E;
border: outset #D0D0D02E 4px;
}
.content-item {
border: dashed #00000044 1px;
padding: 0.25rem;
margin: 0.25rem;
}
.content-container .content-item .big-me:last-of-type {
height: 20rem;
}
<div class="container-all">
<div class="logo-container content-container">
<button type="button" class="content-item">
<img class="logo-image" src="https://www.google.com/gmail/about/static-2.0/images/logo-gmail.png">
</button>
</div>
<div class="content-container">
<div class="content-item">
Below here just to force scrolling on the sticky icon
</div>
</div>
<div id="logoholder" class="xcontent-container">
<div class="content-item">
<img id="logo" src="https://www.google.com/gmail/about/static-2.0/images/logo-gmail.png">
</div>
</div>
<div class="content-container">
<div class="content-item">
<-- Expected result -->
</div>
</div>
<div id="logoholder2" class="content-container">
<div class="content-item">
<img id="logo2" src="https://www.google.com/gmail/about/static-2.0/images/logo-gmail.png">
</div>
</div>
<div class="content-container">
<div class="content-item">
<div class="big-me">I am big so I can force the scroll.
</div>
</div>
</div>
</div>

Split screen into grid and align items relatively vertically and horizontally

I need to create a fairly static page divided into regions with an image carousel on the right (hcentered and vcentered)
This needs to be very browser compatible, so flexbox is not really an option
Here is a mockup image of what I'm after:
Mockup
The Code I have thus far is as follows, but I can for the life of me not get the right hand image to be centered and middle aligned:
$(function() {
// var exits = ['fadeOut', 'fadeOutDown', 'fadeOutUpBig', 'bounceOut', 'bounceOutDown', 'hinge',
// 'bounceOutUp', 'bounceOutLeft', 'rotateOut', 'rotateOutUpLeft', 'lightSpeedOut', 'rollOut'];
// var entrances = ['fadeIn', 'fadeInDown', 'fadeInRight', 'bounceIn', 'bounceInRight', 'rotateIn',
// 'rotateInDownLeft', 'lightSpeedIn', 'rollIn', 'bounceInDown' ];
var exits = ['fadeOut'];
var entrances = ['fadeInRight'];
var photos = $('#photos'),
ignoreClicks = false;
$('.arrow').click(function(e, simulated) {
if (ignoreClicks) {
// If clicks on the arrows should be ignored,
// stop the event from triggering the rest
// of the handlers
e.stopImmediatePropagation();
return false;
}
// Otherwise allo this click to proceed,
// but raise the ignoreClicks flag
ignoreClicks = true;
if (!simulated) {
// Once the user clicks on the arrows,
// stop the automatic slideshow
clearInterval(slideshow);
}
});
// Listen for clicks on the next arrow
$('.arrow.next').click(function(e) {
e.preventDefault();
// The topmost element
var elem = $('#photos #innerdiv:last');
// Apply a random exit animation
elem.addClass('animated')
.addClass(exits[Math.floor(exits.length * Math.random())]);
setTimeout(function() {
// Reset the classes
elem.attr('class', '').prependTo(photos);
// The animation is complate!
// Allow clicks again:
ignoreClicks = false;
}, 10);
});
// Start an automatic slideshow
var slideshow = setInterval(function() {
// Simulate a click every 1.5 seconds
$('.arrow.next').trigger('click', [true]);
}, 1000);
});
/* https://tutorialzine.com/2013/02/animated-css3-photo-stack */
body {
/* overflow:hidden;*/
}
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
#photos {
/* margin:0 auto; */
/*position:relative; */
}
#photos .outerdiv {
position: relative;
}
#photos .middlediv {
/* position:absolute; */
/* display:inline-block; */
/* width:450px; */
/* height:450px; */
/* overflow:hidden; */
background-color: #fff;
z-index: 10;
border: 1px solid #aaa;
/* -webkit-animation-duration: 1s; */
-moz-animation-duration: 1s;
/* animation-duration: 1s; */
}
#photos .innerdiv {
/* position:absolute; */
/* top:0px; */
/* left:0px; */
/* right:0px; */
/* bottom:0px; */
width: 450px;
height: 450px;
background-size: cover;
background-position: center;
/*overflow:hidden;*/
/* width:400px; */
/* height:400px; */
position: absolute;
}
.lefttop {
grid-area: lefttop;
width: 50vw;
height: 33.3vh
}
.leftcenter {
grid-area: leftcenter;
width: 50vw;
height: 33.3vh
}
.leftbottom {
grid-area: leftbottom;
width: 50vw;
height: 33.3vh
}
.rightfull {
grid-area: rightfull;
width: 50vw;
}
.grid-container {
display: grid;
grid-template-areas: 'lefttop rightfull' 'leftcenter rightfull' 'leftbottom rightfull';
grid-gap: 1px;
background-color: #2196F3;
padding: 1px;
}
.grid-container>div {
background-color: rgba(255, 255, 255, 0.8);
text-align: center;
padding: 0px;
font-size: 30px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="grid-container">
<div class="lefttop">left top</div>
<div class="leftcenter">left center</div>
<div class="leftbottom">left bottom </div>
<div class="rightfull">
<div id="photos" class="outerdiv">
<div class="middlediv">
<div class="innerdiv" style="background-image:url(http://127.0.0.1:81/wordpress/wp-content/uploads/2018/08/20180823_132842-01-400x347.jpeg)"></div>
</div>
<div class="middlediv">
<div class="innerdiv" style="background-image:url(http://127.0.0.1:81/wordpress/wp-content/uploads/2018/07/20180806_162813-01-1-400x389.jpeg)"></div>
</div>
<div class="middlediv">
<div class="innerdiv" style="background-image:url(http://127.0.0.1:81/wordpress/wp-content/uploads/2018/08/20180820_153720-01-400x356.jpeg)"></div>
</div>
</div>
</div>
</div>
Ideally, I would want to use grid or table but it seems like table does not allow for vertical merging of cells.
IE10 and above needs to be supported.
The image in the carousel should be a percentage of the width or height of the right hand column to make it relatively responsive to different screen sizes.
I have used the photo carousel at https://tutorialzine.com/2013/02/animated-css3-photo-stack and modified the code and javascript slightly as I thought using divs would be easier than UL's and LI's, but the results are just about the same.
Any guidance on how to achieve this without too many dirty fixes would be very much appreciated!
In other words:
a simple page, divided into two equal columns.
The left column should have a logo and some links spaced vertically away from the middle horizontal line of the screen.
The right column should be half the screen width, and full screen height with the image carousel centered and middle of the column with responsive width and height.
here is a fiddle with your requirement, I was based on the mock image in your question, I hope this help you.
Here is the HTML:
<div class="grid-container">
<div class="lefttop">
<h1>
LOGO
</h1>
</div>
<div class="leftbottom">
<ul>
<li>
home
</li>
<li>
about
</li>
<li>
contact
</li>
</ul>
</div>
<div class="rightfull">
<div id="photos" class="outerdiv">
<div class="middlediv">
<img class="innerdiv" src="https://picsum.photos/200/300/?random">
</div>
<div class="middlediv">
<img class="innerdiv" src="https://picsum.photos/200/300/?random">
</div>
<div class="middlediv">
<img class="innerdiv" src="https://picsum.photos/200/300/?random">
</div>
</div>
</div>
</div>
And tht SCSS
/* https://tutorialzine.com/2013/02/animated-css3-photo-stack */
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
html, body {
height: 100%;
}
.grid-container {
overflow: hidden;
display: grid;
height: 100% !important;
grid-template-columns: repeat(2, 50%);
grid-template-rows: repeat(2, 50%);
background-color: #2196F3;
& > div {
background-color: rgba(255, 255, 255, 0.8);
text-align: center;
padding: 0px;
// font-size: 30px;
}
.lefttop, .leftbottom {
grid-column: 1;
}
.lefttop {
&::before, & > h1 {
display: inline-block;
vertical-align: bottom;
}
&::before {
content: '';
height: 100%;
}
grid-row: 1;
position: relative;
h1 {
font-size: 3rem;
font-weight: 100;
}
}
.leftbottom {
grid-row: 2;
ul {
margin: 1rem auto;
li {
list-style: none;
display: inline;
&:not(:first-child):not(:last-child)::before {
content: '-';
}
&:not(:first-child):not(:last-child)::after {
content: '-';
}
a {
text-decoration: none;
color: inherit;
}
}
}
}
.rightfull {
grid-column: 2 / 3;
grid-row: 1 / 3;
position: relative;
img {
top: 0;
left: 0;
padding: 1rem;
position: absolute;
width: 100%;
height: 100%;
object-fit: cover;
}
}
}
https://jsfiddle.net/cisco336/wpfzL03k/1/
Here is MS Edge screenshot
MS IE11 screenshot

How to expand DIV to fit set area in set position, without re-positioning it?

The best way I can explain my question is by the picture I posted below. Basically when you increase the number of the width of an object it expands to the right(see figure 1), I know you can make it expand to the left by adding some changes to the css positioning, but I need my div to expand a little to the left and a little to the right to be able to take up a certain amount of space at a certain position.(See figure 2 below)What does happen (AKA the closest I can get):Figure 1:
What I want to happen (fill the whole area):
Figure 2:
so basically I want to know how I can achieve what is happening in figure 2
Try:
.div {
width: someWidth;
margin: 0 auto;
}
This can be achieved quite easy using flexbox.
Use align-items: flex-end; display: flex; and justify-content: center;in your parent element. Then define the child dimensions.
align-items: flex-end; : To vertically position the element at the end in the cross axis.
justify-content: center; : To horizontally center the element in the main axis.
JSFIDDLE
body {
margin: 0;
}
* {
box-sizing: border-box;
}
.flex-container {
align-items: flex-end;
display: flex;
justify-content: center;
height: 100vh;
border: .5em dashed black;
background-color: lightgreen;
}
.flex-item {
flex-basis: 3em;
height: 3em;
background-color: dodgerblue;
}
<div class="flex-container">
<div class="flex-item"></div>
</div>
EDIT:
Here's another demo for you to see how this behaves if you change the child element dimensions. (Click the blue square to toggle dimension change).
JSFIDDLE
$(".flex-item").on("click", function() {
$(this).toggleClass("flex-item--big");
});
body {
margin: 0;
}
* {
box-sizing: border-box;
}
.flex-container {
align-items: flex-end;
display: flex;
justify-content: center;
height: 100vh;
border: .5em dashed black;
background-color: lightgreen;
}
.flex-item {
flex-basis: 3em;
height: 3em;
background-color: dodgerblue;
transition: flex-basis 300ms linear, height 300ms linear;
cursor: pointer;
}
.flex-item--big {
flex-basis: 10em;
height: 10em;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="flex-container">
<div class="flex-item"></div>
</div>
EDIT 2:
After some specifications mentioned in the comments, here's what can be done.
To tweak "margin" between flex-items you would need to make this a
little bit more complex, wrapping each item in a container and adding
padding, which is not in the scope of the following demo.
Notes & Recommendations:
Try to avoid width and height changes in your elements, you should stick to transform and opacity in transitions and animations.
Try to make your transitions faster, something between 300ms and 500ms
DEMO
CODE SNIPPET:
function panels() {
/* jQuery Objects */
var $panelsContainer = $(".panels-container"),
$panel = $(".panel"),
/* Strings of Classes used */
cHasPanelOpened = "has-panel-opened",
cHoverEffect = "panel-hover-effect",
cOpened = "opened",
cLastClicked = "last-clicked",
cFaded = "faded";
/* Panel click event listener */
$panel.on("click", function() {
$panelsContainer
.toggleClass(cHasPanelOpened);
$(this)
.toggleClass([cHoverEffect, cOpened].join(" "))
.addClass(cLastClicked);
$panel.not(this)
.toggleClass(cFaded)
.removeClass(cLastClicked);
});
}
$(document).ready(panels);
body {
/* DEMO illustration purposes only */
margin: 0;
background-color: white;
border: .5em dotted darkorange;
height: 100vh;
/* DEMO illustration purposes only */
}
* {
box-sizing: border-box;
}
/*
Panels Container
*/
.panels-container {
display: flex;
//width: 460px;
//height: 290px;
/* DEMO illustration purposes only */
height: 100%;
transform: scale(.9);
/* DEMO illustration purposes only */
}
/*
Panel Sections
*/
.panel__section {
display: flex;
flex-flow: row wrap;
}
.panel__section--media {
flex-basis: 66%;
}
.panel__section--download {
flex-basis: 34%;
}
/*
Panel
*/
.panel {
position: relative;
transition: transform 300ms, opacity 500ms;
cursor: pointer;
}
.panel--blue {
flex-basis: 100%;
height: 50%;
background-color: #2196F3;
background-image: url('https://cdn2.scratch.mit.edu/get_image/user/15016755_60x60.png?v=1465352804.66');
background-size: 50% 100%;
transform-origin: top left;
}
.panel--red,
.panel--yellow {
flex-basis: 50%;
height: 50%;
align-self: flex-end;
}
.panel--red {
background: url('http://iconshow.me/media/images/Application/Modern-Flat-style-Icons/png/512/Video.png') #F44336 no-repeat center;
background-size: 120px;
transform-origin: bottom left;
}
.panel--yellow {
background: url('https://scontent.cdninstagram.com/t51.2885-15/s320x320/e15/10731543_602219616549530_1911663388_n.jpg?ig_cache_key=ODQxODcxMTQxNDcxOTE1NzQw.2') #FFEB3B no-repeat center;
background-size: 100%;
transform-origin: center bottom;
}
.panel--green {
flex-basis: 100%;
height: 100%;
background: url('https://cdn1.iconfinder.com/data/icons/hawcons/32/698860-icon-129-cloud-download-128.png') #4CAF50 no-repeat center;
transform-origin: center right;
}
/*
Handle each panel when opened
*/
.panel--blue.opened {
transform: scale(calc(1/.66), 2);
}
.panel--green.opened {
transform: scaleX(calc(1/.34));
background-size: 50% 50%;
}
.panel--red.opened {
transform: scale(calc(1/.33), 2);
}
.panel--yellow.opened {
transform: scale(calc(1/.33), 2);
}
/*
Styling Helpers
*/
.faded {
opacity: 0;
}
.opened {
outline: 0;
}
.last-clicked {
z-index: 1;
}
.panel-hover-effect:hover {
transform: skewY(3deg);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- Panel Section Begin -->
<section class="panels-container">
<section class="panel__section panel__section--media">
<div class="panel panel--blue panel-hover-effect"></div>
<div class="panel panel--red panel-hover-effect"></div>
<div class="panel panel--yellow panel-hover-effect"></div>
</section>
<section class="panel__section panel__section--download">
<div class="panel panel--green panel-hover-effect"></div>
</section>
</section>
<!-- Panel Section End -->
You can read more about flexbox here.

Changing image on hover without using an extra div

I'm trying to make my footer img change to a different img on hover, I've accomplished this by creating each img as a div, however, I'm trying to avoid this, is there any other possible way to do this?
Current CSS:
.footerLeft {
float:left;
width: 50%;
height: 100px;
color: #fff;
background-color: #33383b;
}
.footerLeft p {
margin-left: 25px;
}
.footerLeft img {
width: 175px;
height: 50px;
padding-left: 25px;
margin-top: 10px;
}
.footerRight {
float:right;
width: 50%;
height: 100px;
color: #fff;
background-color: #33383b;
}
.footerRight img {
width: 35px;
height: 35px;
}
.footerRight p {
text-align: right;
position:relative;
margin-top: -20px;
margin-right: 20px;
}
Current HTML:
<div class="footerLeft">
<img src="img/logo.png">
<p>Sharpturn Network© 2016</p>
</div>
<div class="footerRight">
<ul id="menu">
<li><img src="img/footer/facebook.png"></li>
<li><img src="img/footer/twitter.png"></li>
<li><img src="img/footer/youtube.png"></li>
</ul>
<p>Designed by Ryan Williams</p>
</div>
Set one img as the background img, and the other as the background img on hover.
footer {
background-image: url(...);
}
footer:hover {
background-image: url(...);
}
The only alternative I can think of to using a div (or some other element with background image) is to use JavaScript. This will allow you to change the 'src' of the image on hover.
element.setAttribute('src', 'http://www.example.com/image.jpg');
As #partians said, just added "background-size" as cover, I assumed that you need that.
footer {
width: 900px;
height: 600px;
background-image: url("http://www.joomlaworks.net/images/demos/galleries/abstract/7.jpg");
background-size: cover
}
footer:hover {
background-image: url("http://image2.redbull.com/rbcom/010/2013-07-25/1331603705670_2/0010/1/900/600/2/red-bull-illume.jpg");
}
<footer> </footer>
try this.just copy and pastea and try it.only have to replace your two images.
<!DOCTYPE html>
<html>
<head>
<title>hover</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<style type="text/css">
body{
margin:0;
padding:0;
}
.imageOne{
width: 500px;
height: 500px;
box-shadow: 1px 2px 1px black;
background-image: url(http://www.ron-gatepain.com/images/Golden_Gate_Bridge.JPG?306);
background-repeat: no-repeat;
}
.imageTwo{
width: 500px;
height: 500px;
box-shadow: 1px 2px 1px black;
background-image: url(http://gym1526-english.narod.ru/images/Statue.jpg);
background-repeat: no-repeat;
}
</style>
</head>
<body>
<div id="myimage" class="imageOne">
</div>
<script type="text/javascript">
$(document).ready(function(){
$("#myimage").mouseenter(function(){
$(this).addClass("imageTwo").removeClass("imageOne");
});
$("#myimage").mouseleave(function(){
$(this).addClass("imageOne").removeClass("imageTwo");
});
});
</script>
</body>
</html>
EDIT: Note that some of the other answers will change the image when hovering any part of the whole footer container. This method changes the image only when hovering the image's region.
You could declare a pseudo-element on the footer container in the same position as the image to replace it on hover. Basically, using a combination of opacity and z-index you can hide the original image and show the pseudo element in the same place.
Here is an example of how to accomplish that:
.footerLeft:before {
/* this creates the pseudo-element */
width: 175px; /* Same as img */
height: 50px; /* Same as img */
margin-left: 25px; /* Same as img */
margin-top: 10px; /* Same as img */
background: url(http://lorempixel.com/175/50/cats); /* your replacement img */
position: absolute;
z-index: 0;
content: '';
}
.footerLeft img {
width: 175px;
height: 50px;
margin-left: 25px; /* I used margin-left instead of padding-left */
margin-top: 10px;
position: relative; /* necessary for the z-index to work */
z-index: 1; /* puts the img above the pseudo-element by default */
}
.footerLeft img:hover {
opacity: 0; /* hides the original image on hover */
}
EDIT 2: If you want the social media icons to change images on hover, the process is similar. Create pseudo elements on each a tag with CSS, with the same dimensions as the original img. Configure a different replacement image for each icon:
.footerRight img {
width: 35px;
height: 35px;
position: relative; /* enables the use of z-index */
z-index: 1; /* puts the image on top by default */
transition: opacity .2s; /* remove this for no smooth transtion */
}
.footerRight a:before {
width: 35px; /* same a img */
height: 35px; /* same a img */
z-index: 0;
content: '';
position: absolute;
}
.footerRight li:nth-child(1) a:before {
/* facebook icon */
background: url(http://lorempixel.com/35/35/cats);
}
.footerRight li:nth-child(2) a:before {
/* twitter icon */
background: url(http://lorempixel.com/35/36/cats);
}
.footerRight li:nth-child(3) a:before {
/* youtube icon */
background: url(http://lorempixel.com/36/35/cats);
}
.footerRight img:hover {
opacity: 0; /* hides the original image */
}
Note: This method has the advantage of loading the replacement images immediately. The same might not be true for other methods.
You can see the working example here: http://codepen.io/wilman/pen/mVZVzg

Static background image with transparent content

This is a question for the CSS gurus. A trend at the moment seems to be to place an image in the background and then have a transparent content scroll over the top.
AIM
What technique is used to produce this result, where the top content is transparent and slides over a background image.
http://jsfiddle.net/spadez/2uUEL/9/embedded/result/
MY ATTEMPT
What I have tried to do is apply a background and then make the top section transparent on top of it.
http://jsfiddle.net/spadez/N9sCD/3/
body {
background-image"http://www.hdwallpapers.in/walls/abstract_color_background_picture_8016-wide.jpg";
}
#top {
height: 160px;
opacity:0.4;
filter:alpha(opacity=40);
}
#section {
height: 600px; background-color: blue;
}
QUESTION
How has this technique of a transparent div moving over a static background image been achieved in my first link and how can I reproduce it. It must be a CSS solution because it still works without javascript enabled.
Here's a FIDDLE
<div id="top">
<span class="mask">
<img src="https://app.h2ometrics.com/build/v0.1.1a/styles/img/chrome_logo.png" class="logo" alt="Chrome">
Link 3
Link 2
Link 1
</span>
</div>
<div class="section l">
</div>
<div class="section d">
</div>
#top {
background:url(http://www.hdwallpapers3d.com/wp-content/uploads/2013/06/6.jpg) fixed;
background-size: cover;
position: relative;
height: 400px;
}
#top a {
background: rgba(200,200,200,0.5);
display: block;
float: right;
margin: 10px 15px;
padding: 2px 5px;
text-decoration: none;
color: #111;
cursor: pointer;
border: 2px solid #ddd;
border-radius: 8px;
transition: color 0.2s ease-in;
}
#top a:hover {
color: #fff;
}
.mask {
background: rgba(0,187,255,0.5); /* or hex combined with opacity */
position: absolute;
display: block;
top: 0;
left: 0;
width: 100%;
height: 100%;
box-shadow: inset 0 -5px 8px -3px #666; /* makes #top little inset */
}
.logo {
position: relative;
width: 60px;
height: 60px;
margin: 10px;
}
.section {
height: 600px;
}
.l {
background: #ddd;
}
.d {
background: #333;
}
Update #top content placed inside .mask which removes need for z-index.
You were essentially correct in building but your CSS has some errors.
body {
background: url('http://www.hdwallpapers.in/walls/abstract_color_background_picture_8016-wide.jpg') fixed; /* fixed stops background from scrolling */
background-size: cover cover; /* expands bg image to cover body */
}
#top {
height: 160px;
color: #fff; /* this just makes the text visible on your dark bg */
}
You don't need to set the opacity of #top because without a background set it will already be transparent.
Try this:
HTML - pushed the menu into its own div
<div id="top">
<div id="menu">
logo
link 1
link 2
</div>
</div>
<div id="section">
</div>
CSS - removed margin from body, set the background to a fixed position and to always cover the whole body, added background color to menu. Note that #top does not need a transparency as it is 100% transparent by default. If you want to get a 'colour washed' looking image it would be better to adjust the image itself rather than trying to re-create a colour overlay.
body {
margin: 0;
background: url("http://www.hdwallpapers.in/walls/abstract_color_background_picture_8016-wide.jpg") fixed;
background-size: cover;
}
#top {
height: 500px;
}
#menu {
padding: 10px;
background-color: #fff;
}
#section {
height: 600px; background-color: blue;
}