Strategies for avoiding a hover component from causing distortion to its parent component in React

I am encountering an issue with a hover component that is causing distortion in its parent component when displayed. Essentially, I need to prevent the hover component from affecting the layout of its container. Below is the code snippet:

Styling for LanguageOptions (hover component):

import styled from 'styled-components';

export const LanguagesWrapper = styled.div`
  // removed padding: 0.3rem;
  background-color: #b0b2b7;
  border-radius: 5px;
  display: flex;
  flex-direction: column;
  flex-grow: 1; /* Add flex-grow property to expand vertically */
  gap: 0.8rem;
`;

export const StyledLanguagesTitle = styled.p`
  padding: 0.3rem; // added padding here;
  font-size: ${({theme}) => theme.typography.fontSize.medium};
  cursor: pointer;
  transition: background-color 0.3s;
  &:hover {
    background-color: #526d82;
  }
`;

export const ButtonForReferenceLink = styled.button<{
  icon: string;
}>`
  position: relative;
  width: 1.3rem;
  height: 1.3rem;
  background-image: url(${({icon}) => icon});
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  background-color: transparent;
  border: none;
  cursor: pointer;
  :first-of-type {
    height: 1.1rem;
  }
`;

Styling for References:

import styled, { css } from 'styled-components';


export const StyledWrapper = styled.div`
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  min-width: 200px;
  width: 98%;
  margin: auto;
  padding: 0 5px 0 5px;
  gap: 0.5rem;
`;

export const StyledTitle = styled.h2<{type: boolean}>`
  font-size: ${({theme}) => theme.typography.fontSize.mediumLarge};
  margin-bottom: 1rem;
  color: ${({theme, type}) => (type ? '#e0e0e0' : theme.colors.blue)};
`;

export const StyledInnerWrapper = styled.div<{type: boolean}>`
  width: 100%;
  max-height: 30rem;
  padding-right: 1.3rem;
  overflow-y: scroll;
  margin-bottom: 1rem;
  ::-webkit-scrollbar {
    width: 10px;
    background-color: rgba(
      0,
      0,
      0,
      0.2
    );
  }

  ::-webkit-scrollbar-thumb {
    background-color: ${({type}) =>
      type
        ? '#ff6363'
        : '#779199'};
    border-radius: 5px;
  }

  ::-webkit-scrollbar-thumb:hover {
    background-color: #c70000;
  }
`;

export const ReferenceItem = styled.div<{darkMode: boolean}>`
  display: flex;
  background-color: ${({theme, darkMode}) =>
    darkMode ? 'grey' : theme.colors.blueWithOpacity};
  padding: ${({theme}) => theme.spacing.small};
  border-radius: 0.6rem;
  width: 100%;
  height: fit-content;
  margin-bottom: 0.5rem;
  gap: 1rem;
  
`;

export const Content = styled.div`
  width: 100%;
  padding-left: 0.3rem;
  
`;

export const ButtonsWrapper = styled.div`
  display: flex;
  justify-content: start;
  flex-direction: column;
  min-height: 3rem;
  height: 100%;
  padding: 0.3rem;
  gap: 0.8rem;
`;

export const StyledText = styled.p<{small?: boolean, darkMode:boolean}>`

  font-size: ${({theme, small}) =>
    small
      ? theme.typography.fontSize.small
      : theme.typography.fontSize.mediumSmall};

  ${({small}) =>
    small &&
    css`
      font-style: italic;
      padding-top: 0.5rem;
      padding-bottom: 0.4rem;
    `}

  ${({theme}) => theme.breakpoints.up('sm')} {
    font-size: ${({theme, small}) =>
      small
        ? theme.typography.fontSize.small
        : theme.typography.fontSize.medium};
  }
  color: ${({theme, darkMode}) =>
   darkMode ? 'white'  : 'black' }; 
`;

export const ButtonForReferenceLink = styled.button<{icon: string}>`
  position: relative;
  width: 1.3rem;
  height: 1.3rem;
  background-image: url(${({icon}) => icon});
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  background-color: transparent;
  border: none;
  cursor: pointer;

  :first-of-type {
    height: 1.1rem;
  }
`;

Gif:https://i.stack.imgur.com/dXwQI.gif

I attempted some CSS tweaks without success in resolving the issue.

Answer №1

Can CSS be utilized to tackle this issue?

html

<div class="parent">
<div class="chilled">
 ... some element
</div>
</div>

css

/* position: relative; is positioned relative to its normal position. */ 
.parent{
position: relative;
}
/* position: absolute; is positioned relative to the nearest positioned ancestor. */ 
.chilled{
position: absolute;
}

The CSS Position property can be used to place an element behind another without disrupting the position of other elements. Find out more Here

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

What is the recursive process for printing the numbers 1 to 5 and then 5 to 1?

I was looking to print numbers from 5 to 0 and then from 0 to 5 in the most concise way possible. The code I came up with is below. However, I am open to other suggestions that may require fewer lines of code. Looking forward to your feedback. Thanks! ...

Simply modifying a custom attribute source using jQuery does not result in it being refreshed

