开发者

Insert special character using :before pseudo class in css

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 pseu开发者_如何转开发do class.

By the way, my doctype is:

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


try this

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

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


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";.


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


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 :)


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