Utilize CSS selector to modify the class of every second pair of div elements

I attempted to utilize CSS to target a group of divs in pairs of 2 with an interval of 2.

For example:

I have AA AA AA AA AA AA but I need to apply different styles to every 2 elements (where A and B represent DIVs):

AA BB AA BB AA BB

I have tried the following code snippet without success:

&:nth-child(3n+3)

Can anyone provide guidance on how to achieve this?

Answer №1

It seems like you're looking to achieve this using 2 rules

div {
    display: inline-block;
}
div:nth-child(4n+3),
div:nth-child(4n+4) {
    color: red;
}
<div>A</div><div>A</div>
<div>A</div><div>A</div>
<div>A</div><div>A</div>
<div>A</div><div>A</div>
<div>A</div><div>A</div>
<div>A</div><div>A</div>

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

What causes the discrepancy in smoothness between the JavaScript animation when offline versus its choppiness when online, particularly on AWS

Recently I delved into game development using HTML5/CSS/JS and embarked on a small project. Check out the game here at this AWS storage link: If you open the game and press SPACE, you'll notice that the ball starts moving with occasional brief pauses ...

REACT: Implement a feature to add a distinctive border around the currently selected image

When selecting a picture, I would like to have a border around it. Specifically, if out of 6 pictures I choose 3, I want highlighted borders around those selected images. How can this be achieved? EDIT: I am utilizing React to address this issue. ...

Why isn't anything happening with the .class element?

I've been diving into the world of CSS and stumbled upon something that's left me puzzled. Here is a snippet of HTML code: <ul class="weblist"> <li>Coffee Brur</li> <li>Taco Finder</li> <li>CSS Se ...

What is a better method for aligning an image in the middle of a floated container?

Is there a better way to center an image within a floated div without using an extra p tag? I currently have the image inside a p tag and center the p, but it annoys me having that extra tag. Any suggestions on how to center the image itself? Thanks! Below ...

Positioning my login form in the right spot is proving to be a challenge

I'm working on integrating this form into my website, but I'm having trouble placing it in the top right corner of the header. Below is the HTML code: $(function(){ var $form_inputs = $('form input'); var $rainbow_and_b ...

Sending JavaScript variables to an external CSS file

I've been searching for a solution without much luck. I must admit, my CSS skills are pretty basic. Currently, I am using Muxy.io to manage notifications for my livestreams. The platform allows customization of notifications through HTML and CSS file ...

There was an error in calculating the Foundation 5 - 1170 grid

Currently, I am in the process of learning Foundation 5 and working on an app that utilizes a 1170 grid system. The app has 70px columns and 30px gutters (which equals to 1170 when calculated as 70 * 12 + 30 * 11). However, after setting the default values ...

Update the page using Ajax without relying on jQuery

I want to implement automatic page updates without the need for a refresh using Ajax. However, most resources I've come across suggest using jQuery and PHP, which are areas of coding I am not very familiar with. My goal is to integrate Ajax into my HT ...

Optimize HTML outputs in Smarty by reducing the file size

Is there a way to minify all output HTML templates in Smarty automatically? Would it be possible to set something like this: $smarty->minify = true; Additionally, I have come across the {strip} function but using it in every single .tpl file is not fe ...

Can content projection be utilized from a child component in Angular?

Keep in mind, this example could be achieved without using content projection. I am just showing a simplified version here. Imagine having a component that displays lists of names in two separate elements: import { Component } from '@angular/core&ap ...

The combination of HTML div elements, table structure, and CSS

I'm struggling to develop a table using DIV tags and CSS. I find it puzzling that all rows have the same width on a small screen, but not on a larger screen. Html code: <div class="rTable"> <div class="rTableRow"> <div class="rTab ...

Erase embedded frame from a Google Sheets document

Is there a way for me to customize the frame and replace it with my own design? Click here to view the Google Sheet embedded frame ...

Transparency of Iframe in Internet Explorer

I came across a tutorial on this website explaining how to enable iframe transparency in IE, but unfortunately it is not working for me. I have attempted setting the background to transparent and allowing transparency to be true... However, the background ...

Send the td value to a PHP script with the help of JavaScript

I have an HTML table that displays records from a database. Below is a screenshot of my table There is a button in a TD (i.e column 5,7,9), when I click the button I want to perform a function to display a popup box with an HTML table. Before that, I wa ...

Altering the display attribute cancels out any opacity transitions

When using JavaScript to change the opacity of an element with transition: opacity 1s, the expected duration of one second is met, as demonstrated here: onload = e => { var p = document.getElementsByTagName("p")[0]; p.style.opacity = 1; }; p { ...

Troubleshooting Problem with Django and Bootstrap Styling

Currently, I am following some introductory Django tutorials to create a basic polling website. I have managed to get everything functioning properly, but I am struggling with the formatting on the "results" page for the polls. Here is how the page appear ...

Utilizing RSelenium for accessing a website built using the <td> element

My supervisor has tasked me with retrieving data from the China in-depth accident study database. Given my limited experience with HTML and javascript, I decided to utilize RSelenium and phantomjs to assist me in completing this task. Although I was able ...

What are the conditionals and operations that need to be underscored in this template?

I am new to working with underscore and I need help writing an "each" function for posts where only the latest post is displayed. I understand the basic logic which looks like this <% _.each(posts, function(post, index) { %> <% if(index % 3 == 0 ...

Styling with CSS in a React component

I am trying to display a row of buttons instead of columns on my webpage. I have used display:flex but it is still showing as a column. What I want is for each button to display the first character of its name underneath it, with all buttons lined up next ...

Coordinating the vertical scrolling of two div elements simultaneously. (scrolling both divs together)

I have a specific setup where I have a text box that is scrollable, and outside of this box are headings that correspond to different sections in the text. I am looking for a way to synchronize the scrolling of the text inside the box with the headings out ...