1

Given HTML that looks like this:

<td class="n">1234.56</td>

I would like, using only CSS (without having to use, say, a <span> element in the HTML), to format the number with the last two digits (or, in general, characters) diminished in size.

My goal is to write a CSS stylesheet rule for the unadorned HTML above that behaves as if I had this:

<style>
.diminish { font-size: 50% }
</style>
<td class="number">1234.<span class="diminish">56</span></td>
5
  • You kind could but not really, if the content is always 1234.56 then you could use :before or :after to manipulate it but I am sure you have different content Commented Mar 9, 2015 at 18:34
  • ::before and ::after insert a fake element before and after the current one, so it wouldn't select the digits which are part of the element. The only CSS selector which can select characters is ::first-letter which selects the first letter of a paragraph. You have no choice but to edit the html, sorry. Commented Mar 9, 2015 at 18:43
  • What if you changed it to have a space before the decimal point? Is that doable? Commented Mar 9, 2015 at 18:44
  • @SmokeyPHP, I could (with some pretty weird rendering code)..., but I wonder what you're driving at? Commented Mar 9, 2015 at 18:47
  • Just thinking about white space wrapping with a hidden overflow and then same again for the other part in a pseudo element. You'd set the size small but to allow horizontal overflow and turn off word breaking, then hide the bottom wrapping (the decimals), then try and get just the second line in the :after pseudo element with the same technique Commented Mar 9, 2015 at 18:49

1 Answer 1

3

That is not possible with pure CSS. Only html as you pointed out or Javascript.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.