css类选择器来选择div内的文本

css类选择器来选择div内的文本

本文介绍了css类选择器来选择div内的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个div,类名为test。类test具有分配给它的光标指针。类的固定宽度为200px。在div内部是长度短于div宽度的文本。我不希望当鼠标放在div的空白部分时出现点。

I have a div with a classname "test". The class "test" has a cursor pointer assigns to it. The class also has a fixed width of 200px. Inside the div is text of length that is shorter than the width of the div. I don't want the point to appear when the mouse is placed in the blank part of the div.

有一种方法可以将css指针指定给div内部的文本,而不将文本放在另一个< span> code>标记。我只是不想回去,并将span标记添加到每一个div并重写javascript。

Is there a way that I can assign the css pointer to the text inside the div without wrapping the text inside another <span> tag. I just don't want to go back and add the span tag to every single div and rewrite the javascript.

我想像这样的伪css代码



I am thinking of something like this pseudo css code

.test.text {
  cursor:pointer;
}


推荐答案

办法。正如biziclop在评论中所说,。您必须在< span> 中包装您的文字,并使用

CSS doesn't work this way. As biziclop says in the comments, text nodes can't be selected with CSS. You'll either have to wrap your text in a <span> and use

.test span {
    cursor: pointer;
}

使用

<div class="test">
    <span>Text</span>
</div>

或将 .test 设为 display:inline ,但这不会让你给它一个宽度,这不是你想要的行为。 < span> 很好,在这种情况下。

Or set .test to display: inline, but that won't let you give it a width, which is not the behaviour you want. <span>s are fine, in this case.

这篇关于css类选择器来选择div内的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 16:15