2

I've got a bunch of lists

<ul>
  <li class="first">Item 1</li>
  <li>Item 2</li>
  <li class="last">Item 3</li>
</ul>

styled with

li:after {
  content: ' / ';
}
li.last:after {
  content: '';
}

This has to be a sort of commonplace problem. I'm thinking i could either clutter the html and put in intermediary <li>'s containing the character, or i could hook on a javascript to put them in there if IE is the loading browser, but that wouldn't catch people without javascript. Iuno. I'm leaning towards cluttering the html but I'd like to hear if there are some opinions on this.

John Slegers
  • 45,213
  • 22
  • 199
  • 169
xkcd150
  • 8,767
  • 3
  • 23
  • 17

8 Answers8

3

Internet Explorer (IE) doesn't support the :after selector, we must use some hack instead, for example this one:

li { scrollbar-face-color: expression(!this.isInserted==true ? this.isInserted=(this.innerHTML = '' + this.innerHTML + 'xkcd150') : ''); }

"xkcd150" - this one will be added after each <li>.

its an expression, which usually used to replace and fix some IE bugs.

So, the full code is:

li { scrollbar-face-color: expression(!this.isInserted==true ? this.isInserted=(this.innerHTML = '' + this.innerHTML + ' / ') : ''); }

li.last {
scrollbar-face-color: expression(!this.isInserted==true ? this.isInserted=(this.innerHTML = '' + this.innerHTML + '') : ''); }

The first lines adds " / ", and the second is used to add nothing.

All the code must be added into your css file.

Mike
  • 1,825
  • 3
  • 21
  • 26
2

Here's an idea you won't like. 8-) Put your / symbols in as background images, in the right padding of the <li>s.

RichieHindle
  • 272,464
  • 47
  • 358
  • 399
  • are you serious :D is that what you usually do? – xkcd150 May 01 '09 at 21:46
  • I've only used vertical bars in this context, not slashes, in which case you can use border-right (eg. the top navigation menu on http://entrian.com/source-search/) – RichieHindle May 01 '09 at 21:56
2
  1. Use the IE7.js hack to add after pseudoelement support.
  2. Use conditional comments to add to the markup to simulate that effect or to remove some of the existing style to make it easier to read without dividers -- eg, let the list items stack in a stylesheet in a conditional comment
  3. Allow IE6 to degrade gracefully by rearranging the style so this doesn't happen, even if it looks different in other browsers.
Anonymous
  • 49,213
  • 1
  • 25
  • 19
  • ah, i forgot all about conditional comments. they have to be the most un-cluttery way to clutter up the html – xkcd150 May 01 '09 at 22:23
1

I just do it in the server-side language when generating the list HTML. I suppose that would be considered "cluttering the HTML".

Chad Birch
  • 73,098
  • 23
  • 151
  • 149
  • 1
    do you do it for all clients and not bother with the css at all or do you pinpoint IE from its user-agent? – xkcd150 May 01 '09 at 21:45
  • I just always do it, :after isn't a particularly well-supported selector at the moment, unfortunately. – Chad Birch May 01 '09 at 21:46
  • :after is well-supported in browsers released after 2001. The user agent is not reliable, especially for deciding browser capability. – Anonymous May 02 '09 at 01:52
0

If your content is not intented to change at runtime, you could use the following :

.icon-glass {
  *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = '&#xf000;');
}

If your content is intended to change at runtime, you could do something like this :

.icon-glass {
  *top:expression(0, this.innerHTML = '&#xf000;');
}

Unfortunately, this is extremely slow. While it is likely to work in IE6 with a significant reduction of your performance, IE7 is likely to crash if you have too many icons on your page. So I wouldn't recommend this second technique unless you use only very few icons and you can afford the performance reduction.

John Slegers
  • 45,213
  • 22
  • 199
  • 169
0

I use javascript and conditional comments. i.e. using jQuery.

 <!--[if IE 6]>
   <script type='text/javascript'>
     $(document).ready( function() {
      $('li').not('li.last').after('/');
     });
   </script>
 <![endif]-->

It is offcourse better to use a seperate JS file.
This also has the disadvantage that you have to write everything twice since you put it in CSS for good browsers and again in javascript for IE6.

Pim Jager
  • 31,965
  • 17
  • 72
  • 98
0

Try using something like jQuery.

`$(function(){

$('li').not(':last-child').append('\'');

});`

It doesn't clutter up the html. Also, to make this only work with IE, try using jquery compatibility.

CodeJoust
  • 3,760
  • 21
  • 23
-1

And if IE would support last-child you would not need to do the class="last" :P.

IE support has been and will continue to be crap. IE 8 has made massive improvements, :after and :before work as you would expect, IE 7 supports them as well. Just target those two, especially since Microsoft is pushing IE 8 out over Windows Update.

X-Istence
  • 16,324
  • 6
  • 57
  • 74
  • Figured i'd get modded into oblivion for this :P IE 8 in comparison to IE 6 is absolutely amazing and developing for it and other standards compliant browsers is easy. A box model that is not all screwed up, standards compliant rendering, or almost at least. On a website I am developing I have implemented not a single hack in the CSS and the site renders exactly the same in IE 8, FireFox, Chrome, Opera and Safari. – X-Istence May 01 '09 at 22:03
  • I'm guessing the mod down is really for this being a comment and not an answer. – Anonymous May 01 '09 at 22:05
  • well, if the client is fine with not targeting ie6, i won't. tbh i haven't kept up with ie8 developments, but it's good to hear it's not all bad. – xkcd150 May 01 '09 at 22:20