Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select a text (without tag) in a div using CSS selector?

I have this :

<div class="foo">
    <h3>Title</h3>
    Some text I want to select using a CSS selector.
    <div class="subfoo">Some other text</div>
</div>

Is it possible to select only "Some text I want to retrieve using a CSS selector" using a single expression of CSS selectors ?

like image 328
Reveclair Avatar asked Jul 30 '15 09:07

Reveclair


1 Answers

It's not possible to do in a clean manner with pure CSS.

As Vangel as suggested I recommend setting the styling for it in a .foo selector then apply overrides for other elements:

.foo{
  //Some text styles
}
.foo *{
  //Overriding styles
}

However the best option would be to make changes to the HTML to place the text in its own element so it can be styled in isolation:

<div class="foo">
    <h3>Title</h3>
    <span>Some text</span>
    <div class="subfoo">Some other text</div>
</div>

.foo span
{
   //Some text styling
}
like image 82
Curtis Avatar answered Oct 20 '22 23:10

Curtis