Solved

Static image on top of rotating image - css3

Posted on 2013-11-01
7
324 Views
Last Modified: 2013-11-02
I'm having trouble getting a static (non-moving) small image on top of a larger rotating image.  I'm using position: relative for the larger image, and position:absolute for the small one.  Displays great in FF and IE10 when I don't rotate the bottom image.  When I rotate it the position for the smaller image seems to become relative to the next outside <div> layer.
z-index didn't help either.

So, I seem to be able to rotate the larger image with the small one displayed to the side, or not rotate the large one and get the small one displayed on top of the large one where I want it.

I'm sure this is possible but I haven't discovered how.  Any help will be appreciated.
0
Comment
Question by:JoeTodd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 39617797
A link to the page might help.
0
 

Author Comment

by:JoeTodd
ID: 39617889
Here's a runnable snippet that will hopefully illustrate the problem I'm having.
There's one html and two image files attached.
You can see the difference in behavior by commenting out or leaving active the second styling for '#spinThisImage'.

Thanks,

Joe Todd
test.html
doggy-icon.jpg
milkyway.jpg
0
 
LVL 53

Expert Comment

by:Scott Fell, EE MVE
ID: 39618344
I would wrap your images in a div and then change your css by getting rid of the first

	#spinThisImage {
			z-index: 4;
			position: relative;
			top: 20%;
			left: 20%;
		}

Open in new window

Then change this
	#spinThisImage {
			z-index: 4;
			position: relative;
			top: 20%;
			left: 20%;
			-webkit-animation:spin 8s linear infinite;
			-moz-animation:spin 8s linear infinite;
			animation:spin 8s linear infinite;
		}
			@-moz-keyframes spin { 100% { -moz-transform: rotate(360deg); } }
			@-webkit-keyframes spin { 100% { -webkit-transform: rotate(360deg); } }
			@keyframes spin { 100% { -webkit-transform: rotate(360deg); transform:rotate(360deg); }

Open in new window


to
	#spinThisImage {
			-webkit-animation:spin 8s linear infinite;
			-moz-animation:spin 8s linear infinite;
			animation:spin 8s linear infinite;
		}
			@-moz-keyframes spin { 100% { -moz-transform: rotate(360deg); } }
			@-webkit-keyframes spin { 100% { -webkit-transform: rotate(360deg); } }
			@keyframes spin { 100% { -webkit-transform: rotate(360deg); transform:rotate(360deg); }

Open in new window


http://jsbin.com/aRIsOjO/1/edit?html,output
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
  	<style>

		

		#spinThisImage {
			z-index: 4;
		
			-webkit-animation:spin 8s linear infinite;
			-moz-animation:spin 8s linear infinite;
			animation:spin 8s linear infinite;
		}
			@-moz-keyframes spin { 100% { -moz-transform: rotate(360deg); } }
			@-webkit-keyframes spin { 100% { -webkit-transform: rotate(360deg); } }
			@keyframes spin { 100% { -webkit-transform: rotate(360deg); transform:rotate(360deg); }
		
		#holdThisSteady {
			position: absolute;
			top: 256px;
			left: 300px;
			z-index: 10;
		}

     

	</style>
</head>
<body>
  <div id="canvas">
			
			<div id="imageDiv">
              <div><img src="milkyway.jpg" id="spinThisImage"></div>
              <div><img src="images/doggy_icon.jpg" id="holdThisSteady"></div>

			</div> <!-- end of imageDiv -->
		</div> <!-- end of canvas -->

</body>
</html>

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:JoeTodd
ID: 39618777
The doggy_image is still displaying under the milkyway image.  I get the same results in IE10, FF, and Chrome.
I've attached the file I used to ensure that I copied the suggestions accurately.
Thanks,
Joe Todd
test2.html
0
 
LVL 53

Expert Comment

by:Scott Fell, EE MVE
ID: 39618826
Ok, when you said on top, I thought you meant stacked on top. I didn't actually load the image. I see what you mean now.  You want a layered effect.  When you say on top, you mean the top layer not stacked on top.
0
 
LVL 53

Accepted Solution

by:
Scott Fell,  EE MVE earned 500 total points
ID: 39618843
The problem with your code is in your last keyframe.  I have it working http://jsbin.com/AkUsemO/1/edit?html,output

You have the code below missing the last bracket
@keyframes spin { 100% { -webkit-transform: rotate(360deg); transform:rotate(360deg); }

Open in new window

and should be
@keyframes spin { 100% { -webkit-transform: rotate(360deg); transform:rotate(360deg); }	}

Open in new window


Also, the image you want on top has to be position:absolute;  If you want both position absolute for both, then as you know the top image needs to have a higher z-index.
0
 

Author Closing Comment

by:JoeTodd
ID: 39618868
GOOD EYES!
Good problem solving also.  
Works on IE10, FF, and Chrome.
Thanks for your help,
Joe
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

As a result of several questions about how to use Bootstrap I thought it would be a good idea to write down the development aspect of creating a Bootstrapped website in as little time as possible. Part 1 of this article will only concentrate on g…
This article discusses four methods for overlaying images in a container on a web page
In this Micro Tutorial users will learn how to embed custom fonts into websites using @font-face in CSS Select a font: Ensure the EULA allows you to use @font-face: Download the font: Get the browser-compatible files you need: Edit your CSS       - Name …
In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question