CSS nested selector, target only the second level elements and disregard the first and any levels beyond the third

I have a complex structure with nested divs and classes. The hierarchy is as follows: row-container, row, row-content, col, and col-inner.

Objective: I aim to target only the "col" class on the second level of the "box" class, while disregarding the first and subsequent levels.

Below is the cleaned HTML markup, followed by the working CSS code and two expected CSS versions that are currently not functional.

Working CSS:

.box > .row-content > .col > .col-inner > .row-container > .row > .row-content > .col { 
        /* css stuff */ 
    }
    

Expected CSS 1: (not working)

.box > .row-content:nth-of-type(2) > .col { 
        /* css stuff */ 
    }
    

Expected CSS 2: (not working)

.box > .row-content > .row-content > .col { 
        /* css stuff */ 
    }
     

HTML Code


        <div class="box row"> 
            <div class="row-content">
                <div class="col"> <!-- IGNORE THIS COL -->
                    <div class="col-inner">
                        <div class="row-container">
                            <div class="row"> 
                                <div class="row-content">
                                    <div class="col"> <!-- TARGET COL -->
                                        <div class="col-inner">
                                            <!-- do stuff -->
                                        </div>
                                    </div>
                                    <div class="col"> <!-- TARGET COL -->
                                        <div class="row">
                                            <div class="row-content">
                                                <div class="col"> <!-- IGNORE THIS COL -->
                                                    <div class="col-inner">
                                                        <!-- do stuff -->
                                                    </div>
                                                </div>
                                                <div class="col"> <!-- IGNORE THIS COL -->
                                                    <div class="col-inner">
                                                        <!-- do stuff -->
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div> 
    

Any assistance or suggestions would be greatly appreciated!

Answer №1

Presenting to you...

.container .row-wrapper > .item-row > .content-row > .column {
    /* styling in css */
}

Answer №2

Feel free to give this a shot

.container .row .column:nth-child(1){
      /*Applicable CSS*/
 }
 .container .row .column:nth-child(2){
     /*Relevant CSS*/
 }

Answer №3

Your issue should be resolved with this solution

.row > .row-content > .col

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Attempting to position the input field beside the label

I need help aligning the input field box next to my label. Currently, there is a gap between the text (label) and the input field when clicking on Item#1 and Invoice Number. I want the input field to be directly next to the label. Can anyone assist me with ...

In relation to the adaptability of websites to smaller screens

Welcome to my first website! You can check out my portfolio at . I decided to go for free hosting on Webhost, but I've encountered a problem - despite using Bootstrap classes in my code, my page is not fully responsive on small screens. Any suggestion ...

Eliminate the gaps within CSS3 columns

I'm attempting to achieve an effect that looks like: C---------------------------------------) | Address 1 | Phone Numbers | | Address 2 | Times place is open | (---------------------------------------) However, the spacing with th ...

Intersection Observer API is not compatible with the functionality of the navigation bar

Having trouble with the Intersection Observer API. Attempting to use it to show a nav-bar with a white background fixed to the viewport once it scrolls out of view. Initially tested using console.log('visible') successfully to determine visibili ...

Trouble with Bootstrap v4 toggle drop-down menu functionality detected in local environment, yet functions correctly when live on the

Today, I've encountered an issue with my Bootstrap v4 collapsible hamburger menu on my local XAMPP server. Interestingly, the menu works perfectly fine on my public website when the display is 768px wide in Chrome and Firefox. I have searched through ...

Easily automate button clicks on a new tab website

Seeking assistance below, following codes are sourced from "example.com" as assumed: <a href="http://www.example.org" target="vo1" onclick="gp(1)" rel="nofollow">Click Me</a> Upon clicking on ...

Connect your HTML page to your CHtml page

Can anyone guide me on how to link a button in an HTML page to a chtml page within an ASP MVC project? image description here ...

How can I dynamically generate multiple Reactive Forms from an array of names using ngFor in Angular?

I am in the process of developing an ID lookup form using Angular. My goal is to generate multiple formGroups within the same HTML file based on an array of values I have, all while keeping my code DRY (Don't Repeat Yourself). Each formGroup will be l ...

Unsure why the React button is disappearing specifically on Safari iOS. Any thoughts on how CSS

Hey there! I created a small hamburger button for my website, but for some reason, it doesn't show up on Safari iOS. Interestingly, it works perfectly fine on Windows Chrome, Windows Firefox, and my Android device. I've been trying to troubleshoo ...

What is the method to adjust the time of print's font size?

When trying to print a datatable using the following JavaScript code: <script type="text/javascript"> function data(divName) { var printContents = document.getElementById(divName).innerHTML; var originalContents = document.body.innerHTML ...

Unable to vertically align an image within a navigation bar item that is not the brand

Having a unique issue for which I cannot find a solution. In the navbar of Bootstrap 4, I am attempting to include an image next to one of the items, not the navbar-brand as commonly asked about. When Bootstrap 4 is loaded with a custom alpha dark theme, ...

Update the image source within a CSS element

I'm facing an issue with changing the source image of an Element. The situation is that I have a customized CSS script and I need to modify a logo image. Below, you can find the source code: https://i.stack.imgur.com/8HLCE.png The problem lies in at ...

Ways to prevent a floated element from impacting text-align: center styling?

Within my code, there is a <p> element structured as follows: <div><p>Text Goes Here <span></span</p></div> The CSS I currently have is: div { text-align:center } span { float:right } An issue arises when I populate ...

Curious as to why body.scrollTop functions differently in Google Chrome and Firefox compared to Microsoft Edge

Up until recently, the code body.scrollTop was functioning correctly in my Chrome browser. However, I've noticed that now it is returning 0 in both Firefox and Chrome, but still giving the proper value in Microsoft Edge. Is there anyone who can assis ...

Is it possible for webkit CSS resize to not function properly when applied to a canvas element that is

Consider this HTML and CSS code snippet: #box { width: 100px; height: 100px; overflow: hidden; resize: both; border: 1px solid black; } #content { width: 100%; height: 100%; } <div id="box"> <canvas id="content"> ...

Maintain the same javascript variable throughout multiple pages

I am working on a project that involves utilizing a database along with 2 drop down menus. Through the use of JavaScript, I am able to capture the value selected from the drop down menus and then pass it on to my PHP script. The PHP script retrieves releva ...

Creating a Canvas Viewport Tailored for Multiplayer Gaming

Lately, I've been playing around with the HTML5 Canvas while working on an io game. However, I've hit a roadblock when it comes to handling the viewport. Setting up the viewport itself isn't too complicated, but accurately displaying other p ...

JavaScript Slide Show using setInterval()

Need some help with JavaScript! I have a slide and I want to add a button to either make it autoplay or stop it. When I just use an Alert inside the function, it works, but when I add the interval code, it won't. Check out my codepen link Here is the ...

Ways to resolve the issue of forms causing button overlap

I've implemented the following code in my project: <div class="table-responsive"> <table class="table align-items-center table-flush"> <thead class="thead-light"> <tr> ...

ajax and codeigniter combination for selecting options

Is it possible to implement a set_select option within an AJAX component for a dynamic dependent dropdown list that is being cleared after validation errors? I am looking to incorporate the set_select functionality in the code snippet below: <script ty ...