Ignore the initial children of the highest level divs exclusively

Is there a way to apply a style to all top-level divs within a div, excluding the first one? I have tried using not(:first-child) but it seems to be recursive. How can this be achieved?

<div class='want-to-skip-first-a'>
    <div class='a'>
        <div>1</div>
        <div>2</div>
    </div>
    <div class='a'>
        <div>3</div>
        <div>4</div>
    </div>
    <div class='a'>
        <div>5</div>
        <div>6</div>
    </div>
</div>

.want-to-skip-first-a div:not(:first-child) {
    border-top: solid red 11px;
}

Jfiddle: http://jsfiddle.net/GrAaA/85/

Thank you!

Answer №1

When targeting div elements with the "a" class, excluding the first one for styling purposes, a slight adjustment in your CSS will do.

.omit-first-a .a:not(:first-child) {
  background-color: red;
}

Answer №2

If you follow j08691's suggestion, you can simply utilize the direct child selector (>) like this:

.want-to-skip-first-a>div:not(:first-child) {
  border-top: solid red 11px;
}
<div class='want-to-skip-first-a'>
  <div class='a'>
    <div>1</div>
    <div>2</div>
  </div>
  <div class='a'>
    <div>3</div>
    <div>4</div>
  </div>
  <div class='a'>
    <div>5</div>
    <div>6</div>
  </div>
</div>

Alternatively, you can use the "sibling" selector (+):

.want-to-skip-first-a .a + .a{
  border-top:11px solid red;
  }
<div class='want-to-skip-first-a'>
    <div class='a'>
        <div>1</div>
        <div>2</div>
    </div>
    <div class='a'>
        <div>3</div>
        <div>4</div>
    </div>
    <div class='a'>
        <div>5</div>
        <div>6</div>
    </div>
</div>

It might also be useful to specify the class name on the div element for your CSS to work correctly:

.want-to-skip-first-a div.a:not(:first-child) {
  border-top: solid red 11px;
}
<div class='want-to-skip-first-a'>
  <div class='a'>
    <div>1</div>
    <div>2</div>
  </div>
  <div class='a'>
    <div>3</div>
    <div>4</div>
  </div>
  <div class='a'>
    <div>5</div>
    <div>6</div>
  </div>
</div>

Feel free to choose any of these methods to achieve your desired outcome.

Answer №3

Don't overcomplicate things, it's simple. All you have to do is assign a class to the div elements where you want specific CSS properties. In this scenario, there are 6 elements and you just need to add the class to all except the first one.

<div>
   <div >1</div>
   <div class='want-to-skip-first-a'>2</div>
   <div class='want-to-skip-first-a'>3</div>
   <div class='want-to-skip-first-a'>4</div>
   <div class='want-to-skip-first-a'>5</div>
   <div class='want-to-skip-first-a'>6</div>
</div>

Check out the solution here

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

Tips for arranging Radio buttons in multiple columns within the same Radio group in Material UI

As a newcomer in the world of React.js, I am feeling a bit anxious about posting my question on Stack Overflow. I hope everyone can overlook my lack of experience and forgive me for any mistakes. I have been struggling to find the right solution to my prob ...

Ensure that the view remains consistent while navigating a table that contains expanding concealed information

My table is dynamically populated with data within a div that has overflow: scroll and height set properties. The issue I face is that the data populates from the top, making it difficult to keep track of specific rows when scrolling within the #container ...

Add an arrow or triangle at the tip of the line

I am currently working on recreating the design of lines with an arrow or triangle at the end side of an Input form. The inspiration for this comes from an old flash application that is now being converted to HTML5: https://i.sstatic.net/OCpif.jpg So far, ...

Is there a way to specify the dimensions of the canvas in my image editing software based on the user-input

Here is the code and link for my unique image editor. I would like to allow users to enter the desired width and height of the selection area. For example, if a user enters a width of 300 and height of 200, the selection size will adjust accordingly. Addit ...

"Transforming a static navbar to a fixed position causes the page to jump

