Insert special character using :before pseudo clas

2020-08-09 05:03发布

I was toying around with the :before pseudo class in css, trying to insert a special character but the result is not what I was hoping for.

Using:

.read_more:before {
    content: "»";
    margin-right: 6px;
}

I get the character I want, but with an  character before it and using:

.read_more:before {
    content: "»";
    margin-right: 6px;
}

I get the complete » on the html page.

I can think of a couple of ways to solve my problem, but I was wondering what the correct syntax would be if I wanted to use the :before pseudo class.

By the way, my doctype is:

<!doctype html>
<html lang="en">

6条回答
家丑人穷心不美
2楼-- · 2020-08-09 05:16

I know it's been a while since this question was asked but in case someone might need it nowadays, I found the solution for it.

Here's a chart with lots of glyphs. Find the one you want and copy the hex code for it.

Then paste it here to convert.

You'll get a value that looks like this: \00E1 (CSS Value)

Paste this value on your 'content:' and be happy :)

查看更多
我欲成王,谁敢阻挡
3楼-- · 2020-08-09 05:19

Add this on the html, inside the <head> section

<meta HTTP-EQUIV="content-type" CONTENT="text/html; charset=UTF-8" />

But if the html page is coded in PHP, I would prefer the following:

<?php
    header("Content-Encoding: utf-8");
    header("Content-type: text/html; charset=utf-8");
?>

And don't forget to save any file (css, html, php) with UTF-8 encoding

查看更多
三岁会撩人
4楼-- · 2020-08-09 05:23

try this

.read_more:before {
    content: "\00BB";
    margin-right: 6px;
}

\00BB is the unicode representation of that character. It should reasonably works =)

查看更多
Evening l夕情丶
5楼-- · 2020-08-09 05:31

The answer has been already told, but I want to refer to:

I get the complete &raquo; on the html page.

That's because CSS content property isn't treated as HTML. It's not appended to the DOM, therefore any HTML-specific markup isn't parsed. You can insert a character directly: content: "Ԃ"; or use Unicode notation: content: "\0504";.

查看更多
聊天终结者
6楼-- · 2020-08-09 05:36

Your browser isn't using the correct text encoding -- that is, it isn't using the same text encoding as your editor. If you are receiving the page from a Web server, the best approach is to make sure the server is sending the proper Content-Type header. If you don't have control over the Web server's headers, or if you will be doing a lot of testing using local HTML files, add appropriate tags to your document for the encoding and HTML version you are using. I recommend using UTF-8. The CSS file (if it is separate from the HTML) should use the same encoding.

查看更多
The star\"
7楼-- · 2020-08-09 05:40

Try specifying <meta charset="utf-8">. Ideally you want to set this in the server.

查看更多
登录 后发表回答