Programing

CSS 컨텐츠를 사용하여 HTML 엔티티 추가

crosscheck 2020. 9. 28. 08:15
반응형

CSS 컨텐츠를 사용하여 HTML 엔티티 추가


CSS content속성을 사용하여 html 엔터티를 추가 하는 방법은 무엇입니까?

다음과 같이 사용하면  공백이 아닌 공백 대신 화면에 인쇄 됩니다.

.breadcrumbs a:before {
    content: ' ';
}

이스케이프 된 유니 코드를 사용해야합니다.

처럼

.breadcrumbs a:before {
    content: '\0000a0';
}

자세한 정보 : http://www.evotech.net/blog/2007/04/named-html-entities-in-numeric-order/


CSS는 HTML이 아닙니다. HTML에서  명명 된 문자 참조 입니다. 십진 숫자 참조에 해당  합니다. 160은 유니 코드 문자 (또는 UCS-2 , HTML 4.01 사양 참조 )의 소수점 코드 포인트 입니다 . 해당 코드 포인트의 16 진수 표현은 U + 00A0 (160 = 10 × 16 1 + 0 × 16 0 )입니다. 유니 코드 코드 차트문자 데이터베이스 에서 찾을 수 있습니다.NO-BREAK SPACE

CSS에서는 문자 코드 포인트의 16 진수 값을 기반으로하는 이러한 문자에 유니 코드 이스케이프 시퀀스를 사용해야합니다. 그래서 당신은 작성해야

.breadcrumbs a:before {
  content: '\a0';
}

이스케이프 시퀀스가 ​​문자열 값에서 마지막에 오는 한 작동합니다. 문자가 뒤 따르면 오해를 피하는 두 가지 방법이 있습니다.

a) (다른 사람이 언급 함) 이스케이프 시퀀스에 정확히 6 개의 16 진수를 사용합니다.

.breadcrumbs a:before {
  content: '\0000a0foo';
}

b) 이스케이프 시퀀스 뒤에 하나의 공백 (예 : 공백) 문자를 추가합니다.

.breadcrumbs a:before {
  content: '\a0 foo';
}

( f16 진수 이므로 여기에서 \a0f의미 GURMUKHI LETTER EE하거나 적절한 글꼴이있는 경우 ਏ을 의미 합니다.)

구분 공백은 무시되며  foo여기에 표시된 공백은 NO-BREAK SPACE문자입니다.

공백 방식 ( '\a0 foo')은 6 자리 방식 ( '\0000a0foo')에 비해 다음과 같은 이점이 있습니다 .

  • 를 입력 하는 것이 더 쉽습니다 . 왜냐하면 선행 0이 필요하지 않고 숫자를 계산할 필요가 없기 때문입니다.
  • 이스케이프 시퀀스와 다음 텍스트 사이에 공백이 있고 숫자를 계산할 필요가 없기 때문에 읽기더 쉽습니다 .
  • 그것은 더 적은 공간을 필요로 앞에 0이 필요하지 않기 때문에;
  • 그것은이다 위쪽으로 호환 미래의 U + 10FFFF 넘어 유니 코드 지원 코드 포인트가 CSS 사양의 수정을 필요로하기 때문에.

따라서 이스케이프 된 문자 뒤에 공백을 표시하려면 스타일 시트에서 두 개의 공백을 사용 하십시오.

.breadcrumbs a:before {
  content: '\a0  foo';
}

-또는 명시 적으로 작성하십시오.

.breadcrumbs a:before {
  content: '\a0\20 foo';
}

자세한 내용은 CSS 2.1, 섹션 "4.1.3 문자 및 대소 문자" 를 참조하십시오.


업데이트 : PointedEars는  모든 CSS 상황에서 올바른
'\a0 '의미는 공백이 16 진수 문자열의 종결 자이며 이스케이프 된 시퀀스에 의해 흡수된다는 것을 의미한다고 언급합니다. 그는 아래에서 설명하고 수정 한 문제에 대한 좋은 해결책처럼 들리는 권위있는 설명추가로 지적했습니다 .

해야 할 일은 이스케이프 된 유니 코드를 사용하는 것입니다. 당신이들은 말에도 불구하고 CSS 내 \00a0에서 완벽한 대립은 아닙니다  . 그래서 시도하십시오 :

content:'>\a0 ';          /* or */
content:'>\0000a0';       /* because you'll find: */
content:'No\a0 Break';    /* and */
content:'No\0000a0Break'; /* becomes No Break as opposed to below */

구체적으로는 사용 \0000a0 . 시도하면 mathieu와 millikin이 제안한대로 :

content:'No\00a0Break'   /* becomes No਋reak */

B를 16 진 이스케이프 문자로 가져옵니다. 0-9a-fA-F에서도 마찬가지입니다.


In CSS you need to use a Unicode escape sequence in place of HTML Entities. This is based on the hexadecimal value of a character.

I found that the easiest way to convert symbol to their hexadecimal equivalent is, such as from ▾ (▾) to \25BE is to use the Microsoft calculator =)

Yes. Enable programmers mode, turn on the decimal system, enter 9662, then switch to hex and you'll get 25BE. Then just add a backslash \ to the beginning.


Use the hex code for a non-breaking space. Something like this:

.breadcrumbs a:before {
    content: '>\00a0';
}

There is a way to paste an nbsp - open CharMap and copy character 160. However, in this case I'd probably space it out with padding, like this:

.breadcrumbs a:before { content: '>'; padding-right: .5em; }

You might need to set the breadcrumbs display:inline-block or something, though.


For Example :

http://character-code.com/arrows-html-codes.php

Example: If you want select your character , I selected "&#8620" "&#x21ac" (We use HEX values)

.breadcrumbs a:before {
    content: '\0021ac';
}

Result : ↬

Thats it :)


I know this is an pretty old post, but if spacing is all your after, why not simply:

.breadcrumbs a::before {
    content: '>';
    margin-left: 8px;
    margin-right: 8px;
}

I have used this method before. It wraps perfectly fine to other lines with ">" by its side in my testing.


Here are two ways:

  • In HTML:

    <div class="ics">&#9969;</div>

This will result into ⛱

  • In Css:

    .ics::before {content: "\9969;"}

with HTML code <div class="ics"></div>

This also results in ⛱

참고URL : https://stackoverflow.com/questions/190396/adding-html-entities-using-css-content

반응형