Targeting all children instead of just the odd ones when using `nth-child(odd)`

In the portfolio, I have a unique requirement where every odd entry should be reversed. These projects are generated dynamically from an array and passed into the component through props.

To style it, I'm utilizing styled-components.

However, I'm encountering an issue with nth-child where setting it to odd or even affects all of the projects. When set to odd, none of them are reversed, but when set to even, all of them are. What am I overlooking here?

https://i.stack.imgur.com/FSYiN.png

Answer №1

<SummaryContainer/> is facing issues with mapping. It seems like the mapping is not happening as expected when running on the entire Project component. This may be why nth-child is not functioning properly. A simpler solution would be:

Step 1: Provide index as a prop to the Project Component.

Step 2: Apply styles to dynamically add rows based on odd or even logic

<JobContainer style={{ flexDirection: props.index % 2 ? 'row' : 'row-reverse' }}>

</JobContainer>

Step 3: In the <JobContainer /> component, use the passed style as prop.style

Following these steps should resolve the issue you are experiencing.

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

Creating a Product Box design with CSS and incorporating visual elements

I have created a simple box design in Photoshop that I want to use to display product information. The box consists of a Header, Body, and Button, each as separate images. How can I assemble these elements using CSS/HTML? I only need the header text at th ...

How can I move a TableItem from one material UI component to another using drag-and-drop?

I am facing an issue where I need to drag a ListItem from one List component to another. I am uncertain about how to accomplish this in Material UI. ...

Error: The classes prop in ForwardRef(TablePagination) does not recognize the key `caption` that was provided

After adding a basic DataGrid to my component, the following code snippet was used: <div className='Employees'> <Button onClick={queryEmployees}>Employees</Button> <DataGrid rows={rows} columns={columns} autoHeigh ...

How to ensure that a div element occupies the entire height of the webpage

After developing a small app in Angular, I'm looking to make the container element expand to the full height of the page, even when the content doesn't fill the entire space. On larger screens, the page doesn't stretch as desired. Here' ...

Unable to generate a navigation panel using HTML/CSS and jQuery

I recently completed the basic courses in HTML/CSS, JavaScript, jQuery, and PHP on Codecademy. I'm currently working on creating a website using HTML/CSS and jQuery in Codecademy's codebits. However, I'm facing some issues with my navigation ...

Attempting to modify the array content using useState, but unfortunately, it is not functioning as expected

Starting out with react.js and trying to update an array's content using useState upon clicking a send-button, but it's not working as expected. Struggling with adding date and number in the row. Check image here Here's what I'm aiming ...

Creating a custom color palette with Material UI using ThemeProvider

Attempting to set a custom color for a Button using createMuiTheme and ThemeProvider has been successful with the primary and secondary palettes. However, when trying to utilize an alternate color such as "info", it does not seem to work as expected: http ...

Enhance Animation Fluidity with HTML/CSS

I am experimenting with creating a floating animation for my iceberg logo by adjusting the top margin. Below is the CSS code I have implemented: img { height: 60px; padding: 5px; -webkit-animation: logofloat 1s ease-in-out infinite alternate; -moz ...

Hide bootstrap card on smaller screens such as sm and md

Utilizing the Bootstrap 4.1 card component, I showcase categories within the right sidebar - check out a sample image of the card here: Card example image; When viewing on smaller screens, it's preferable to collapse this large card as shown in this ...

How to target the nth child element uniquely in CSS

Is there a way to style items 1 through 10 in CSS without using nth-child selectors individually? Instead of doing: &.nth-child(1) { //style } &.nth-child(2) { //style } &.nth-child(3) { //style } I'm looking for a range selector in C ...

Is it not feasible to place a well within a column using Bootstrap?

Would like to place a .well div (or a button, whichever works best) within the designated green area shown in this image: here Here is the code I currently have: <div class="container-fluid"> <div class="row row1" style=&q ...

Tips for expanding button width in 'react-native-swipeout' to enable swipe action on ListView row (React Native)

Currently, I am exploring how to implement the component found here: https://github.com/dancormier/react-native-swipeout My goal is to have the row swiped all the way. Is there a method to increase the button width so that it covers the entire width of th ...

I'm looking to implement a feature in my notes application built with the MERN stack using Mongoose for MongoDB that allows users to add hidden notes. How

I am looking to implement a hidden notes functionality in my web application. When the "hide note" button is clicked, I want the note to be removed from its current location and added to a hidden notes section. Users should then have the ability to view an ...

Start building your React application with the command `npx create-react-app react-task-tracker`

When attempting to create a new react app, an error message is popping up. What might be causing this issue? ...

How can jQuery determine the amount of line breaks within a div element?

My div wrap size is a percentage of the screen width, containing multiple .item divs that break into new lines as the window size decreases. I attempted to calculate the total number of boxes that could fit based on their widths compared to the container ...

Attempting to initiate the React App on PORT 3000 is the initial step in the process

I am currently facing an issue with running two react apps using pm2. One of the apps is successfully running on port 3000, but when I try to run the second app, it fails. Even though I have specified the port number as 3001 in the package.json file, I st ...

Precise loading display in React using splines

When utilizing next.js to render a spline model, I have encountered an issue where the "onLoad" function does not accurately reflect the loading time. import Spline from '@splinetool/react-spline'; import { useState } fr ...

Implementing functions on React component classes

Recently, I decided to convert a slideshow from w3s schools into a React component. The process involved changing all the functions into methods on the class and setting the initial state to display the first slide. However, upon clicking the buttons or do ...

Conceal and reveal elements using a specific identifier with

Web Development Guide <ul id="menüü"> <li id="meist"> <p><a href="meist.html">Meist</a></p> </li> </ul> <div id="submenu"> <ul id="submeist"> ...

Positioning a div relative to another div using the pos:fixed attribute

Is there a way to make a fixed position div relative to its parent div instead of the window using only CSS? I want a sticky block that follows the content while scrolling with the page, and stays in place even when the window is resized. I know this can ...