Jump to content

How do I control the last character of a string?


Recommended Posts

I have a string in a TD tag that says "100 g".

The 'g' is grams, but it's not in it's own Span, so I need a way to find the 'last character', and then hide it in CSS.

I can see how to do ::first-letter, but there doesn't seem to be a way to do Last-Letter.

Is there?

It's not possible to target the last letter with CSS afaik. 

CSS generally depends on having the proper structure/markup to target things and if that's missing there's not much you can do.   ::first-letter exists because stylizing the first letter is a common thing that places do so it made it into the spec as a convenience feature so authors didn't have to do <span class="first-letter">*</span> everywhere.  Stylizing the last letter is not that common in my experience so it's not in there. 

So if you want to stylize your suffix you'll need to tag it with a span, or just remove it if all you want to do is hide it.

If you're desperate to do it and kicken's far better suggestions can't or don't work for you, you can use JavaScript to find the last letter and remove it or wrap it in a span that  you can then style separately. Assuming you have a way to target the specific paragraph with the last character to remove, of course.

Yes i should have added this here.

their shop has % instead of weight, and in the cart it still shows 100kg rather than 100%.

For some reason, Wordpress's logo translate won't change that.  It will change what shows in the Dropdown in Woocommerce, but not the front-end "you have 100kg in your cart" text.  So thought i could simply hide the 'kg'. Or the 'g' if it is just grams.

 

...

For one, percent and weight are not interchangeable units. I can't imagine why a thing is being labelled with a "kg" unit when it's supposed to be a percentage. It doesn't make any sense. It isn't the sort of problem that should exist.
For two, I can't imagine why someone has a thing in a (shopping?) cart that is measured in percentages.

Sweeping this problem under the rug is not the answer. You need to deal with the fact that WP or whatever is attaching incorrect units to the items. Because there's a really, really good chance that the wrong units are a symptom of a larger problem.

  • Like 1
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.