apocalypse
apocalypse

Reputation: 5884

HTML / CSS own entity

Is this possible to do own entities?

Like: &longline; --> -----------------------------

then use it in html code:

<div>
    &longline;
    bla bl bla
</div>

Upvotes: 1

Views: 91

Answers (4)

Ry-
Ry-

Reputation: 224942

It's possible in XML using the <!ENTITY> declaration, but I wouldn't recommend it. Your site would no longer be HTML, and most browsers wouldn't accept it. (Indeed, none do, unless your file is XML, which rather defeats the purpose.) Client-side processing using JavaScript is possible, but not accessible. Server-side processing is a waste of time, unless it's user input, in which case you should replace the entities before inserting the data into your database.

So, yes, it's possible, but unless you have a good reason to do it... don't!

Upvotes: 2

Rok Kralj
Rok Kralj

Reputation: 48735

No, not in pure HTML.

However, this desired behaviour could be achieved with javascript (or PHP, python, ruby). You could scan all the text nodes with it and replace accordingly.

However, I hardly see why would you like such behaviour. I think you should use propperly styled <hr> element. CSS support border: 1px dashed black; so it would look like many dashes (-).

Php also has function str_repeat('-', 30);. That would make 30 dashes, but it has to be replaced server-side.

Upvotes: 1

Billy Moon
Billy Moon

Reputation: 58531

Not possible with HTML, but best way to achieve this would be server side scripting, so that the user receives pure well formed HTML, but gives the developer the freedom to use methods like what you want to do to generate the HTML.

PHP could do this by caching the output, then replacing all occurrences with your new string.

Upvotes: 1

Jon Newmuis
Jon Newmuis

Reputation: 26502

No.

If you're using a server-side language, you can use a string replace function in that language (PHP, C#, Java, Ruby, etc.), but not in pure HTML.

Upvotes: 1

Related Questions