Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Static image on top of rotating image - css3

Posted on 2013-11-01
7
Medium Priority
?
331 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 54

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 54

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 54

Accepted Solution

by:
Scott Fell,  EE MVE earned 2000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

When applying CSS to your HTML, there are many different ways to select which element(s) the CSS applies to.  Some of these selectors are more commonly known and used than others - Here are the more common ones: #X - Matches an ID of X .X - Matche…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…
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

886 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