带css的文本中的上标第一项

带css的文本中的上标第一项,css,superscript,Css,Superscript,我想在这个文本的第一个字符上标上css$50.00,这样,$的高度就只有文本其余部分的一半 如何使用css实现这一点?有没有办法在一段文本中选择第一个符号并用css为其上标 span.price:before{ content:'$'; font-size:xx-small; vertical-align:top; } 这将使: <p>The current price is <span class="price">100.0</span></p>

我想在这个文本的第一个字符上标上css$50.00,这样,$的高度就只有文本其余部分的一半

如何使用css实现这一点?有没有办法在一段文本中选择第一个符号并用css为其上标

span.price:before{ content:'$'; font-size:xx-small; vertical-align:top; }
这将使:

<p>The current price is <span class="price">100.0</span></p>
除了美元是上标

编辑:我再次测试了它,可以确认上面的工作。但是,并非所有浏览器都支持css中的前后格式。

否则,您可以像这样使用html:

<p>The current price is <sup class="price">$</sup>100.0</p>
目前的价格是100.0美元

两种解决方案的概念验证标记:

<!DOCTYPE html>
<html dir="ltr" lang="en-US"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    <meta charset="UTF-8"> 
    <title>Price test</title> 
    <style>
        span.price:before{ content:'$'; font-size:xx-small; vertical-align:top; }
    </style>
</head> 
<body>
    <p>The price is <span class="price">100.0</span></p>
    <p>The price is <sup>$</sup>100.0</p>
</body></html>

价格测试
span.price:before{content:'$”;字体大小:xx小;垂直对齐:top;}
价格是100.0美元

价格是100美元

<!DOCTYPE html>
<html dir="ltr" lang="en-US"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    <meta charset="UTF-8"> 
    <title>Price test</title> 
    <style>
        span.price:before{ content:'$'; font-size:xx-small; vertical-align:top; }
    </style>
</head> 
<body>
    <p>The price is <span class="price">100.0</span></p>
    <p>The price is <sup>$</sup>100.0</p>
</body></html>