simona6 Posted August 26, 2020 Share Posted August 26, 2020 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? Quote Link to comment https://forums.phpfreaks.com/topic/311390-how-do-i-control-the-last-character-of-a-string/ Share on other sites More sharing options...
kicken Posted August 26, 2020 Share Posted August 26, 2020 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. Quote Link to comment https://forums.phpfreaks.com/topic/311390-how-do-i-control-the-last-character-of-a-string/#findComment-1580986 Share on other sites More sharing options...
maxxd Posted August 27, 2020 Share Posted August 27, 2020 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. Quote Link to comment https://forums.phpfreaks.com/topic/311390-how-do-i-control-the-last-character-of-a-string/#findComment-1580998 Share on other sites More sharing options...
requinix Posted August 27, 2020 Share Posted August 27, 2020 I guess my question is why the letter is even there in the first place if you don't want to see it. Quote Link to comment https://forums.phpfreaks.com/topic/311390-how-do-i-control-the-last-character-of-a-string/#findComment-1580999 Share on other sites More sharing options...
simona6 Posted August 27, 2020 Author Share Posted August 27, 2020 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. Quote Link to comment https://forums.phpfreaks.com/topic/311390-how-do-i-control-the-last-character-of-a-string/#findComment-1581001 Share on other sites More sharing options...
requinix Posted August 27, 2020 Share Posted August 27, 2020 ... 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. 1 Quote Link to comment https://forums.phpfreaks.com/topic/311390-how-do-i-control-the-last-character-of-a-string/#findComment-1581002 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.