Skip to content Skip to sidebar Skip to footer

Css Class Selector To Select Text Inside A 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 sh

Solution 1:

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;
}

With

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

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.


Solution 2:

You could try using the :before or :after pseudo-elements.

I was playing with this solution, for 1-line divs:
http://jsfiddle.net/yAfKw/

Multi-line divs:
http://jsfiddle.net/yAfKw/1/

Works in Firefox, does not work in Safari.


Post a Comment for "Css Class Selector To Select Text Inside A Div"