Embarking on the journey of nesting components within styled-components

Check out these custom components I created:

<UserImg imgUrl={userPhoto}>
  <DropDown>
    <div onClick={handleAuth}>Sign Out</div>
  </DropDown>
</UserImg>

const DropDown = styled.div`
  letter-spacing: 0.2em;
  position: relative;
  top: 7vh;
  left: 23vw;
  border-radius: 2px;
  text-transform: uppercase;
  transition: all 0.5s ease-in;
  border: 2px solid red;
  div {
    padding: 0.3em;
  }
`;

const UserImg = styled.a`
  background-image: url(${(props) => props.imgUrl});
  background-repeat: no-repeat;
  background-size: contain;
  background-position: 30%;
  display: inline-block;
  cursor: pointer;
  position: relative;
  height: 12vh;
  width: 5vw;
  left: 25vw;
  border: 2px solid white;
  border-radius: 50%;
  &:hover {
    ${DropDown} {
      visibility: visible;
      border: 1px solid white;
      border: transparent;
      cursor: pointer;
    }
  }
`;

The UserImg component is functioning properly, but unfortunately the DropDown component isn't showing up as expected.

I'm looking to have the DropDown component visible on the page.

Answer №1

Your <DropDown> component is being displayed, but it may not be in the position you anticipated. It is actually 23vw to the right of <UserImg>, as indicated by the left: 23vw; style property: https://i.sstatic.net/M6LUE.png

If you wish for it to be positioned 2vw to the left instead, you would need to adjust the style to left: -2vw;.

Keep in mind that because <DropDown> is a child of <UserImg>, its positioning is relative to its parent container.

Check out the demo here: https://codesandbox.io/s/naughty-lewin-9zi6ws?file=/src/App.js

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

Enhance container and typography for layouts converted to 1920px width to improve overall design

Greetings to all! I need some assistance with converting a design file that is 1920px wide into an HTML layout. Can someone provide tips on optimizing containers and typography for responsiveness? Specifically, I would like the font-size and line-height ...

Can you please provide the Typescript type of a route map object in hookrouter?

Is there a way to replace the 'any' type in hookrouter? type RouteMap = Record<string, (props?: any) => JSX.Element>; Full Code import { useRoutes, usePath, } from 'hookrouter' //// HOW DO I REPLACE any??? type RouteMap = ...

Using jQuery to modify CSS properties in the propertyName

With jQuery v1.6.4, I am attempting to dynamically format some objects. Take a look at my code snippet: <html> <head> <script src="http://code.jquery.com/jquery-1.6.4.min.js" type="text/javascript"></script> <script type="text ...

React Material-UI components (Slider/Select) "onChange" event does not update the value instantly, it shows the result of the previous click

My goal is to utilize Slider/Select for capturing user query parameters, which will then trigger changes in the URL (via handleChange) and subsequently make API calls using fetch hooks. However, I've encountered an issue where adjusting the Slider va ...

Images in NextJS failing to load

In my main project directory, I have a folder called /public which contains two image files: "home.jpg" and "home-placeholder.jpg". Within the /pages/index.js file, there is a component that requires these images: function Page() { return ( <> ...

Retrieve and modify the various elements belonging to a specific category

I'm currently developing a chrome extension and I need to access all elements of this specific type: https://i.stack.imgur.com/sDZSI.png I attempted the following but was unable to modify the CSS properties of these elements: const nodeList = documen ...

Styling with CSS: A guide to reducing paragraph margins within a div element

My current project involves using javascript to dynamically insert paragraphs inside a div element. Essentially, the script grabs the value entered into an input form when a button is clicked and adds it as a new paragraph within a specific div. However, I ...

What is the correct way to import and display custom fonts (non-google fonts) in a next.js 14 / tailwind combo?

Is there a way to use .otf font files in my next.js 14 project and apply them using tailwind convention? I've noticed that regardless of what I do, the browser defaults to google fonts for the font-family (ui-sans-serif, system-ui, sans-serif, "Apple ...

Fuzzy backdrop with razor-sharp edges

In the process of designing a website, I am in need of a header with a blurred background that retains sharp edges. To achieve this effect, I implemented the use of ::before in my CSS code. Current Outcome: (For full clarity, it may be necessary to view ...

Errors from jQuery validation are causing disruptions in my form's functionality

When jQuery validation error messages appear, they take up space and push other fields downwards. I want the error messages to adjust within the available space and not disrupt other fields or elements. Below is the jQuery validation code I'm currentl ...

Steps for aligning the upper rectangular text in the center of the larger rectangular border

https://i.stack.imgur.com/7yr5V.png I was aware of a particular element in html that had text positioned in the upper left corner, but my knowledge didn't go beyond that. Should I be adjusting the translation on both the X and Y axes based on the par ...

What is the best source for retrieving data - my database, an open api, or JSON files?

For my novice portfolio, I am creating a Pokemon team builder app. With over 800 unique Pokemon to choose from, each with its own abilities and moves, the project requires substantial data. Luckily, there is a free online api known as PokeAPI that provides ...

Validating (Update database with correct email and token)

Authentication (Update database if email and token are accurate) Even when the code is incorrect, it displays "Great Success", but the status does not update in my database. However, if I input the correct code, it shows "Great Success" and updates the s ...

Efficient Techniques for Concealing and Revealing Navigation Menus using HTML, CSS, and JavaScript

I need help making the menu icon toggle the navigate menu between showing and hiding when clicked on the top right corner of the screen. For better understanding, here is an accompanying image: https://i.stack.imgur.com/oy6d9.png However, the current co ...

Unable to successfully upload a file using useField within Formik

I've been working on uploading files with Formik and encountered an issue with the following code snippet. import { Field, ErrorMessage, useField, FieldProps } from "formik"; import { InputHTMLAttributes } from "react"; type Formi ...

Ways to expand logo space within the header of the Twentysixteen Theme on WordPress

I am facing an issue with my logo being resized to a much smaller size of 200px even though it is originally over 2000px wide. In the style.css file, I found the following code: .custom-logo { max-width: 180px; } Despite changing the max-width value t ...

Adding icons to form fields based on the accuracy of the inputs provided

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Assignment 2 - Website Bui ...

Dealing with a void method in a React unit test by treating it as an object's property

How can I pass a value to a function in an interface to trigger a click event on an element? I have a React component that I want to write unit tests for: const VariantItem = (props: VariantItem): ReactElement => { return ( <div key={props.produc ...

Methods for defining a variable in React with Typescript without encountering the "Index signature is missing in type" issue

I am facing an issue while trying to declare a variable 'reports' and assigning it to an array of arrays containing string and number types. The problem arises when I try to assign it, resulting in errors. ... // Retrieving data from an API let ...

The nextjs project I'm working on is currently facing a build error

https://i.stack.imgur.com/f8WUB.png https://i.stack.imgur.com/gcD6n.png I am facing an issue with the build while trying to upload my project to Vercel. Being new to this, I am unsure about how to resolve it. Please assist me in troubleshooting. Th ...