What is the best way to select all the divs with even indexes within a parent div?

Is there a way to style every second div with the class .event-date inside the .upcome-events div differently? I want to give all even-numbered divs with the class .event-date a unique background color compared to the other divs. I attempted to achieve this using the following CSS:

.upcome-events .event-date:nth-child(even) {
    background-color: #000;
}

This is my HTML structure:

                    <div class="upcome-events box">

                        <h4></h4>

                        <div class="event clearfix">
                            <div class="event-date">
                               <h3></h3>
                                <p></p>
                            </div>
                            <div class="event-desc">
                                <p></p>
                                <p></p>
                            </div>
                        </div>

                        <div class="event clearfix">
                            <div class="event-date">
                               <h3></h3>
                                <p></p>
                            </div>
                            <div class="event-desc">
                                <p></p>
                                <p></p>
                            </div>
                        </div>

                        <div class="event clearfix">
                            <div class="event-date">
                               <h3></h3>
                                <p></p>
                            </div>
                            <div class="event-desc">
                                <p></p>
                                <p></p>
                            </div>
                        </div>

                        <div class="event clearfix">
                            <div class="event-date">
                               <h3></h3>
                                <p></p>
                            </div>
                            <div class="event-desc">
                                <p></p>
                                <p></p>
                            </div>
                        </div>


                    </div>

Unfortunately, the above code doesn't seem to be working as expected for me. Any suggestions on how to make it work?

Answer №1

Here is a suggestion:

.upcome-events .event:nth-child(even) .event-date {
    background-color: #000;
}

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

transferring variables to a different php file

I'm looking to transfer values from one page to another. <form action="../PHP/sendemail.php" enctype="multipart/form-data" method="post"> <table class="table" style="margin-bottom: 0"> <tbody> <?php while($ro ...

Incapable of modifying the text within a div container

I am currently working on a script that translates a Russian forum word by word using TreeWalker. However, there is a specific type of div element that I have been unable to change the text for. That leads to my question: How can I go about changing it? Un ...

Improving website performance: removing outdated header contributions and implementing AJAX panel updates

We are developing a Wicket application with heavy use of AJAX, and we've encountered an issue with panels contributing CSS via the renderHead() method. The problem arises when panels are replaced using AJAX functions, such as an AjaxTabbedPanel, as th ...

Utilizing CSS inheritance in React app to style multiple classes simultaneously

My app features two buttons that serve similar functions on different pages. One button directs users to the search page, while the other takes them back to the home page. The challenge I'm facing is that I need the background image for each button t ...

Mastering the art of creating data tables

Currently, I am working on a table that involves phone numbers, subscription status, and groups. However, I have encountered an issue where the incoming date is not aligning properly in my table. It seems to be a simple HTML problem, but I am struggling to ...

Activate the div when hovering over the span

Experiencing an issue with triggering a visible div while hovering over a span. Here is the code structure: <ul class="products"> <li> <a href="somelink"> <img src="some image"> <div class="overlay"> Some Text</div> & ...

Handling overlapping elements with pointer events

Suppose I have two overlapping divs, along with the following jQuery code snippet: $( "#div1" ).click(function() { console.log('click on div1'); }); $( "#div2" ).mousemove(function() { console.log('mousemove on div2'); }); From w ...

Intercepts clicks outside of element borders when heading has a line-height lower than 1

Right after an anchor tag, I have an H1 element. The line-height of the H1 element is set to '0.9' for design purposes. As a result, the computed height of the H1 becomes shorter, but the actual Text element inside overflows and covers part of t ...

Is it possible for Django's trans tags to incorporate HTML tags?

Is it possible for Django trans tags to incorporate HTML tags? For instance, can I use {% trans "Hold <em><strong>Ctrl</strong></em>" %}? Or would I need to use {% trans "Hold" %} <em><strong>{% trans "Ctrl" %}</str ...

Issue with font icons not displaying properly on Firefox

In Firefox, the icon is not displaying in the center, but it works fine in Opera. body { height: 100vh; display: grid; place-items: center; } .link { background-color: red; padding: 3px; display: grid; place-items: center; ...

Difficulty encountered while trying to implement JQuery Typer effect in HTML

I'm new to web development and I'm currently working on my personal website. I've been trying to incorporate a JQuery effect into my site, but I'm facing some difficulties. I came across this code snippet online that supposedly makes it ...

What is the best way to send a string literal as a parameter to a method triggered by a click event

I'm trying to pass a string literal to a method as a click handler. <button (click)="changeLanguage('en')">EN</button> The above code is not working. Any suggestions on how to achieve this? ...

Incantation within ng-include | src involving a series of characters

Is there a way to create a URL in ng-include|src by combining an expression and a constant string? I've attempted the code below, but it doesn't seem to be working. <aside ng-include src="{{staticPath}} + 'assets/tpl/products-feed-histor ...

Adding an iframe with inline script to my Next.js website: A step-by-step guide

For my Next.js project, I have this iframe that needs to be integrated: <iframe class="plot" aria-label="Map" id="datawrapper-chart-${id}" src="https://datawrapper.dwcdn.net/${id}/1/" style="width: ...

What is the best way to incorporate multiple Bootstrap templates into an Angular project without causing conflicts between them?

When incorporating a bootstrap template into the admin interface, it is important to consider that its design may vary from the template used for visitors. Mixing multiple styles based on different templates can lead to conflicting styles and can potenti ...

Trouble encountered when attempting to download PDF using jQuery

I have encountered an issue while trying to download a PDF using Ajax response HTML. Here is the code I am using: var newPDFAction = function () { $.ajax({ type: "post", url: '{{ route("admin.getCustomerSalesRepTota ...

What are the best practices for incorporating an ASP variable into Javascript code?

Trying to incorporate an ASP variable into JavaScript code, but encountering difficulties. How can this be achieved? Any suggestions? <% dim strMyString strMyString = "hello there" %> <HTML> <body> <%=strMyString%> ...

I'm experiencing an issue where the submit button on my HTML form is not successfully recording my information

Welcome and thank you for taking the time to read this. I am facing an issue while setting up a login system. For styling purposes, I had to create two separate forms: one for Email and Password, and another for the submit button. Unfortunately, because ...

Python's Selenium encountering a NoSuchElementException with the error message "./ancestor-or-self::form"

Trying to create a Python script that allows me to input my credentials and tweet text in the Python console. The script should then log in and post a tweet using Selenium. Everything works fine, except for the final click on the Tweet button which is caus ...

Interactive horizontal web design with center alignment and dynamic scrolling feature

We have designed a unique web layout that is centered horizontally and includes an animated scrolling effect. There are 5 menu options that use simple anchor links to navigate between different pages. Our layout features static content with only the body s ...