Troubleshooting: Border not showing up in Tailwind CSS (React JS)

Below is the code snippet from my JSX file:

import { useState, useEffect } from "react";
import { PropTypes } from "prop-types";
import { HashtagIcon } from "@heroicons/react/24/outline";

// Function to fetch categories from the API (temporary replaced with hardcoded values)
const fetchCategories = () => {
  return new Promise((resolve) => {
    setTimeout(() => {
      const categories = [
        { id: 1, name: "Human Resources", icon: "icon" },
        { id: 2, name: "Technological Innovation", icon: "icon" },
        { id: 3, name: "Marketing Strategies", icon: "icon" },
        // More category objects...
      ];
      resolve(categories);
    }, 1000);
  });
};

function CategoryList({ onCategorySelect }) {
  const [categoryList, setCategoryList] = useState([]);

  useEffect(() => {
    // Load categories on component mount
    fetchCategories().then((categories) => {
      setCategoryList(categories);
    });
  }, []);

  function handleCategorySelect(categoryId) {
    // Function to filter ideas based on selected category
    onCategorySelect(categoryId);
  }

  return (
    <div className="flex flex-wrap">
      {categoryList.map((category) => (
        <div
          key={category.id}
          className="flex items-center justify-center w-1/3 md:w-1/4 lg:w-1/6 p-1 md:p-2 cursor-pointer"
          onClick={() => handleCategorySelect(category.id)}
          onKeyDown={(e) => {
            if (e.key === "Enter" || e.key === " ") {
              handleCategorySelect(category.id);
            }
          }}
          role="button"
          tabIndex={0}
        >
          <div className="flex flex-col items-center bg-orange-500 rounded-lg h-20 border-2 border-gray-700">
            <div className="flex items-center justify-center h-12 w-12 bg-indigo-200 rounded-full mb-2 mt-1">
              <HashtagIcon className="h-5 w-6" />
            </div>
            <div className="text-xs font-sans font-semibold truncate w-20 text-center">
              <span className="ml-1">{category.name}</span>
            </div>
          </div>
        </div>
      ))}
    </div>
  );
}

CategoryList.propTypes = {
  onCategorySelect: PropTypes.func.isRequired, // Callback function for category selection
};

export default CategoryList;

Issue: The borders are not showing in the specific line. Even after trying different div classNames, the borders still do not appear. I have tested it on a codesandbox file and the borders work fine there. I suspect it could be related to the functions used in my code, but I'm unsure of the exact cause.

I experimented with applying borders to other div classNames, but faced the same issue of borders not appearing. Therefore, I decided to test it out on a codesandbox file where the borders worked perfectly. I believe the problem might be due to the complexity of my functions, but I am unable to pinpoint the exact reason behind this issue.

Answer â„–1

I have a quick fix for this issue. Simply duplicate the CSS code I'm proposing

border-solid border (border-*color*-*number*)
, and you should see the border display properly (for some reason, it seems we need to specify it twice in Tailwind).

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 implementing Material-UI components in a .ts file

