Targeting IE with jQuery, but it doesn't seem to be working

Posted on 2011-10-24
Last Modified: 2012-06-27
I'm using a script I found called CSS Browser selector. It's worked great in the past, for Chrome, but now I can't seem to get it to work with IE7. The script is supposed to add a browser class to the body tag, but it's not doing it.
I want to to align the text vertically centered and horizontally centered in the thumbnails. I found a hack for IE7 because it doesn't support CSS tables. So I wanted to target IE7 with the script.

Here's the site:

And the browser selector code:

function css_browser_selector(u){var ua=u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1},g='gecko',w='webkit',s='safari',o='opera',m='mobile',h=document.documentElement,b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3.5')?g+' ff3 ff3_5':is('firefox/3.6')?g+' ff3 ff3_6':is('firefox/3')?g+' ff3':is('gecko/')?g:is('opera')?o+(/version\/(\d+)/.test(ua)?' '+o+RegExp.$1:(/opera(\s|\/)(\d+)/.test(ua)?' '+o+RegExp.$2:'')):is('konqueror')?'konqueror':is('blackberry')?m+' blackberry':is('android')?m+' android':is('chrome')?w+' chrome':is('iron')?w+' iron':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?m+' j2me':is('iphone')?m+' iphone':is('ipod')?m+' ipod':is('ipad')?m+' ipad':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win'+(is('windows nt 6.0')?' vista':''):is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);

Open in new window

Sorry, the code was all on one line when I downloaded it.

/********** Works/Authors List **********/

#featured h2, 
#all-items h2 {
	height: 39px;
	margin-bottom: 0;
	padding: 17px 0 0 80px;
	color: #fff;
	font-size: 1.7em;
.list-o-items {
	margin-bottom: 22px;
	padding: 20px 0 0 13px;	
	overflow: hidden;
	font: .9em Helvetica, Arial, sans-serif;
	font-weight: 500;
	.list-o-items li {
		float: left;
		width: 135px;
		height: 230px;
		margin: 0 12px 12px 0;
		border-radius: 10px;
		-webkit-border-radius: 10px;
		-o-border-radius: 10px;
	.ie7 .list-o-items li { /* targeting IE7 using css_browser_selector.js centering text-vertically */
		position: relative;
	.list-o-items li:first-child {
		margin-left: 0;
		.list-o-items  li img {
			border-radius: 10px;
			-webkit-border-radius: 10px;
			-o-border-radius: 10px;
		.list-o-items li h3 {
			display: table;
			width: 125px;
			height: 49px;
			padding: 5px;
			overflow: hidden;
		.ie7 .list-o-items li h3 { /* targeting IE7 using css_browser_selector.js centering text-vertically */
			position: absolute;
			top: 50%;
			.list-o-items li h3 a {
			display: table-cell;
			width: 100%;
  		vertical-align: middle;
			color: #fff;
			text-align: center;
			text-decoration: none;
			font-weight: normal;
			.ie7 .list-o-items li h3 a { /* targeting IE7 using css_browser_selector.js centering text-vertically */
				position: relative;
				top: 50%

Open in new window


Question by:Alicia St Rose
    LVL 42

    Accepted Solution

    The JavaScript seems to be working fine (you don't have the IE Developer Toolbar for IE7?). The problem seems to be with the CSS.

    Firstly, IE7 has problems with "left:auto", so to fix that give "left:0" to ".ie7 .list-o-items li h3".

    Secondly, you don't really want to vertically align the <h3> anyway; you want to vertically align its contents.

    I would recommend a different vertical centering technique. I would use "display:inline-block" for IE7 as shown in these pages:
    LVL 7

    Author Closing Comment

    by:Alicia St Rose
    Sorry, it took so long to reply. I got pushed to the wall with deadlines!

    Thanks so much!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    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

    Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
    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 define a gradient in CSS. Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Gradient. Define the background as "linear-gradient(to right, #ee3668, black)". Ensure you …
    In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…

    758 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

    11 Experts available now in Live!

    Get 1:1 Help Now