Introduction: Utilizing jQuery.elevateZoom-3.0.8 to display zoomed-in images. The SRC attribute contains the path to the smaller/normal image The DATA-ZOOM-IMAGE attribute holds the path to the larger image used for zooming. Here is the HTML Code: ...

Error: Unable to access the property 'existsSync' since it is undefined - Creating Web Applications using Node.js and Express.js by Ethan Brown - Chapter 13

I am brand new to GitHub and the MEAN (mongodb, express, angular, node.js) stack. I am currently working through a book by Ethan Brown called 'Web Development with Node and Express', and he has provided a Git repository for me to clone and follow ...

Display a preview image at the conclusion of a YouTube video

I am currently working on an iOS device and have a Youtube video thumbnail that, when clicked, disappears and the video automatically plays in fullscreen mode using an iframe. It's working perfectly. Now, I would like to know how I can make the thumb ...

Error encountered in React component: TypeScript TS2339 states that the property 'xyz' is not found on type 'IntrinsicAttributes...'

I am attempting to develop a straightforward React component that can accept any properties. The syntax below using any is causing issues (unexpected token just before <): export class ValidatedInput extends React.Component<any, any> {...} The p ...

What is the process of setting up a RichTextEditor using Facebook's Lexical and inputting a text string for initialization?

I am looking for a way to integrate Facebook's lexical plugin into my React app by replacing the existing Material UI textFields. I need a simple example of how to populate the rich text plugin with text content. Currently, I am using this example: ...

Transforming the hover color of a dropdown in Material-UI Select components using React

I'm struggling to change the color of my dropdown hover to green. I attempted using inline CSS and makeStyle(), but neither of these solutions seem to be working for me. I'm unsure how to go about changing this hover color. If anyone has any insi ...

Encountering a "Module not found" error while trying to run npm start in a Create React App

I'm attempting to initiate a React project using create-react-app. Encountered an error when running npm start: Failed to compile. multi ./node_modules/react-scripts/config/polyfills.js ./node_modules/react-dev-utils/webpackHotDevClient.js ./src/i ...

How can I turn off the animation for a q-select (quasar select input)?

I'm just starting out with Quasar and I'm looking to keep the animation/class change of a q-select (Quasar input select) disabled. Essentially, I want the text to remain static like in this image: https://i.stack.imgur.com/d5O5s.png, instead of c ...

What is the best way to retrieve information from an http website and display it in an html table using javascript

I am attempting to retrieve data from the specified site: . The website appears to feature a list of objects, and my goal is to extract each object enclosed in {} into separate columns within a row (6 columns total - one for gameNumber, one for teams, and ...

Tips on how to add spacing between list items in React Material design

I am currently learning React Material and I am facing an issue with creating space between each row in a React Material List. Despite going through the documentation, I am unable to figure out how to achieve this as I am relatively new to React. My attem ...

Tips for keeping a login session active on multiple tabs

As I am in the process of developing a website, one issue I am facing is determining the most effective method to maintain user login sessions. Currently, I am utilizing Html5 web storage known as "session storage" to keep track of whether a user is logged ...

The back-to-top button guides users back to their last visited page

I'm excited to explore AngularJS and I want to add two "return to top" buttons on different pages. Here's what I have so far: Page 1: <h1 id = "top"> .......... <a href="#top" target = "_self">Return to Top</a> Page ...

When using React, I noticed that the AuthContext does not update when I change the state

After creating a useState ( [logined,setLogined] ) in authContext and sharing it as a value, I noticed that even when I change the logined value in signout, my Navbar does not re-render. This led me to place useEffect in Navbar to check the logined state ...

Get rid of the add to cart message and modify the button that says "add to cart" on Woocommerce

How can I modify the shopping cart page to remove the "has been added to your cart" text and replace the quantity and add to cart button with a custom button (my image)? Here is an example of what I am trying to achieve: This is the current state of the p ...

The issue with nextjs and vscode is that all the files are named index.js

With the current setup where all page files are named index.js, the file tabs section is cluttered with multiple index.js files. It becomes difficult to identify which file belongs to each specific page without opening and viewing the tab. This approach i ...

Tips for displaying and sorting two requests within one console

I am currently working on a project to display both folders and subfolders, but only the folders are visible at the moment. function getParserTypes (types, subject) { return types.map((type) => { return { id: type.entry.id, name: type. ...

I am having trouble scrolling through the main content when the side-drawer is open. How can I fix this issue?

When the sidebar is opened, I am facing issues with the main content scroll and certain fields such as select options and search bar not functioning properly. I have included the main content in the routes from which it is being loaded. However, the scroll ...

Using AngularJS to dynamically populate a dropdown menu from a JSON object

I am a beginner to Angular and currently facing my first significant challenge. The JSON object below is the address data retrieved from a third-party API and added to $scope.AddressData in a controller: $scope.AddressData = [{ "Address1":"South Row", ...

Refreshing an AJAX call automatically in Knockout JS

Greetings everyone! I'm currently working on setting up a simple setInterval function to automatically refresh my data every minute. The line that is giving me trouble is: setInterval(incidentViewModel.fetchdata,60000); I also attempted this: windo ...