क्या एक तत्व के लिए सीएसएस शैली को परिभाषित करना संभव है, यह केवल तभी लागू किया जाता है यदि मिलान तत्व में एक विशिष्ट तत्व (प्रत्यक्ष बच्चे की वस्तु के रूप में) हो?
मुझे लगता है कि यह एक उदाहरण का उपयोग करके सबसे अच्छा समझाया गया है।
नोट : मैं मूल तत्व को स्टाइल करने की कोशिश कर रहा हूं , यह इस बात पर निर्भर करता है कि इसमें कौन से बाल तत्व हैं।
<style>
/* note this is invalid syntax. I'm using the non-existing
":containing" pseudo-class to show what I want to achieve. */
div:containing div.a { border: solid 3px red; }
div:containing div.b { border: solid 3px blue; }
</style>
<!-- the following div should have a red border because
if contains a div with class="a" -->
<div>
<div class="a"></div>
</div>
<!-- the following div should have a blue border -->
<div>
<div class="b"></div>
</div>
नोट 2 : मुझे पता है कि मैं जावास्क्रिप्ट का उपयोग करके इसे प्राप्त कर सकता हूं, लेकिन मैंने अभी सोचा कि क्या यह कुछ अज्ञात (मेरे लिए) सीएसएस सुविधाओं का उपयोग करके संभव है।
ol < li:nth-child(n+10) { margin-left: 2rem; } ol < li:nth-child(n+100) { margin-left: 3rem; } ol < li:nth-child(n+1000) { margin-left: 4rem; }एक आदर्श दुनिया में यह निहित बच्चों olकी संख्या पर निर्भरता के मार्जिन को बढ़ाएगा liताकि बाईं ओर का मार्जिन केवल उतना ही चौड़ा हो जितना कि होना चाहिए।