Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visualize whitespaces using css

Tags:

Is there some way to visualize whitespaces in text using only CSS without altering the original HTML code? Lets say the HTML is:

<div class="paragraph">Lorem ipsum dolor sit amet,<br/>consectetur adipiscing elit.</div><div class="paragraph">In augue ipsum, iaculis vel dapibus ut, viverra ut tellus. In ornare euismod leo a ultrices.</div> 
  • paragraph end (¶) -> can use :after
  • line break (↵) -> can use :after
  • space (·) -> the only way I can think of is to prepend all spaces with something like <span class='space' /> and the use :after

The last one does not fulfill the condition to use only CSS and original HTML. Is there some way to do that?

EDIT: as requested, here is CSS for the pilcrow sign after the paragarph: .paragraph:after { content: "¶"; }

like image 829
bretik Avatar asked Oct 26 '11 09:10

bretik


People also ask

How do you show Whitespaces in HTML?

HTML Paragraph (<p>) Tag With <p>, browsers will add some extra whitespace with this line break to make consecutive paragraphs more readable, so it can be used any time you're using blocks of text that are distinct from each other.

What is pre-line in CSS?

pre-line. Sequences of whitespace will collapse into a single whitespace. Text will wrap when necessary, and on line breaks.

How do you show Whitespaces in VS code?

In Visual Studio for Windows, to display whitespace characters (tabs, spaces, etc) you simply press Ctrl + R, Ctrl + W.

What is white-space pre wrap in CSS?

pre-wrap: When the white-space property of CSS is set to a pre-line value, every sequence of white-spaces will appear as it is. The content in the element will be wrapped when required and when explicitly specified.


2 Answers

javascript and php are probably easier, but if you insist on CSS you can use a custom web font and replace the space character (U+0020) with a glyph. Information for somewhat browser compatible css and generating custom web font

like image 139
uncreative Avatar answered Nov 07 '22 21:11

uncreative


I doubt this can be achieved by CSS. It's selectors ar designed to select tags, not plain text.

I recommend you to use some script replace - server or client side. You can try to use PHP preg_replace or JavaScript replace functions.

like image 30
Rusty Horse Avatar answered Nov 07 '22 20:11

Rusty Horse