Snorlax Snorlax - 8 months ago 24
jQuery Question

Make specific character (or class/ID) be the center point of a string

I would like to align some text in the center, but not just by doing

text-align: center

I would like to make a specific character/class/ID be the center, while the rest of the string gets appended and prepended nicely. Here is what I mean:

As you can see, the red
in the middle is aligned somewhat in the middle (I used
to make this small example). I want to say something like:

align all the text in the middle, but make the 'anchor point' of the string a specific character/class/ID

Is something like this doable?


This could be done with some jQuery:

var width = $('#text').width();
var left = $('#center').position().left;
$('#text').css('margin-left', (left-width)/2);