使用CSS属性在div中选择文本

时间:2015-11-27 10:51:18

标签: css

尝试使用CSS属性选择div中的某个文本块。

似乎没有采取任何其他选择?我尝试了各种各样的

 .welcome [text~="You are logged in as"]{
    display:none;
 }

HTML文字是

 <div id="welcome">
    You are logged in as <a href="example.com">Me</a> <b>(</b> <a   href="http://example.com/index.php?route=account/logout">Logout</a> <b>)</b>         </div>

2 个答案:

答案 0 :(得分:4)

您只能将[ ]用于html属性(如id,class ...),而不能用于文本。你必须使用javascript或其他东西。 顺便说一下,它是#welcome,而不是.welcome:)

答案 1 :(得分:1)

您可以稍微更改html,以定位整个文本或部分内容:

<div id="welcome">
  <span class="target_one">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span>
  <span class="target_two">Aenean quis augue gravida, ornare arcu quis, gravida arcu.</span>
</div>

然后css变得容易了:

#welcome .target_one { color:red; }
#welcome .target_two { color:green; }