Building a unique style for ClassName using React

Embarking on my first React project as part of a school assignment has been quite an adventure.

I kicked things off by running npm install -g create-react-app and then created my app with create-react-app my-app.

After adding some HTML to the application, everything worked seamlessly in the browser. Now, I've introduced a button.js file along with a button.css file.

Despite making changes to the button.css file, I'm not able to see any updates reflected. Could it be an issue with the code or am I missing something crucial for the CSS to take effect?

Here's a snippet from src/App.js:

import React, { Component } from "react";
import './App.css';
import Button from './components/Button'; 

class App extends Component {
  render() {
    return (
  <div className="App">
    <div className="calc-wrapper">
      <div className="row">
      <Button>7</Button>
      <Button>8</Button>
      <Button>9</Button>
      <Button>/</Button>
    </div>
</div> 

);
  }
}

export default App;    

In src/compontents/Button.js:

import React, { Component } from "react";
import './Button.css';

class Button extends Component {
  render() {
    return (
      <div className="button">
      {this.props.children}
      </div> 

    );
  }
}

export default Button;

The styles defined in src/components/Button.css are expected to apply to the buttons:

.button {
display: flex;
height: 4em;
flex: 1;
justify-content: center;
align-items: center;
font-weight: lighter;
font-size: 1.4em;
background-color: #e0e1e6;
color:#888;
outline: 1px solid #888;
}

Answer №1

When you used the lowercase button, it was recognized as the standard <button> element rather than your custom <Button> component.

This is how your App.js file should appear.

import React, { Component } from "react";
import "./App.css";
import Button from "./components/Button";

class App extends Component {
  render() {
    return (
      <div className="App">
        <div className="calc-wrapper">
          <div className="row">
            <Button>7</Button>
            <Button>8</Button>
            <Button>9</Button>
            <Button>/</Button>
          </div>
        </div>
      </div>
    );
  }
}

export default App;

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 dynamic background color that pulses with animation

I recently created a script to animate the menu li element when hovering over the corresponding a element. Everything is functioning as expected, but now I'm looking to enhance the effect by having it continue as long as the mouse remains over the a e ...

The styling of divIcons in React Leaflet Material UI is not applied as expected

When using divIcon in React Leaflet to render a custom Material UI marker with a background color prop, I noticed that the background style is not being applied correctly when the marker is displayed in Leaflet. Below you can find the code for the project ...

Retrieve base64 encoded data from several content attributes

Is there a way to optimize the use of base64 data in CSS by defining it once and referencing it in multiple content properties? div#my_id1 { content: url(data:image/png;base64,...); } div#my_id2 { content: url(data:image/png;base64,...); } Using ...

Local React build is successful, but encounters errors when deployed to Amplify

Is there any insight on what could be causing this issue or how to troubleshoot it without having to restart from scratch? I've put in a lot of time working on the API, GraphQL, and CI. This is a standard create-react-app with some minor modification ...

Is there a way to create a dropdown menu that transforms into a burger icon on smaller screens, while still housing all of my navigation items within it?

I'm currently working on a segment of my header that includes a navbar with 3 links, as well as a dropdown menu listing additional functionalities. Here is the current code I have: <div class="col-md-4 pt-4"> <nav class="navbar ...

Using a zoom background image in an HTML document without any accompanying text

I am trying to create a zoom effect on a background image without affecting the text overlaying it. Here is the CSS code: .page1-box { width: 1200px; height:800px; overflow:hidden; } .page1 { width: 100%; height: 100%; background: ...

Troubleshooting a dysfunctional collapsed navbar in React with Bootstrap 5

I am experiencing an issue where the collapsed navbar icon does not expand when clicked on smaller screens. I followed the example provided by bootstrap 5 and made sure to include bootstrap css/js and jquery. class CustomNavBar extends Component { re ...

Having trouble getting the CSS animation to work properly with the text

Update: The direct link is working fine, unlike the rocketscript version. <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> I have been attempting to animate word rotati ...

Unable to properly organize a column within the Ant Design Table on a Gatsby website

I have successfully integrated an Ant Design Table into my Gatsby website, utilizing data from graphql. The display and pagination are functioning perfectly. Now, I am looking to enhance the functionality by enabling column sorting. Below is how I have se ...

Location of a Confirmation Box

When positioning the confirmBox on a page with lots of content using absolute inside relative positioning, I encountered an issue where the confirmBox was centered in the page but not in the center of the screen. Since the confirmBox can be opened through ...

Error: Unable to perform operation on undefined object when trying to map over 'reminder' object

I've been struggling with my reminder-list.tsx file. No matter how many times I try to fix it, I always end up failing. Can someone help me figure out how to resolve this issue? Every time I run the code, I get the TypeError: undefined is not an obje ...

Unable to render information from JSON object using Object.Keys and .map function in ReactJS

I'm facing a challenge in updating my API structure from an array to an object format. I attempted to map the object for use with Bootstrap cards, but encountered issues as it did not display any items. How can I resolve this problem? Below is an exa ...

React-Admin error: Attempting to invoke a built-in Promise constructor without using the new keyword is not allowed

I'm currently facing an issue where I am trying to retrieve data using a hook. Strangely, there are no TypeScript errors appearing, but when I run the code, a console error pops up stating "Uncaught TypeError: calling a builtin Promise constructor wit ...

Intermittent Z-index conflicts in need of a solution - seeking guidance

Is there a way to make the h1 heading and img image elements appear on top of the opaque div they are enclosed in? I want them to look unaffected by the transparency of their parent div. Here is a Fiddle demonstrating my issue: <div id="main"> ...

Box surrounding the image with a shade of gray, all thanks to

Despite trying to set "outline: none" and tweaking the border, I'm unable to resolve the issue. For reference, you can visit the page here: . I've shared the link because I'm unsure of what exactly needs fixing or adding on the page. Any gui ...

How come my CSS is causing my images to not align horizontally?

Hey there, I'm facing an issue with the layout of 6 images on my website. Currently, they are stacked vertically, but I want them to be displayed horizontally and centered. Additionally, 4 of these images have captions that should appear below each im ...

Is there a way to establish the TextField's minimum and maximum value parameters?

Is there a way to prevent users from selecting yesterday's date in the datetime-local input field? I've tried setting a min property inside the input props but it doesn't seem to be working. Additionally, how can I set a maximum value so tha ...

Can you explain the significance of open={Boolean(anchor)} in a Material-UI component?

Currently dealing with some existing code that includes a MUI menu defined within a React component written using TypeScript: interface Props { anchor: HTMLButtonElement | null; } ... <Menu id="order-menu" anchorEl={anchor} open={Boolean ...

How to style a CSS list and center-align it

My website features a <ul> list with submenus structured like this: <div id="cssmenu"> <ul> <li class='active'><a href='index.html'><span>Home</span></a></li> <li class=&ap ...

A guide to testing the mui Modal onClose method

When using material UI (mui), the Modal component includes an onClose property, which triggers a callback when the component requests to be closed. This allows users to close the modal by clicking outside of its area. <Modal open={open} onCl ...