views:

21

answers:

1

Is there any way only using CSS (no script) to check if an element such as a table contains another element such as with the target? I know that you can use the :target pseudo class for elements with the target, but I need the ability to select an element which contains the element with the target. If there's any way to using the :contains pseudo class to check if an element contains the target that'd be useful, however I've tried it a few different ways with no success. I know there isn't a parent selector which rules out looking for the parent of the element with the target URI. The only possible ways I can think of are using :contains and I don't think that'll even work with anything but text. If anyone knows some sort of trick or other selector that'd solve this issue, help would be appreciated.

A: 

First guess:

I'm having a hard time understanding your question, so my answer is offered on the assumption that your question is something like this:

Is there any way to style the parent of a targeted element?

And the answer is no, css works by cascading down the hierarchy, it can't cascade up; have a read of the following questions/answers for further details:

(There are others, if you search for 'css parent selectors')


Second guess:

If your question is:

can I find links that target other sections of the same page?

Then yes, you can (with css3 and/or using jQuery):

a[href*='#'] { /* css */ }
$("a[href*='#']") // jQuery selector

The href*='#' part is an attribute-selector, that searches the 'href' attribute for any occurrence1 of the quoted string '#' (the # being used to target same-page links).

If you're able to revise your question to make it more clear what you'd like us to help you with, then I'll be more than happy to try and be more use to you, but as it is I can only guess. Which is pretty much useless. =(


Footnotes:

  1. Other options are:
    • starts with, eg: a[href^='http://'] which selects all links whose href begin with 'http://', and
    • ends with, eg: a[href$='.pdf'], which selects all links that end with the filetype .pdf.
David Thomas