Hero Section

i want to make my hero image expand with the content inside it like the Story Graph my effort got me to second pic and i am lost why it is behaving this way
No description
No description
16 Replies
ἔρως
ἔρως3w ago
can you show us the code?
Duckit69
Duckit69OP3w ago
<nav className="flex items-center justify-between absolute w-full top-4 px-4"> <a href="/"> <img src={logo} alt="logo" className="size-10" /> </a> <ButtonAnchor text="Join us!" path="test" className="text-black text-xl" /> </nav> function App() { const hederHeroClasses = [ "bg-[url(./assets/heroImg.jpg)]", "bg-cover", "mx-auto", "w-full", "py-12", "h-48", ]; return ( <> <div className="text-white bg-cyan-800"> <div className="opacity-10"> <div className={${hederHeroClasses.join(" ")}}></div> </div> <Navbar></Navbar> <div className="px-6 ml-10"> <p className="text-2xl">Book Tracker</p> <p className="text-3xl"> Because life's too busy to track your own books. </p> </div> </div> </> ); }
Duckit69
Duckit69OP3w ago
No description
Duckit69
Duckit69OP3w ago
like the second div ( where the text exist ) has its own background ( i can be wrong i am just thinking out loud )
ἔρως
ἔρως3w ago
that content can be put in a flex parent, taking the width and some height, and you align it to the center
Duckit69
Duckit69OP3w ago
flex parent ? u mean display flex on parent levle ? i am sorry but i did not understand it
ἔρως
ἔρως3w ago
yeah, on whatever has the background
Duckit69
Duckit69OP3w ago
i will try to and push the navbar and the content as its children right ? so whatever the space the children take the parent will expand to cover it
ἔρως
ἔρως3w ago
no, the navbar has nothing to do with it it's a separated element
Duckit69
Duckit69OP3w ago
no idea
Chris Bolson
Chris Bolson3w ago
Unless I am missing something else what you need to do is to move your background image to the main parent element so that it becomes the background for the complete container. Then give it a width and height of 100% . If you want/need to set opacity, you could define it on a pseudo element on the parent element.
Duckit69
Duckit69OP3w ago
i tried this approach and all the content is stuck at the top
Duckit69
Duckit69OP3w ago
No description
ἔρως
ἔρως3w ago
set a minimum height and give it flex
Chris Bolson
Chris Bolson3w ago
I would do something like this: - Place the background image on a pseudo element on the parent (use pseudo so that you can set opacity) - Remove the absolute positioning on the nav. - Add a top margin to the "Book tracker" element to push it down to where you want it.
Duckit69
Duckit69OP3w ago
okay imma exhaust your suggestions thank you

Did you find this page helpful?