주요 브라우저에서 구현 한 XHTML의 모든 유효한 자동 폐쇄 요소는 무엇입니까?
XHTML에서 유효한 자체 폐쇄 요소 (예 : <br/>)는 무엇입니까 (주요 브라우저에서 구현)?
XHTML은 기술적으로 모든 요소를 자동으로 닫을 수 있지만 모든 주요 브라우저에서 지원되는 요소 목록을 찾고 있습니다. <div />와 같은 자체 폐쇄 요소로 인한 일부 문제의 예는 http://dusan.fora.si/blog/self-closing-tags 를 참조 하십시오 .
XHTML (Firefox, Opera, Safari, IE9 )을 지원 하는 모든 브라우저는 모든 요소 에서 자체 닫기 구문을 지원합니다 .
<div/>
, <script/>
, <br></br>
모두 잘 작동합니다. 그렇지 않은 경우 XHTML DOCTYPE이 부적절하게 추가 된 HTML 이 있습니다.
DOCTYPE은 문서 해석 방법을 변경하지 않습니다. MIME 형식 만 수행 합니다.
HTML WG는이 문제에 대해 논의했습니다. 구식 (HTML 전용) 브라우저가 지침에 따라 XHTML 1.0 문서를 수락하고이를 텍스트 / html로 제공하도록하는 것이 었습니다. 따라서 text / html로 제공되는 문서는 XHTML이 아닌 HTML로 처리해야합니다.
W3C Validator는이 규칙을 대부분 무시하지만 브라우저는 종교적으로 따르기 때문에 매우 일반적인 함정입니다. WebKit 블로그에서 HTML, XML 및 XHTML 이해를 읽으십시오 .
실제로 인터넷에있는 대부분의 XHTML 문서는로 제공됩니다
text/html
. 이는 XHTML이 아니라 HTML 파서의 오류 처리로 인해 실제로 유효하지 않은 HTML을 의미합니다. 모든 "유효한 XHTML 1.0!" 웹의 링크는 실제로 "잘못된 HTML 4.01!"이라고 말합니다.
XHTML의 DOCTYPE을 사용하여 실제 XHTML 또는 유효하지 않은 HTML이 있는지 테스트하려면 다음을 문서에 넣으십시오.
<span style="color:green"><span style="color:red"/>
If it's red, it's HTML. Green is XHTML.
</span>
그것은 유효성을 검사하고 실제 XHTML에서는 완벽하게 작동합니다 ( 1 대 2 참조 ). 당신의 눈을 믿을 수 없거나 MIME 유형을 설정하는 방법을 모른다면 XHTML 프록시 를 통해 페이지를여십시오 .
확인하는 또 다른 방법은 Firefox에서 소스보기입니다. 유효하지 않으면 슬래시가 빨간색으로 강조 표시됩니다.
HTML5 / XHTML5에서는 변경되지 않았으며 추가 사항이 없기 때문에 구별이 더 명확 DOCTYPE
합니다. Content-Type
왕입니다.
기록을 위해, XHTML 스펙은 XHTML을 XML 애플리케이션 으로 만들어 어떤 요소가 자체적으로 닫힐 수 있도록합니다 . [emphasis mine]
빈 요소 태그는 키워드 EMPTY를 사용하여 선언되는지 여부에 관계 없이 content가없는 모든 요소에 사용될 수 있습니다 .
또한 XHTML 사양 에 명시 적으로 표시됩니다 .
빈 요소가 있어야 하거나 종료 태그 또는로 끝나야 시작 태그가
/>
. 예를 들어,<br/>
또는<hr></hr>
이 주제에서 매우주의해야 할 요소는 <script
> 요소입니다. 외부 소스 파일이 있으면 직접 닫을 때 문제가 발생합니다. 시도 해봐:
<!-- this will not consistently work in all browsers! -->
<script type="text/javascript" src="external.js" />
이것은 Firefox에서는 작동하지만 최소한 IE6에서는 작동하지 않습니다. 내가 본 모든 요소를 지나치게 열성적으로 닫을 때이 문제가 발생했기 때문에 ;-)
자체 닫기 구문은 application / xhtml + xml의 모든 요소에서 작동합니다. text / html의 어떤 요소에서도 지원되지 않지만 HTML4에서 "비어 있거나"HTML5에서 "void"인 요소는 어쨌든 종료 태그를 사용하지 않으므로 슬래시를 넣으면 마치 자체 결산 구문이 지원되었습니다.
로부터 W3 학교 참조 사이트 :
<area />
<base />
<basefont />
<br />
<hr />
<input />
<img />
<link />
<meta />
더 좋은 질문은 코드에 영향을 미치지 않고 HTML 모드에서도 어떤 태그를 자동으로 닫을 수 있습니까? 답 : 빈 내용물이있는 것 (공백)입니다. HTML 사양 에 따르면 다음 요소는 무효입니다.
area, base, br, col, embed, hr, img, input, keygen, link, menuitem, meta, param, source, track, wbr
이전 버전의 사양도 나와 있습니다 command
. 또한 다양한 출처에 따라 다음과 같이 사용되지 않거나 표준이 아닌 태그는 무효입니다.
basefont, bgsound, frame, isindex
이것이 누군가를 돕기를 바랍니다.
<base />
<basefont />
<frame />
<link />
<meta />
<area />
<br />
<col />
<hr />
<img />
<input />
<param />
무엇에 대한 <meta>
그리고 <link>
? 왜 그들은 그 목록에 없습니까?
빠른 경험 법칙은 콘텐츠를 가지고있는 요소를 자동으로 닫지 마십시오. 곧 브라우저 문제가 발생할 수 있기 때문입니다.
자연스럽게 같은 자동 폐쇄,있는 사람 <br>
과는 <img>
분명해야한다. 그렇지 않은 사람들은 ... 그들을 스스로 닫지 마십시오!
The last time I checked, the following were the empty/void elements listed in HTML5.
Valid for authors: area, base, br, col, command, embed, eventsource, hr, img, input, link, meta, param, source
Invalid for authors: basefont, bgsound, frame, spacer, wbr
Besides the few that are new in HTML5, that should give you an idea of ones that might be supported when serving XHTML as text/html. (Just test them by examining the DOM produced.)
As for XHTML served as application/xhtml+xml (which makes it XML), XML rules apply and any element can be empty (even though the XHTML DTD can't express this).
You should have a look the xHTML DTDs, they're all listed. Here is a quick review all the main ones:
<br />
<hr />
<img />
<input />
They're called "void" elements in HTML 5. They're listed in the official W3 spec.
A void element is an element whose content model never allows it to have contents under any circumstances.
As of April 2013, they are:
area, base, br, col, command, embed, hr, img, input, keygen, link, meta, param, source, track, wbr
As of December 2018 (HTML 5.2), they are:
area, base, br, col, embed, hr, img, input, link, meta, param, source, track, wbr
Another self closing tag problem for IE is the title element. When IE (just tried it in IE7) sees this, it presents the user a blank page. However you "view source" and everything is there.
<title/>
I originally saw this when my XSLT generated the self closing tag.
I'm not going to try to overelaborate on this, especially since the majority of pages that I write are either generated or the tag does have content. The only two that have ever given me trouble when making them self-closing are:
<title/>
For this, I have simply resorted to always giving it a separate closing tag, since once it's up there in the <head></head>
it doesn't really make your code any messier to work with anyway.
<script/>
This is the big one that I very recently ran into problems with. For years I had always used self-closing <script/>
tags when the script is coming from an external source. But I very recently started recieving JavaScript error messages about a null form. After several days of research, I found that the problem was (supposedly) that the browser was never getting to the <form>
tag because it didn't realize this was the end of the <script/>
tag. So when I made it into separate <script></script>
tags, everything worked. Why different in different pages I made on the same browser, I don't know, but it was a big relief to find the solution!
<hr /> is another
'IT' 카테고리의 다른 글
CSS를 사용하여 입력 버튼 이미지를 변경하는 방법은 무엇입니까? (0) | 2020.05.17 |
---|---|
WPF 탐색을위한 Window vs Page vs UserControl? (0) | 2020.05.17 |
Windows FINDSTR 명령의 문서화되지 않은 기능 및 제한 사항은 무엇입니까? (0) | 2020.05.17 |
Maven 빌드의 "java.lang.OutOfMemoryError : PermGen 공간" (0) | 2020.05.17 |
AngularJS에서 $ http 요청을 취소하는 방법? (0) | 2020.05.17 |