CSS规则在2个标签之间定位文本 [英] CSS rule to target text between 2 tags

查看:233
本文介绍了CSS规则在2个标签之间定位文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HTML:

 < p& 
< span> blah< / span>
blah
< span> blah< / span>
lorum ipsum
< br>
< span> blah< / span>
blah
< span> blah< / span>
lorum ipsum
< / p>

给定这个HTML,是否有任何方式可以样式所有 blah 一种颜色(在之内和之间),并为剩余文本设置不同的颜色?它必须是支持IE7及以上的纯CSS解决方案。



显然,我可以这样做:

  p {
color:#000;
}
p span {
color:#f00;
}

但这会留下一个 blah black。

解决方案


有什么方法可以$ c> blah 一种颜色,并为其余文字设置不同的颜色?


使用纯CSS执行此操作。



您需要更改标记(添加另一个语义范围),或者使用一些JavaScript在运行时修改标记。 p>

如果你的 span 文本都在第一行,你可以样式:第一行


HTML:

<p>
    <span>blah</span>
    blah
    <span>blah</span>
    lorum ipsum
    <br>
    <span>blah</span>
    blah
    <span>blah</span>
    lorum ipsum
</p>

Given this HTML, is there any way that I can style all of the blah one color (inside and outside the spans) and style the remaining text a different color? It must be a pure CSS solution with support for IE7 and above.

Obviously I can do something like this:

p {
    color:#000;
}
p span {
    color:#f00;
}

but this leaves one blah black.

解决方案

Is there any way that I can style all of the blah one color, and style the remaining text a different color?

There's no way of doing this with pure CSS.

You'll either need to change your markup (add another semantic span), or use some JavaScript to modify the markup at runtime.

As a long shot, if your span text is all on the first line, you could style :first-line.

这篇关于CSS规则在2个标签之间定位文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