-1

Hello i want to build a toolbar that has an image in the background. I have build two different components. The first is the image component:

import React from 'react';
import thepic from '../mypic.jpg'; // with import
import '../App.css';

const Image = () => {
  return (
    <img src={thepic} className='the-pic' />
  )
}

export default Image;

The second component is the toolbar, i am using react-bootstrap toolbar and i wrap the previous component in the toolbar:

<Image>
  <Navbar>
    <Container>
      <Navbar.Brand href="#home">
        React-Bootstrap
      </Navbar.Brand>
      <Navbar.Toggle aria-controls="basic-navbar-nav" />
      <Navbar.Collapse id="basic-navbar-nav">
        <Nav className="me-auto">
          <Nav.Link href="#home">
            Home
          </Nav.Link>
          <Nav.Link href="#link">
            Link
          </Nav.Link>
        </Nav>
      </Navbar.Collapse>
    </Container>
  </Navbar>
</Image>

I have manage to display the image in the screen but the toolbar is not shown up. It's like the image override the toolbar.
Can anyone help with this ?

Monstar
  • 795
  • 1
  • 5
  • 23
The_elevator
  • 75
  • 1
  • 8
  • Why is there a duplicate question right below? https://stackoverflow.com/questions/72047655/build-a-toolbar-inside-an-image-in-reactjs – Igor Gonak Apr 29 '22 at 14:01

1 Answers1

0

The approach is wrong, you shouldn't make a component for a background image and use it like a "slot" for other components. What you can do is siply give a background image to your navbar component as prop, so it will be dynamic.

Davide
  • 21
  • 3
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 29 '22 at 20:25