Solved

Static image on top of rotating image - css3

Posted on 2013-11-01
7
318 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
  • 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 52

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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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 52

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 52

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

759 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now