开发者

CSS - Select all elements that are outside of a particular element

I would like to select all elements which are outside of my container div using CSS and would like to know how this is done.

I attempted to select all elements which are not container elements - :not(container) - but this results in all elements which are contained in the container element to be affected开发者_开发百科 too.

I am looking to do something along the lines of the following:

Apply this to all elements OUTSIDE of 'container'

do NOT include elements contained WITHIN 'container'.

How do I achieve this?


You could use something like this:

(parent element) > *:not(container)

">" selects all direct children of the parent element specified, unfortunatly this will not work if you have divs outside the container that are not direct descendants of the parent but you could use multiple selectors such as:

(parent element) > *:not(container) > *:not(container)

You will need to replace (parent element) with your chosen selector


This does the trick for me:

parent:not(container) {}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