:target-within
Quick Summary for :target-within
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
Code Usage for :target-within
/* Selects a <div> when one of its descendants is a target */ div:target-within {   background: cyan; } 
More Details for :target-within

:target-within

Experimental: This is an experimental technologyCheck the Browser compatibility table carefully before using this in production.

The :target-within CSS pseudo-class represents an element that is a target element or contains an element that is a target. A target element is a unique element with an id matching the URL's fragment. In other words, it represents an element that is itself matched by the :target pseudo-class or has a descendant that is matched by :target. (This includes descendants in shadow trees.)

/* Selects a <div> when one of its descendants is a target */ div:target-within {   background: cyan; } 

Syntax

:target-within

Examples

Highlighting an article

The :target-within pseudo-class can be used to highlight the article if anything inside it has been directly linked to. The :target pseudo-class is also being used to show which item has been targeted.

HTML
<h3>Table of Contents</h3> <ol>  <li><a href="#p1">Jump to the first paragraph!</a></li>  <li><a href="#p2">Jump to the second paragraph!</a></li>  </ol>  <article>  <h3>My Fun Article</h3> <p id="p1">You can target <i>this paragraph</i> using a   URL fragment. Click on the link above to try out!</p> <p id="p2">This is <i>another paragraph</i>, also accessible   from the links above. Isn't that delightful?</p> </article> 
CSS
article:target-within {   background-color: gold; }  /* Add a pseudo-element inside the target element */ p:target::before {   font: 70% sans-serif;   content: "►";   color: limegreen;   margin-right: .25em; }  /* Style italic elements within the target element */ p:target i {   color: red; } 
Result

Specifications

Specification
Selectors Level 4 # the-target-within-pseudo

See also

:target Select your preferred language English (US)Français Change language

No Items Found.

Add Comment
Type in a Nick Name here
 
Other Categories in CSS
css
Search CSS
Search CSS by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

Subscribe to weekly updates about things i have added to the site or thought interesting during the last week.

You could also follow me on twitter or not... does anyone even use twitter anymore?

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕

❤️👩‍💻🎮

🪦 2000 - 16 Oct 2022 - Boots
Random Quote
In this case my anchor this week becomes driving almost 2hrs outside of Atlanta to one of my favorite hard core gyms in the world.. MetroFlex aka The Dungeon. The gym owners turn the heat way up so it becomes a fun sweat box and the gym members just watch from afar and leave me alone. I happily drive myself long distances to find MY ANCHOR. Our anchor allows us to have balance, focus and be as productive as possible. And if you're in the middle of a heavy set and your headphones start to fall off your head, like mine did here.. well.. f*ck the headphones. Let em break and fall. You can always get a new pair, but the iron ain't ever gonna lift itself.
Unknown
Random CSS Property

scroll-padding-block-end

The scroll-padding-block-end property defines offsets for the end edge in the block dimension of the optimal viewing region of the scrollport: the region used as the target region for placing things in view of the user. This allows the author to exclude regions of the scrollport that are obscured by other content (such as fixed-positioned toolbars or sidebars) or to put more breathing room between a targeted element and the edges of the scrollport.
scroll-padding-block-end css reference