Struggling to understand how React js interacts with CSS files

While reviewing a React JS project, I came across some confusing CSS classes in the file. Classes like '.cards__item', '.cards__item__pic-wrap', and '.cards__item__img' were being referenced, but they weren't present in the JavaScript code. Thinking it was unnecessary, I deleted the code only to find out that it actually had a significant impact on the webpage. So, the code does serve a purpose.

I've been stuck on this for a while now. Can someone please explain what's going on here? Any help would be greatly appreciated.

JavaScript File:

import React from 'react';
import './Cards.css';
import CardItem from './CardItem';

const Cards= () => {
  return (
    <div className='cards'>
      <h1>Check out these EPIC Destinations!</h1>
      <div className='cards__container'>
        <div className='cards__wrapper'>
          <ul className='cards__items'>
            <CardItem
              src='images/img-9.jpg'
              text='Explore the hidden waterfall deep inside the Amazon Jungle'
              label='Adventure'
              path='/services'
            />
            <CardItem
              src='images/img-2.jpg'
              text='Travel through the Islands of Bali in a Private Cruise'
              label='Luxury'
              path='/services'
            />
          </ul>
          <ul className='cards__items'>
            <CardItem
              src='images/img-3.jpg'
              text='Set Sail in the Atlantic Ocean visiting Uncharted Waters'
              label='Mystery'
              path='/services'
            />
            <CardItem
              src='images/img-4.jpg'
              text='Experience Football on Top of the Himilayan Mountains'
              label='Adventure'
              path='/products'
            />
            <CardItem
              src='images/img-8.jpg'
              text='Ride through the Sahara Desert on a guided camel tour'
              label='Adrenaline'
              path='/sign-up'
            />
          </ul>
        </div>
      </div>
    </div>
  );
}

export default Cards;

CSS File:

.cards {
  padding: 3rem;
  background: #fff;
}

h1 {
  text-align: center;
}

.cards__container {
  display: flex;
  flex-flow: column;
  align-items: center;
  max-width: 1120px;
  width: 90%;
  margin: 0 auto;
}

.cards__wrapper {
  position: relative;
  margin: 50px 0 45px;
}

.cards__items {
  margin-bottom: 24px;
}
______________________________________________________________________

.cards__item {
  display: flex;
  flex: 1;
  margin: 0 1rem;
  border-radius: 10px;
}

.cards__item__link {
  display: flex;
  flex-flow: column;
  width: 100%;
  box-shadow: 0 6px 20px rgba(56, 125, 255, 0.17);
  -webkit-filter: drop-shadow(0 6px 20px rgba(56, 125, 255, 0.017));
  filter: drop-shadow(0 6px 20px rgba(56, 125, 255, 0.017));
  border-radius: 10px;
  overflow: hidden;
  text-decoration: none;
}

.cards__item__pic-wrap {
  position: relative;
  width: 100%;
  padding-top: 67%;
  overflow: hidden;
}


.cards__item__pic-wrap::after {
  content: attr(data-category);
  position: absolute;
  bottom: 0;
  margin-left: 10px;
  padding: 6px 8px;
  max-width: calc((100%) - 60px);
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  background-color: #1f98f4;
  box-sizing: border-box;
}

.cards__item__img {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  display: block;
  width: 100%;
  max-width: 100%;
  height: 100%;
  max-height: 100%;
  object-fit: cover;
  transition: all 0.2s linear;
}

.cards__item__img:hover {
  transform: scale(1.1);
}

.cards__item__info {
  padding: 20px 30px 30px;
}

.cards__item__text {
  color: #252e48;
  font-size: 18px;
  line-height: 24px;
}

@media only screen and (min-width: 1200px) {
  .content__blog__container {
    width: 84%;
  }
}

@media only screen and (min-width: 1024px) {
  .cards__items {
    display: flex;
  }
}

@media only screen and (max-width: 1024px) {
  .cards__item {
    margin-bottom: 2rem;
  }
}

li {
  list-style: none;
}

Answer №1

<CardItem /> represents a React component that has been imported on line 3 using the code

import CardItem from './CardItem';

It is likely that the CSS classes mentioned are being used within this particular component. You may want to inspect the code of this component for further details.

Answer №2

Were you able to examine the code for the CardItems component? It is possible that the classes are dynamically added by the component code before or after the component has been rendered.

Furthermore, it appears that these classes may not be actively used, but upon closer inspection, many of them appear to be sub-classes of the .cards-item class. This suggests that some sort of UI framework is in use, and the individual you mentioned may have removed and customized framework style classes for a specific purpose.

Front end frameworks typically initialize once an application has been [bootstrapped][1], and they may handle certain elements differently behind-the-scenes, unbeknownst to the developer. Refer to the higher order components to understand their functionality.

A reliable method to investigate this further is to observe the application when idle (i.e., the web server is running and the app is loaded, awaiting user interaction) and launch the standard developer tools console by right-clicking on the misbehaving elements.

In the elements tab of the developer console, you can view the applied classes for each element.

https://i.sstatic.net/G2hsd.png

This will help identify which elements are impacted and which classes are active.

An alternative approach, without manual examination of the markup, is executing vanilla JavaScript within the developer console.

To begin, open the browser's console tools through right-click inspect, navigate to the console tab, and click within the white space. Type a command like the following:

document.querySelectorAll('.cards__item__link');

This will produce an array list of element node objects. In the image provided, I am browsing a Microsoft website and utilizing the .container-element CSS class.

https://i.sstatic.net/VxSFD.jpg

Element nodes represent the essence of a markup element, detailing its contents and capabilities. Click on one of the nodes to reveal its properties and methods. Look specifically for the classList property and review its content.

