문제

Instead of:

<a href="http://really-exceptionally-ridiculously-long-example.com">go</a>

I'd like:

<a href="http://really-exceptionally- ridiculously-long-example.com">go</a>

But this is invalid because of the whitespace indentation.

While I could do:

<a href="http://really-exceptionally- ridiculously-long-example.com">go</a>

I would like to have pretty formatted source. And that means no long lines and proper whitespace indentation.

Is there a difference between different versions of HTML/XHTML?

도움이 되었습니까?

해결책

An attribute value that is declared to be a URL, such as an href attribute value, must not contain whitespace at all (by generic URL syntax), except that HTML5 permits whitespace around the URL. (%-encoded whitespace such as %20 is permitted, but it then means that the actual URL contains whitespace.)

So you simply cannot break an href attribute value across lines, or to have spaces inside the URL.

If you wish to reduce line length in HTML source in your example, you cannot thus get any shorter than here:

<a href=
http://really-exceptionally-ridiculously-long-example.com
>go</a>

Quotation marks are not required around attributes like this, in browser practice or by HTML5 rules (HTML 4.01 is more restrictive, and so are all versions of XHTML).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top