作为我的研究项目的一部分,我需要更改段落内单个单词(“ adventure”)的背景。我不允许更改HTML代码,只能使用CSS。
<p class="section_text">
Welcome to adventure!
</p>
我唯一的想法是将背景设置为伪元素::after
并以相对/绝对位置播放,但是感觉不对。
.section_text {
position: relative; }
.section_text::after {
content: "adventure";
background-color: #04128f;
color: #0f0;
width: 65px;
height: 20px;
position: absolute;
top: 0;
left: 90px; }
是否有任何明智的方法(应该在最新版本的Chrome中运行)?附言不能同时使用JS或jQuery。不应更改感叹号的背景。
将固有字体大小设置为:root
选择器。例如:root {font-size: 5vw}
。这使字体响应视口宽度。
编辑:要更改任意位置字的背景颜色,请参见下面的zer00ne's answer。我没有彻底阅读问题,OP希望使用单词adventure
而不是adventure!