I am currently working on some .ts files for mocks, and I have a question about inserting MUI elements such as the Facebook icon. export const links: Link[] = [ { url: "https://uk-ua.facebook.com/", **icon: <Facebook fontSize ...

What could be causing the inability of Firefox4 to render the background color of the li element?

Is there a way to apply a background color to a forced inline element? I am having issues with displaying the background color in Firefox4, while it works fine in IE7. Can someone help me understand why this is happening and how to fix it? You can view th ...

What steps can be taken to display a backup URL in case the JSON data is undefined?

const DisplaySearchResults = ({ artists }) => ( <div className="search-results"> {artists.map(val => ( <a href="# " key={uniqid()}> <h3>{val.name}</h3> <img className="box-img" ...

Clickable links and compliant W3C coding

Recently, I have encountered errors in the W3C validator due to the presence of "name" attributes in some <a> tags in my document. The validator flagged these attributes as obsolete. I am curious to know when and why this happened? Additionally, I n ...

What is the best way to create a personalized image as the background in WordPress using CSS for a client?

I have this in my style.css .showcase{ background: url("x.jpg") no-repeat 0; } My website is built on WordPress and I have implemented advanced custom fields for the client to edit text. However, I am struggling to find a way for them to change the ...

Fragment errors detected in the Menu Component

I am facing an issue with my code where I am getting an error in the console saying that the Component cannot receive fragments as children. How can I remove the fragments while retaining the logic? Every time I attempt to remove the fragments, I encounter ...

It appears that the home page of next.js is not appearing properly in the Storybook

Currently, I am in the process of setting up my next home page in storybooks for the first time. Following a tutorial, I successfully created my next-app and initialized storybooks. Now, I am stuck at importing my homepage into storybooks. To achieve this, ...

Implementing Micro Frontend Architecture in React Native App

Currently, I am in the process of developing a react-native application that consists of various modules such as: Login Module Payment Cart Product etc. My goal is to implement the Micro Frontend Architecture for each module. Despite researching online, ...

Is it possible to use PHP to add a prefix to every selector in a snippet of CSS code?

Suppose I have a variable named $css that holds some CSS code. My goal is to prepend a specific text to each selector. For instance, consider the following CSS code: #hello, .class{width:1px;height:1px;background-color:#AAA;} div{font-size:1px} input, a, ...

Converting basic CSS to makeStyles for React: A step-by-step guide

Looking to convert basic CSS into makeStyles for React? I've set up some styling on a TextField to allow vertical stretching using the resize attribute. It's currently functioning as expected. Here's the original code that needs some restru ...

Weird State / Unusual Effectiveness with NextJS Links

I'm encountering some unusual behavior in a personal project I'm working on. The project is a recipe website with buttons at the top that lead to different pages querying Firebase for recipe data. In the Index.js file, Firestore queries pass pro ...

Transferring an array of objects from one array to another with the click of a button

I'm facing an issue with moving data between two arrays of objects using buttons in a Nextjs project. The functionality works correctly when selecting a single data item, but it gives unexpected results when selecting multiple items. Although my code ...

Spinning an SVG circle using a group element

I'm interested in rotating an SVG circle without affecting the rotation of other elements. My attempt to rotate the white circle using rotateZ(15deg) resulted in this: This is the progress I've made so far: https://jsfiddle.net/41hrnojs/ <sv ...

Problem concerning the window object in a React functional component

Hey there, I am currently facing a situation where I need to access the window object within my React component in order to retrieve some information from the query string. Here is an excerpt of what my component code looks like: export function MyCompone ...

What is the process for assigning specific tags to specific items within an array?

As I navigate through a list of students, I am encountering an issue with my tag functionality. Currently, when a student adds a tag to their container, it is being added to every student's tags instead of just the intended student. How can I modify t ...

Higher Order Component for JSX element - displaying JSX with wrapped component

I am looking to utilize a ReactJS HOC in order to implement a tooltip around JSX content. The function call should look similar to this: withTooltip(JSX, "very nice") To achieve this, I have created the following function: import React from "re ...

Displaying a div when hovering over it, and keeping it visible until clicked

I want to display a div when hovering over a button. The shown div should be clickable and persistent even if I move the cursor from the button into the shown div. However, it should be hidden when moving out of the entire area. I'm unsure about how ...

Remove the class upon clicking

I recently created a toggle-menu for my website that includes some cool effects on the hamburger menu icon. The issue I am facing is that I added a JavaScript function to add a "close" class when clicking on the menu icon, transforming it into an "X". Whil ...

Tips for shifting a div to the left with AngularJS

I am working with a div structure that looks like the following: <div class="col-xs-1 scroll-button"><i class="glyphicon glyphicon-chevron-left"></i> </div> <div class="customer-ust-bant col-xs-22" id="letters"> <box n ...

Draggable resizing of the Accordion component in React.js using Material-UI

In the visual representation, there are two Accordions—one positioned on the left (30%) and the other on the right (70%). Upon clicking the button, the right accordion disappears, while the one on the left expands to cover the full width (100%). A featu ...