Having some difficulty figuring this out. I'm working on a bootstrap navbar that transitions from static to fixed when the user scrolls past the logo at the top. Everything seems to be working fine, except for when the navbar reaches the top, it sudde ...

Utilize page variables to activate audio clips upon clicking

Can someone assist me with a script that activates an audio clip when five icons on a page are clicked? The image of the icons can be found below: https://i.stack.imgur.com/mBC6o.png Here is the HTML code: <div class="slide overlay-container" id="int ...

Setting the height of a child tag: A step-by-step guide

When trying to set the height of a child tag to 100%, I encountered an issue where the height would remain fixed after redirecting to another page, preventing the page from scrolling. Styling for Image 1 body{ background: url("Resources/Cash.jpeg&q ...

What is the best way to modify React state?

Can someone help me troubleshoot an issue with toggling React state after a button click? I want to be able to change "Work From Office" to "Work From Home" and vice versa, but it's only working once. Is there a way to achieve this using an if stateme ...

Modifying the href attribute of links within various occurrences of an element using jQuery based on its content

Here is an illustration of a recurring element on a webpage <td class=" market all"> <a href="linktosomesite?param=123" target="_blank">123</a> </td> Similar elements change the parameter, resulting in links like: <td clas ...

Is there a conflict between bootstrap.min.JS and chart.min.js?

I have been working on developing an admin page for customer support and I recently added a visually appealing chart to display some data on the home screen. The chart integration was successful, but when I introduced tab panes to the page and refreshed ...

Streamlining all icons to a single downward rotation

I am currently managing a large table of "auditpoints", some of which are designated as "automated". When an auditpoint is automated, it is marked with a gear icon in the row. However, each row also receives two other icons: a pencil and a toggle button. W ...

Utilizing jQuery to dynamically add or remove a class based on the selected radio button option

I am trying to achieve a functionality where checking one radio button will add a class to the label of another radio button, and unchecking it will remove that class. I have provided a Plunker example here. It seems simple but I'm having trouble gett ...

Tips for altering value by selecting radio buttons

Currently, I am in the process of developing a website using Adobe Dreamweaver with php. The site includes three buttons that serve as payment method options and act as continue buttons. My goal is to have the selected radio button (I agree button) add a s ...

Step-by-step guide on crafting a harmonious row of a label and a responsive button group

One of my projects involves a form that contains a list of elements. I want this form to be responsive and suitable for all screen sizes. When I initially run the project on a larger screen, everything looks good. However, when I resize the screen to a sma ...

Establishing the initial value for an input file form

Similar Question: Dynamically set value of a file input I'm currently working with an HTML form that includes a file input field, and I'm attempting to set the initial value for the file path in the form. I've tried changing the "value" ...

Differences in typography across Mozilla Firefox and Internet Explorer

I have come across a question that seems quite common, yet unsolvable. However, I will give it a try anyway. Take a look at this image: To view a larger version of the image, visit the following URL: https://i.stack.imgur.com/dddNm.jpg HTML code: <d ...

Obtaining the node generated from a document fragment

Suppose I add a document fragment to the DOM in the following way: const ul = document.querySelector("ul"); const fruits = ["Apple", "Orange", "Banana", "Melon"]; const fragment = new DocumentFragment(); ...

Organizing your thoughts: Utilizing Etherpad-Lite's list

Looking to stylize the list items with decimal, upper-alpha, lower-alpha, upper-roman, and lower-roman for each of the first five levels? I attempted to achieve this by adding CSS in my pad.css file. .list-number1 li:before { content: counter(first)") " ...

Is there a way to position two forms next to each other in alignment?

I would like to display two forms side by side. Currently, I have one form shown here: http://gyazo.com/093efe95337ace40fe633adb88b76c2d. I want the same form to be displayed on the right-hand side as well. .comments-section .comment-form { padding: 20p ...

What's the best way to prevent extra spacing when typing in a materialUI TextField?

Instructions for the user: Please input your first name without any spaces between characters. I attempted to implement the following code, however, it did not achieve the desired outcome. <TextField required id="name" label="First Name" ...