“”와“”의 차이점은 무엇입니까?
둘 다 공간을 의미하지만 차이점이 있습니까?
하나는 속하지 않는 공간 이고 다른 하나는 일반 공간입니다. 줄 바꿈하지 않는 공간은 단어 중간에 줄 바꿈이되지 않는 것처럼 해당 지점에서 줄을 줄 바꿈하지 않아야한다는 의미입니다.
또한 Svend가 그의 의견에서 지적했듯이, 비 공백 공간은 축소되지 않습니다.
엔터티
는 비 분리 공간을 생성하며,이 위치에서 자동 줄 바꿈을 원하지 않을 때 사용됩니다. 일반 공간에는 문자 코드 32가 있고, 비 공백 공간에는 문자 코드 160이 있습니다.
예를 들어, 공백이있는 숫자를 천 단위 구분 기호 : 1 234 567로 표시 할 경우 숫자를 별도의 줄로 나눌 수 없도록 끊지 않는 공백을 사용합니다. 통화를 표시하고 금액과 통화 사이에 공백이있는 경우 : 42 SEK, 한 줄에 금액을 가져오고 다음 줄에 통화를 얻지 않도록 비 공백 공백을 사용합니다.
여기의 다른 답변 외에도 일반 공간과 같이 비 분리 공간은 "축소"되지 않습니다. 예를 들어
<p>Word1 Word2</p>
과
<p>Word1 Word2</p>
모든 브라우저에서 동일하게 렌더링됩니다.
<p>Word1 Word2</p>
렌더링 될 때 공백을 유지합니다.
예만큼 대답이 아닙니다 ...
예 # 1 :
<div style="width:45px; height:45px; border: solid thin red; overflow: visible">
Hello There
</div>
예 # 2 :
<div style="width:45px; height:45px; border: solid thin red; overflow: visible">
Hello There
</div>
그리고 바이올린에 연결하십시오 .
여기에 실제 예제가 있습니다.
http://codepen.io/anon/pen/GJzBxo
과
http://codepen.io/anon/pen/LVqBQo
같은 div, 같은 텍스트, 다른 "공백"
<div style="width: 500px; background: red"> [loooong text with spaces]</div>
vs
<div style="width: 500px; background: red"> [loooong text with ]</div>
여러 일반 공백 문자 (공백, 표 및 줄 바꿈)는 하나의 공백 문자로 처리됩니다 .
을 제외한 모든 HTML 요소의 경우
PRE
공백 시퀀스는 "단어"를 분리합니다 (여기서는 "단어가 아닌 공백 문자의 순서"를 의미하기 위해 "단어"라는 용어를 사용합니다). 텍스트를 형식화 할 때 사용자 에이전트는 이러한 단어를 식별하고 특정 서면 언어 (스크립트) 및 대상 매체의 규칙에 따라 배치해야합니다.
그래서
foo bar
로 표시됩니다
foo bar
그러나 휴식 공간이 항상 표시됩니다. 그래서
foo   bar
로 표시됩니다
foo bar
이미 언급 한 바와 같이 "중단 공간 없음"이있는 경우 줄 바꿈을받지 않습니다.
또한 ""만 포함 된 요소가 잘못 표시 될 수 있습니다. & nbsp; 작동합니다. 즉 6에서 (내가 기억하는 한 IE7에는 동일한 문제가 있습니다) 빈 테이블 요소가있는 경우 내용이 없거나 흰색 만있는 경우 요소와 같은 스타일을 적용하지 않습니다 (예 : 테두리) 우주. 따라서 다음과 같이 테두리가 렌더링되지 않습니다.
<td></td>
<td> <td>
이 예제에서 테두리가 표시되는 반면 :
<td>& nbsp;</td>
흠-여기에 올바르게 렌더링하기 위해 더미 공간에 넣어야했습니다.
첫 번째는 HTML 파서에 의해 공백으로 처리되지 않으며 두 번째는 공백으로 처리됩니다. 결과적으로 ""이 (가) 특정 HTML 마크 업 내에 표시되는 것을 보장하지는 않지만 깨지지 않는 공간은 항상 표시됩니다.
공백으로 처리해야합니다.
공백 두 개로 처리해야합니다.
''는 흥미롭지 않은 공백으로 처리 될 수 있습니다.
' ' + ' ' can be handled as a single ' '
is stackable, meaning you can create multiple spaces all together.
HTML will only parse one space '' and it drops the rest...
If you want five spaces, you would place 5 x
@Zoidberg is right, example:
<h1>title</h1> <h2>date</h2>
will not display space between header markup, with
& nbsp ;
will do space :)
When having line-breaks, the line will not break when you use an $bnsp; because it's a 'non-breaking space'. This can be important if you have certain product-names or such, that always shall be written together.
Can be interesting if you (have to) use a whitespace as delimiter in numbers, like 12344567, that is displayed 12 344 567 in France. Without the the line would break in the middle of the number, very ugly. Test:12 344 567
TLDR; In addition to the accepted answer; One is implicit and one is explicit.
When the HTML you've written or had generated by an application/library/framework is read by your browser it will do it's best to interpret what your HTML meant (which can vary from browser to browser). When you use the HTML entity codes, you are being more specific to the browser. You are explicitly telling it you wish to display a character to the user (and not that you are just spacing your HTML for easier readability for the developer for instance).
To be more concrete, if the output HTML were:
<html>
<title>hello</title>
<body>
<p>
Tell me and I will forget. Teach me and I
may remember. Involve me and I will learn.
</p>
</body>
</html>
The browser would only render one space between all of these words (even the ones that have been indented for better developer readability.
If, however, you put the same thing and only changed the <p>
tag to:
<p>Hello There</p>
Then it would render the spaces, as you've instructed it more explicitly. There is some history of using these spaces for styling. This use has somewhat been diminished as CSS has matured. However, there are still valid uses for many of the HTML character entities: avoiding unexpectedly/unintentionally interpretation (e.g. if you wanted to display code). The w3 has a great page to show the other character codes.
참고URL : https://stackoverflow.com/questions/1357078/whats-the-difference-between-nbsp-and
'IT' 카테고리의 다른 글
아무것도 선택하지 않도록 jQuery에서 라디오 버튼을 재설정하는 방법 (0) | 2020.06.30 |
---|---|
Java에서 파생 클래스의 재정의 메서드에서 기본 클래스의 메서드를 어떻게 호출합니까? (0) | 2020.06.30 |
Django에서 사용자가 특정 그룹에 있는지 어떻게 확인합니까? (0) | 2020.06.30 |
Javascript에서 신기원 이후 몇 초를 얻을 수 있습니까? (0) | 2020.06.30 |
JDBC로 postgres에 연결할 때 스키마를 지정할 수 있습니까? (0) | 2020.06.30 |