Solved

Static image on top of rotating image - css3

Posted on 2013-11-01
7
326 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

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!

Question has a verified solution.

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

This is a how to build your own CSS3 slideshow and when I say CSS3 I mean just CSS with no javascript in sight! There a few examples online of how to do this but most just show you an example without any explanation, others make it more complicat…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …
Suggested Courses

628 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