Another command yielding identical results, displaying the markup instead of nodes in the built-in JavaScript console, is as follows:

document.getElementsByClass('cards__item__link');

https://i.sstatic.net/WFLUq.png

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

How is Material-UI handling the breaking change in React 15.4.0 regarding the error message "Module 'react/lib/EventPluginHub' cannot be resolved"?

Today, React version 15.4.0 was released which included a change that has caused an issue with react-tap-event-plugin version 1.0.0 resulting in the following error message: $ npm build > <a href="/cdn-cgi/l/email-protection" class="__cf_email__" da ...

How to display specific JSON objects that meet particular criteria in HTML cards using Ionic and Angular?

As a beginner in Ionic/Angular, I am attempting to fetch data from a JSON file and display it using cards in the HTML. The JSON contains numerous objects that are either marked as "deTurno == true" or "deTurno == false". Here is what I have so far: publi ...

What is the most effective way to add HTML from a dynamically loaded document using AJAX?

I am attempting to attach the information from a .html file to the body of my main webpage. Essentially, I am striving to create a reusable section of html that can be loaded into any page with a basic JavaScript function. Below is the content of my navig ...

What methods can I use to get my kahoot botter to produce unpredictable answers?

After attempting to create a kahoot botter using the updated kahoot.js library, I came across this code snippet that supposedly answers random questions: const Kahoot = require("kahoot.js-updated"); var kahoots = [] for (var i = 0; i < bot_cou ...

Combining two arrays containing objects in JavaScript

Imagine having 2 arrays of objects that you want to merge in a parallel manner. For instance var array = [{foo: 2} , {boo: 3}] var array2 = [{foo2: 2}, {boo2: 4}] The outcome would be var array3 = [{foo:2,foo2:2},{boo:3,boo2:4}] In what way can this be ...

Using a combination of Redux and styled components can cause issues with the activeClassName feature in React Router's

I recently completed a project using react, redux sagas, and styled components. One issue I encountered was trying to create a navigation menu using NavLink and styling the active link item with a different color. Here is the code snippet I used: const Me ...

Troubleshooting ng-bind-html issue with displaying images loaded using CSS within HTML content

I followed the instructions provided in a related post on the same topic. I used 'ngSanitize' and formatted the HTML content using 'sce.trustAsHtml()', and it rendered correctly when the HTML contained both text and images. However, I e ...

What is preventing my for loop from reaching the initial index in this visually distinct nested array pattern?

Struggling with rearranging letters in a W shape using arrays. My code seemed to go down instead of reaching level 0. Code snippet: const row = totalLevel =>{ let array = [] for(let i =0;i<totalLevel;i++){ array.push([]) } r ...

Tips for achieving a gradual transformation of an element according to the scrolling position

I have been experimenting with using waypoints for two specific purposes. The first objective is to determine whether a user is scrolling up or down and if the container comes into view. However, this functionality is not working as expected. The sec ...

Using React and TypeScript to enable file uploads

Seeking assistance in creating a basic single select upload component. When I click a button that contains a hidden input field, the file dialog opens and allows me to choose a file. The placeholder then changes to display the selected file name along with ...

The image is not aligning properly within the navigation bar

I had some queries in mind: 1) How can I ensure that the circular profile image on the rightmost side fits within the header without overflowing? 2) How do I properly align the last three images at the bottom (in the "R" class), with adequate spacing bet ...

Addressing React Native Rendering Problems

I'm currently working on a weather application and facing some challenges with rendering the forecast. I'm uncertain whether it's related to the styling. I've tested the API call through the browser and encountered no errors in Android ...

Gulp: executing a task with no specified output location

I am attempting to create a straightforward task to display the file size for each file in an array of paths using the gulp-size plugin, as shown below: var gulp = require('gulp') var size = require('gulp-size') gulp.task('size&a ...

Assign a background image to a master page utilized in subdirectories

In my website's root directory, I have a master page. Inside this root directory, there is a folder named Images which contains the background image for my master page. When I apply this master page to web pages located in the root directory, everythi ...

What is the best way to monitor a Vue instance property within a component?

I recently implemented a plugin that introduces a new property to the Vue instance. This property can then be accessed within components using this.$plugin.prop. However, I am encountering difficulty in watching for changes to this property. I need to perf ...

Issue: The "props" method is designed to be executed on a single node, but it was found on 2 nodes instead

it('should execute setCampaignDate when clicked', function () { let spySetCampaign = sinon.spy(wrapper.instance(), 'setCampaignDate'); let datePickers = wrapper.find('.campaign-date-tab').dive().find(Datepicker); a ...

What steps should I take to create code that can generate a JWT token for user authentication and authorization?

I'm struggling to get this working. I have a dilemma with two files: permissionCtrl.js and tokenCtrl.js. My tech stack includes nJWT, Node.js/Express.js, Sequelize & Postgres. The permission file contains a function called hasPermission that is linke ...

What could be the reason for React Js default page not loading when initiating the command npm start?

When attempting to run my react project using the command below: G:\Node.js> cd reactproject G:\Node.js\reactproject> npm start I encountered the following error: Starting the development server... events.js:167 throw er; // Unhandl ...

What is the process for defining the type of the context for an Apollo resolver?

I am facing an issue with my Apollo GraphQL subgraph where I need to define the type for the context argument in my resolvers. When creating a resolver, I tried setting the context type like this: interface Context { dataSources: { shopify: Shopify; ...

Is it possible to receive both errors and warnings for the same ESLint rule?

My team is currently in the process of refactoring our codebase, utilizing ESLint to pinpoint any lint errors within our files. Initially, we set high thresholds in one .eslintrc file and have been gradually decreasing these limits as we enhance specific f ...