Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I've got a prototype created in Meteor where the CSS / jQuery works fine in creating a shadow effect and adding a border to various images as they are hovered; specifically, in the Meteor prototype (it's a Sharepoint app, but testing features like this out is much quicker with Meteor) I have this CSS:

.addshadow {
	z-index: 4;
	-moz-box-shadow: 0 0 7px #000;
	-webkit-box-shadow: 0 0 7px #000;
	box-shadow: 0 0 7px #000;
}
.addborder {
  border: 1px solid gold;
}


...and this jQuery:

Template.postTravelSection0.events({
  'mouseenter #imgPostTravelTop': function() {
    $('#imgPostTravelTop').addClass('addborder');
    $('#imgPostTravelTop').addClass('addshadow');
  },
  'mouseleave #imgPostTravelTop': function() {
    $('#imgPostTravelTop').removeClass('addborder');
    $('#imgPostTravelTop').removeClass('addshadow');
  },
  . . .
});


It works fine on my Meteor-generated page -- on mouseenter / hovering into an image, it grows a golden five O'Clock shadow, and on mouseleave they are removed.

However, virtually the same thing in the Sharepoint code:

CSS:

.finaff-form-help-shadow {
	z-index: 4;
	-moz-box-shadow: 0 0 7px #000;
	-webkit-box-shadow: 0 0 7px #000;
	box-shadow: 0 0 7px #000;
}
.finaff-form-help-addborder {
  border: 1px solid red;
}


(I used red just so that it will show up clearly)

jQuery:

$( "#imgPostTravelTopLeft, #imgPostTravelTopRight, #imgPostTravelCenter, #imgPostTravelBottom" ).hover(function() {
        $(this).addClass('finaff-form-help-addborder');
        $(this).addClass('finaff-form-help-shadow');
  	}, function() {
        $(this).removeClass('finaff-form-help-addborder');
        $(this).removeClass('finaff-form-help-shadow');
  	}); 


...has different effects, to wit:


  • IE8: Nothing - no shadow, no border
  • Firefox: shadow but not border
  • Chrome: shadow but not border


It's not surprising that IE8 plays the role of the spoiled brat, living down to its recalcitrant reputation; but why do Firefox and Chrome also refuse to show the border?
Posted
Comments
Richard Deeming 30-Sep-15 13:46pm    
Any reason you're using jQuery for something that could just as easily be done in pure CSS?
B. Clay Shannon 30-Sep-15 13:54pm    
Good answestion (combination answer and question); I assume you mean something like:

img:hover {
// with the CSS chicanery in here
}

?

I'll try it...
Richard Deeming 30-Sep-15 13:57pm    
You could do that, but it would apply to every image on the page.

I'd be inclined to use the CSS classes:
.finaff-form-help-shadow:hover { ... }
.finaff-form-help-addborder:hover { ... }


Then you can just add the CSS classes to the images you want the effect on, and remove the jQuery code.
B. Clay Shannon 30-Sep-15 14:29pm    
Okay, first step (Meteor) successfully accomplished. I got rid of the jQuery altogether, and am just using this CSS:

#imgPostTravelTop:hover, #imgPostTravelTopRight:hover, #imgPostTravelCenter:hover, #imgPostTravelBottom:hover {
z-index: 4;
-moz-box-shadow: 0 0 7px #000;
-webkit-box-shadow: 0 0 7px #000;
box-shadow: 0 0 7px #000;

border: 1px solid gold;
}

Now on to the Sharepointiness of things.
Richard Deeming 30-Sep-15 13:52pm    
For the Firefox and Chrome issue, is Sharepoint adding a style="border-width:0px" to your images? The style attribute will override any styles set by CSS classes.

1 solution

This CSS works real well (getting rid of the jQuery altogether):

#imgPostTravelTop:hover, #imgPostTravelTopRight:hover, #imgPostTravelCenter:hover, #imgPostTravelBottom:hover {
z-index: 4;
-moz-box-shadow: 0 0 7px #000;
-webkit-box-shadow: 0 0 7px #000;
box-shadow: 0 0 7px #000;

border: 1px solid gold;
}

...but the following on a separate image to test how IE8 would do:

#imgPostTravel:hover {
  zoom: 1;
  filter: progid:DXImageTransform.Microsoft.DropShadow(OffX=5, OffY=5, Color=#ff0000);
}


...does nothing; I see no box-shadow yet. I got this from http://www.useragentman.com/blog/2011/08/24/how-to-simulate-css3-box-shadow-in-ie7-8-without-javascript/[^]
 
Share this answer
 
v2
Comments
Richard Deeming 1-Oct-15 8:55am    
This is where it gets complicated. :)

IE8 replaced the old "filter" syntax with a new "-ms-filter" syntax:
-ms-filter property (Internet Explorer)[^]
The CSS Corner: Using Filters In IE8[^]
IE8 ignores "filter" CSS styles[^]

This syntax was then deprecated in IE9, and removed in IE10.

So to make it work across the board, you'll need:

/* IE6/7: */
filter: progid:DXImageTransform.Microsoft.DropShadow(OffX=5, OffY=5, Color=#ff0000);
/* IE8: */
-ms-filter: "progid:DXImageTransform.Microsoft.DropShadow(OffX=5, OffY=5, Color=#ff0000)";
/* Firefox 3.6 or earlier: */
-moz-box-shadow: 0 0 7px #000;
/* Chrome 9, Safari 5, Android 3, Blackberry 7 or earler: */
-webkit-box-shadow: 0 0 7px #000;
/* Standards-compliant: */
box-shadow: 0 0 7px #000;
B. Clay Shannon 1-Oct-15 9:09am    
Awesome, thanks; I'll try it out.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900