Solved

Static image on top of rotating image - css3

Posted on 2013-11-01
7
320 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Objects on Same Line 2 30
remove background quote mark from widget 6 53
ASP.net Fit 3 divs on screen side by side 3 30
Help to align the buttons in a row 2 29
Creating a CSS block that only applies to printing By default, all of your CSS applies to every possible view of your page - whether on screen, printed, landscape, touch-screen, or whatever.  You can, however, add CSS that only applies under certai…
CSS is a visual language used to classify objects and define rules about how they should be displayed. CSS skills aren’t restricted to developers anymore, there is a big benefit to having a basic understanding of the language, regardless of your occ…
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
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…

831 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