What is the best way to utilize a CSS framework for just one component in my React application?

I am currently working on a large portfolio project in React and I want to avoid the hassle of rebuilding the entire project just because of a styling framework. The issue I am facing is that when I use Materialize CSS Framework, it affects other parts of my page instead of just the specific div object where I need it to work correctly, like for the className 'card'.

How can I instruct the Materialize CSS Framework to only apply to a particular section, say 'App3', without affecting the rest of the page?

import React, { Component } from 'react';
import Header from './components/Header';
import About from './components/About';
import Resume from './components/Resume';
import Portfolio from './components/Portfolio';
import Testimonials from  './components/Testimonials';
import ContactUs from './components/ContactUs';
import Footer from './components/Footer';
import resumeData from './resumeData';

class App extends Component {
  render() {
    return (
      <div className="App">
        <Header resumeData={resumeData}/>
        <About resumeData={resumeData}/>
        <Resume resumeData={resumeData}/>
        <Portfolio resumeData={resumeData}/>

  <div className="App3">
     <div class="card" style={{ width: '18rem' }}>
      <div class="card-image waves-effect waves-block waves-light">
      <img class="activator" src={weatherImage}></img>
    </div>
  <div class="card-content">          
  <span class="card-title activator grey-text text-dark-4">


<i class="material-icons-right"><img src={iconUrl}></img></i></span>
   </div>
    <div class="card-reveal">
    <span class="card-title activator grey-text text-dark-4">{this.state.cityName}
<i class="material-icons-right"><img src={iconUrl}></img></i></span>

      <div className="row">
        <div className="col s6 offset-s3">
          <form onSubmit={this.searchCity}>
        <input type="text" id="city" placeholder="City..."></input>
        </form>
      </div>
      </div>
      </div>

      </div>
      </div>

`

        <Testimonials resumeData={resumeData}/>
        <ContactUs resumeData={resumeData}/>
        <Footer resumeData={resumeData}/>

      </div>
    );
  }
}

export default App;

Answer №1

If you want to implement scoped style, you can do so by following this example:

<div>
    <style scoped>
        @import "yourCustomCssFile.css";
        <div class="styled-card" style={{ width: '18rem' }}>
    </style>
</div>

For more guidance on scoped CSS, check out this resource.

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

Replace all empty space in the current line with dots. This is a multi-line text

Trying to achieve a specific look for an html page, which involves filling whitespace with dots until the end of the line without using javascript. Various solutions have been attempted for single-line elements, but none have worked for multi-line element ...

Could the problem with inset box-shadow and large border-radius on one side be related to Chrome?

Have you noticed a discrepancy in the inset box-shadow behavior with large border-radius on one side, particularly in Chrome? I'm curious about which browser is showing accurate results. Here's how it appears in Chrome: https://i.stack.imgur. ...

Submitting data from an HTML form directly to a Google Docs spreadsheet

Can an HTML form post directly into a Google Docs spreadsheet without allowing public access or modifications by others? I'm wondering if it's possible to achieve something like this: <form action="https://google-docs-url" method="POST"> ...

Executing a jQuery AJAX request to pass an array of values to a Controller action

I'm attempting to send an array of checkbox values from an Ajax form in MVC to a controller action. Below is the code I am using: The form (inside a modal): @using (Ajax.BeginForm("GetPrintableProject", "Project", null, new AjaxOptions { HttpMethod ...

Tips for altering Koa's HTTP status code for undeclared paths

If an undefined route is accessed on a Koa server, what is the best method to change the default HTTP status code and response body? Currently, Koa returns a 404 status and 'Not Found' text in the body. I intend to modify this to 501 (Not implem ...

Using Typescript and JSX to render a component that has been passed as an argument

I am seeking to create a function that will render a React component passed as an argument. I aim to accommodate both Component and StatelessComponent types with the following approach: function renderComponent(component: React.ComponentClass<any> | ...

What is the process for creating a personalized <a> tag using CSS?

On my website, I am looking to differentiate between two types of <a> tags - one for inline links and the other for standalone links. This means that I want these two variations of <a> tags to have distinct colors and styles. For inline links, ...

Vercel and Express.js do not support hosting JavaScript files

I set up an Express.js server on Vercel with NowCLI, and in my index.js file, I configured it to serve all files in my dash/assets folder at assetsDash/ using app.use('/assetsDash', express.static(path.join(__dirname, 'dash', 'asse ...

Creating a JavaScript function triggered by a click event that will redirect to

I'm attempting to create an onclick function that will redirect you to a new page when you click on a div element, much like the A + href attribute in HTML. Any suggestions on how to achieve this? Should I just add an A tag inside the div? I'm un ...

The React Camera component experiences issues when trying to function on a mobile device

I've been trying to test the Camera functionality in my React application using different mobile devices like the iPad Pro and Google Pixel 6a. I experimented with both react-webcam and react-camera-pro, but unfortunately, neither seemed to work on mo ...

Angular: Unable to retrieve defined data when loading a component

There is a nagging question in my mind that I hesitate to ask because deep down, I know the answer is probably staring me in the face. After struggling with code for two days straight, I am on the brink of pulling my hair out. Although I am relatively new ...

Drupal 6 encountering an inline AJAX error

Is there a way to add custom inline error messages to a form in Node, including CCK and other elements? I have looked at multiple modules, but none of them seem to offer a complete solution as they lack CCK support, upload support, error messages, etc. ...

Can anyone recommend an HTML element that is capable of containing spans and supporting editable text within?

Is there a way to combine a span or another container with editable text within the same box, such as one of the boxes on the left side? https://i.sstatic.net/ZBTtn.jpg I am looking to enable users to click directly on the box, input text, and then a ...

Challenges regarding variable scope in JavaScript

Presented below is the JavaScript code I am currently using, which involves jQuery: function language(language) { var text = new Object(); $.ajax({ type: "GET", url: "includes/xml/languages/" + language + ".xml", dataType: ...

(React) Error: Unable to access property 'this' as it is set to undefined while trying to utilize refs

When using a ref in React to refer to an input field, I encountered an error: "Uncaught TypeError: Cannot read property 'this' of undefined". Despite having defined the ref, React seems unable to locate it in my code. What could be causing this i ...

Add a class to a button in an Angular btn-group if a specific string is found within an

I am currently working on a project where I have multiple buttons that need to toggle an active class when selected in order to change their color. Below is a snippet of what I have: In the array called 'selected', I have: this.selected = [&ap ...

Table pagination in Mat is experiencing overflow, and the button styles have also been customized for a unique look

I implemented a mat paginator feature, however, I am facing an issue where the alignment of items per page options is not correct. Below is the snippet from component.html file: <div class="table-responsive" *ngIf="resultssummaries"> &l ...

When I first began using React with npm, I decided to install create-react-app. However, I encountered difficulty in creating the React folder thereafter

My initial attempt was to install create-react-app globally by using the command `npm install -g create-react-app`. Following that, I tried running `create-react-app myapp`, but unfortunately encountered the same error as shown in the image below. Subseque ...

AngularJS: Batch processing for saving multiple students simultaneously

I have been working on saving information about students, and I've written the code below. However, I'm unsure how to proceed from here. Any additional information or resources related to this topic would be greatly appreciated. <div ng-contr ...

Utilize the power of Material-UI's Drawer and AppBar components in your React

Utilizing the material-ui AppBar and Drawer components, my project structure consists of individual files for each component. However, I am struggling to find documentation on how to activate the Temporary drawer Button using the "OPEN LEFT" button in the ...