title: How to apply my css changes only to one component in react js. Css file includes body tag and other tags which are affecting other components as well
body: <p>How to apply my css changes only to one component in react js. Css file includes body tag and other tags which are affecting other components as well. I have added Ids to each element in the required component where this css rules should be appiled. But its not working. Below are the files. I need the css rules to be applied only to the About.jsx component without affecting other components. Thanks in advance.</p>
  <p><strong>About.jsx component</strong></p>
  <pre><code>import React from 'react';
  import 'react-toastify/dist/ReactToastify.css';
  import LinkedInIcon from '@mui/icons-material/LinkedIn';
  import TwitterIcon from '@mui/icons-material/Twitter';
  import LocalPostOfficeIcon from '@mui/icons-material/LocalPostOffice';
  import { blue } from '@mui/material/colors';
  import logo from '../assets/profile-pic.jpeg';
         
  const About = () =&gt; {                              
  
      return (
          &lt;body id='about1'&gt;
              &lt;section id='about2'&gt;
                  &lt;div className='container' id='about3'&gt;
                      &lt;div className='card' id='about4'&gt;
                          &lt;div className='content' id='about5'&gt;
                              &lt;div className='imgBx' id='about6'&gt;
                                  &lt;img src={logo} alt='Logo' id='about7' /&gt;
                              &lt;/div&gt;
                              &lt;div className='contentBx' id='about8'&gt;
                                  &lt;h3 id='about9'&gt;Rishi&lt;br /&gt;&lt;span id='about10'&gt;Software Developer&lt;/span&gt;&lt;/h3&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;ul className='sci' id='about11'&gt;
                              &lt;li style={{ '--i': '1' }} id='about12'&gt;
                                  &lt;a href='#' id='about13'&gt;&lt;LinkedInIcon fontSize='small' sx={{ color: blue[500] }} /&gt;&lt;/a&gt;
                              &lt;/li&gt;
                              &lt;li style={{ '--i': '2' }} id='about14'&gt;
                                  &lt;a href='#' id='about15'&gt;&lt;TwitterIcon fontSize='small' sx={{ color: blue[500] }} /&gt;&lt;/a&gt;
                              &lt;/li&gt;
                              &lt;li style={{ '--i': '3' }} id='about16'&gt;
                                  &lt;a href='#' id='about17'&gt;&lt;LocalPostOfficeIcon fontSize='small' sx={{ color: blue[500] }} /&gt;&lt;/a&gt;
                              &lt;/li&gt;
                          &lt;/ul&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/section&gt;
              &lt;/body&gt;
      );
  }
  
  export default About;
  </code></pre>
  <p><strong>About.css</strong></p>
  <pre><code>@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300&amp;display=swap');
  *
  {
  margin: 0;
  padding: 0;
  font-family: 'Poppins', sans-serif;
  }
  body
  {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  background: #161623;
  min-height: 100vh;
  }
  section::before
  {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(#f00,#f0f);
  clip-path: circle(30% at right 70%);
  }
  section::after
  {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(#2196f3,#e91e63);
  clip-path: circle(20% at 10% 10%);
  }
  .container
  {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  margin: 40px 0;
  }
  .container .card
  {
  position: relative;
  width: 300px;
  height: 400px;
  background: rgba(255, 255, 255, 0.05);
  margin: 20px;
  box-shadow: 0 15px 35px rgba(0,0,0,0.2);
  border-radius: 15px;
  display: flex;
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(10px);
  }
  .container .card .content
  {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  opacity: 0.5;
  transition: 0.5s;
  }
  .container .card:hover .content
  {
  opacity: 1;
  transform: translateY(-20px);
  }
  .container .card .content .imgBx
  {
  position: relative;
  width: 150px;
  height: 150px;
  border-radius: 50%;
  overflow: hidden;
  border: 10px solid rgba(0,0,0,0.25);
  }
  .container .card .content .imgBx img
  {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  }
  .container .card .content .contentBx h3
  {
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 2px;
  font-weight: 500;
  font-size: 18px;
  text-align: center;
  margin: 20px 0 10px;
  line-height: 1.1em;
  }
  .container .card .content .contentBx h3 span
  {
  font-weight: 300;
  font-size: 12px;
  text-transform: initial;
  }
  .container .card .sci
  {
  position: absolute;
  bottom: 50px;
  display: flex;
  }
  .container .card .sci li
  {
  list-style: none;
  margin: 0 10px;
  transform: translateY(40px);
  transition: 0.5s;
  opacity: 0;
  }
  .container .card:hover .sci li
  {
  transform: translateY(0px);
  opacity: 1;
  }
  .container .card .sci li a
  {
  color: #fff;
  font-size:24px;
  }
  </code></pre>
  <p><strong>Other Css and scss files--&gt;</strong>
  <strong>File1</strong></p>
  <pre><code>return (
      &lt;React.Fragment&gt;
      &lt;HeaderContainer&gt;
          &lt;LogoContainer to='/'&gt;
              &lt;Logo className='logo' /&gt;
          &lt;/LogoContainer&gt;            
          &lt;OptionsContainer&gt;                
              &lt;Profile /&gt;
              &lt;/OptionsContainer&gt;
          &lt;/HeaderContainer&gt;                  
          &lt;HomePageContent /&gt;            
      &lt;/React.Fragment&gt;
  );
  
      import styled from 'styled-components';
      import { Link as RRDLink } from 'react-router-dom'
      
      export const HeaderContainer = styled.div`
          height: 70px;
          width: 100%;
          display: flex;
          justify-content: space-between;
          margin-bottom: 25px;
      `;
      
      export const FooterContainer = styled.div`    
          position: absolute;
          width: 100%;
          bottom: 0;
          height: 50px;
          padding:10px;    
          display: block;   
          text-align:center;
          float:left;
          margin-top:50px;
      `;
      
      export const LogoContainer = styled(RRDLink)`// this link is a custom component thats why we did like styled(Link)
           height: 100%;
            width: 70px;
            padding: 25px;      
      `;
      
      export const OptionsContainer = styled.div`      
            height: 100%;
            width: 70px;
            padding: 15px;
      `;
      
      export const OptionLink = styled(RRDLink)`
            padding: 10px 10px;
            cursor: pointer;
            color: black;
            text-decoration: none;
      `;
  </code></pre>
  <p><strong>File2</strong></p>
  <pre><code> const HomePage = () =&gt; (
      &lt;HomePageContainer&gt;
          &lt;Directory /&gt;
      &lt;/HomePageContainer&gt;
      );
  
  
  import styled from 'styled-components';
  
  export const HomePageContainer = styled.div`
      display: flex;
      flex-direction: column;
      align-items: center;
      padding: 20px 80px; 
  `;
  </code></pre>
  <p><strong>File3</strong></p>
  <pre><code>const Directory = ({ sections }) =&gt; (
      &lt;div className='directory-menu'&gt;
          {
              sections.map(({ id, ...otherSectionProps }) =&gt; (
                  &lt;MenuItem key={id} {...otherSectionProps} /&gt;
              ))
          }
      &lt;/div&gt;
      );
  
          .directory-menu {
          width: 100%;
          display: flex;
          flex-wrap: wrap;
          justify-content: space-between;
        }
  </code></pre>
  <p><strong>File4</strong></p>
  <pre><code> const MenuItem = ({ title, imageUrl, size, history, linkUrl, match }) =&gt; (
      &lt;div
          className={`${size} menu-item`}
          onClick={() =&gt; history.push(`${match.url}${linkUrl}`)}
      &gt;
  
          &lt;div className='background-image' style={{ backgroundImage: `url(${imageUrl})` }}&gt;&lt;/div&gt;
          &lt;div className='content'&gt;
              &lt;h1 className='title'&gt;{title.toUpperCase()}&lt;/h1&gt;                
          &lt;/div&gt;
      &lt;/div&gt;
  );
  
  .menu-item {
          min-width: 30%;
          height: 240px;
          flex: 1 1 auto;
          display: flex;
          align-items: center;
          justify-content: center;
          border: 1px solid black;
          margin: 0 7.5px 15px;
          overflow: hidden;
      
          &amp;:hover {
              cursor: pointer;
      
              &amp; .background-image {
                  transform: scale(1.1);
                  transition: transform 6s cubic-bezier(0.25, 0.45, 0.45, 0.95);
              }
      
              &amp; .content {
                  opacity: 0.9;
              }
          }
      
          &amp;.large {
              height: 380px;
          }
      
          &amp;:first-child {
              margin-right: 7.5px;
          }
      
          &amp;:last-child {
              margin-left: 7.5px;
          }
      
          .background-image {
              width: 100%;
              height: 100%;
              background-position: center;
              background-size: cover;
          }
      
          .content {
              height: 90px;
              padding: 0 25px;
              display: flex;
              flex-direction: column;
              align-items: center;
              justify-content: center;
              border: 1px solid black;
              background-color: white;
              opacity: 0.7;
              position: absolute;
      
              .title {
                  font-weight: bold;
                  margin-bottom: 6px;
                  font-size: 22px;
                  color: #4a4a4a;
              }
      
              .subtitle {
                  font-weight: lighter;
                  font-size: 16px;
              }
          }
      }
  
      
  </code></pre>