Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
291 views
in Technique[技术] by (71.8m points)

html - Adding double quotes to a paragraph with CSS

Lets say I have this paragraph:

<p class="myclass">This is my paragraph</p>

What is the CSS code to add double quotes to this paragraph? (So it will render "This is my paragraph")

.myclass {}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Actually, the accepted answer is wrong, or at least suboptimal. It should be:

q { quotes: '201c' '201d'; }
q:before { content: open-quote; }
q:after  { content: close-quote; }

The 201c here is Unicode for a left curly double quote. There's no reason you could not write the double quotes directly in the rule for q:

q { quotes: '“' '”'}

open-quote and close-quote are special values for the content property, which refer to the strings given as values for the quotes property.

Now you can just say:

<p><q>This is my paragraph</q></p>

Or some variant thereof; you could of course add the before and after rules directly on p if you would prefer:

body { quotes: '201c' '201d'; }
p:before { content: open-quote; }
p:after  { content: close-quote; }

This permits you to factor out the specific characters used for quotes using the quotes property, without changing all the before and after rules. For instance, you can then do things such as

:lang(de) { quotes: "?" "?"; }

to get German-style quotes, if the lang attribute has been set to de on any ancestor.

The quotes property actually allows you to specify additional sets of quotes, for use with nested quotes. See the docs for more details.

body { quotes: '201c' '201d'; }
q:before { content: open-quote; }
q:after  { content: close-quote; }

:lang(de) { quotes: "?" "?"; }
<p>Quoth the raven, <q>Never more.</q></p>

<p lang="de">Sprach der Rabe: <q>Nie du Tor.</q></p>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...