Managing the height of a hero section with TailwindCSS and React.js

Embarking on my first website project using React and Tailwind has been an exciting learning experience.

My vision is to showcase a Hero Section prominently at the top, with a Nav bar situated elegantly at the bottom of the screen.

To bring this concept to life, I plan to divide the layout into two distinct sections: The hero section occupying 80vh and the Navbar taking up the remaining 20vh to ensure full-page coverage.

In attempting to implement this design, I have structured my Hero Component as follows:

const HeroSection = () => (

  <div className="h-4/5 bg-green border-nft-gray-1">Hero Section</div>

);

export default HeroSection;

I have relied on the guidance provided in the documentation for achieving 80% screenspace, indicated by h-4/5:

https://tailwindcss.com/docs/height

Despite my efforts, the frontend displays a different outcome than expected. The Hero Section, represented by the green div, does not adhere to the specified 80%vh but rather adjusts its size based on content height.

https://i.sstatic.net/Bcg5d.png

The app compilation occurs as shown below:

const Marketplace = ({ Component, pageProps }) => (
  <NFTProvider>
    <HeroSection />
    <Navbar />
  </NFTProvider>
);

export default Marketplace;

Furthermore, the Provider utilized for data transfer encapsulates both components and defines their output:

  return (
    <NFTContext.Provider value={{ nftCurrency, buyNft, createSale, fetchNFTs, fetchMyNFTsOrCreatedNFTs, connectWallet, currentAccount, isLoadingNFT }}>
      {children}
    </NFTContext.Provider>
  );

Upon inspection, it seems that there are no conflicts between the CSS and the setup. What am I missing in terms of utilizing Tailwind effectively to achieve the desired composition?

Your insights and assistance are greatly appreciated.

Answer №1

By setting the height of your hero section div to h-4/5, you are effectively making it 80% in height. However, this height is only relative to its parent window. To achieve the styling effect you have in mind, you need to specify that you want the height of the entire viewport.

Therefore, update it to

<div className="h-[80vh] bg-green border-nft-gray-1">Hero Section</div>

Answer №2

It is recommended to specify the height when utilizing the components.

const Marketplace = ({ Component, pageProps }) => (
  <NFTProvider>
    <HeroSection className="h-4/5" />
    <Navbar className="h-1/5" />
  </NFTProvider>
);

export default Marketplace;

Make sure to delete h-4/5 from the HeroSection component itself.

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

Only output to the console if the data returned from an AJAX request has been

Here is a script that I created: <script type="text/javascript> $('.storage').html(""); setInterval(function(){ $.get('./playcommand.php', function(data) { if($('.storage').html() !== data){ ...

Showcasing ranges from various input types on a single page

I have a challenge in displaying the values of multiple sliders on my webpage. Here's the code snippet I've been working on: var i = 0; var st = 'slider'; var ot = 'output'; var s = ''; var o = ''; for ...

Unable to interact with the page while executing printing functionality in

component: <div class="container" id="customComponent1"> New Content </div> <div class="container" id="customComponent2"> different content </div> ...

Scroll bar displayed on a non-editable text box

The TextArea is currently set to readonly mode using "ng-readonly," which is causing the scrollbar-thumb not to appear. It's important to note that I am not utilizing webkit in this scenario. Below is the HTML code being used: <textarea dataitemfq ...

Issue with JavaFX: Unable to remove additional space on the right side of TabPane

While developing a full-screen application on JavaFX 2.2 with tab navigation, I encountered an issue where there is a 10px space at the right side of the headers region. Surprisingly, this space only appears after switching to the last tab and disappears w ...

Checkbox click event not triggering properly

I am facing challenges in triggering an onclick event for the "Elevation" checkboxes located at the URL provided above. <input type="checkbox" value="A" id="elevation_A" onclick="changeElevation(this.value);" /> For some reason, the "changeElevati ...

How to keep Vuetify component at the top of the v-layout?

https://i.stack.imgur.com/cKdsk.png I am in the process of creating a website using vuetify and nuxt. My goal is to specify the max-width property for the expansion panel UI component (https://vuetifyjs.com/en/components/expansion-panels). Here is my curr ...

Splitting up JavaScript and HTML within a WordPress environment

I recently came across a discussion on separating PHP code and HTML at this link I find myself in a similar predicament. My current project involves designing a WordPress website with numerous sliders, animated dropdowns, forms, and other components. The ...

The necessity of using Adobe Photoshop for optimizing a Web Template

My interest lies in utilizing web templates, such as the one referenced here:- templete However, within its details tab, it specifies that the following software is required:- Adobe Photoshop CS+ Sublime Text2 or later, Notepad++, Dreamweaver CS5.5+(Co ...

What are some ways to enhance mobile browsing with CSS?

I'm facing a challenge with optimizing my webpage for different mobile resolutions in my beginner HTML/CSS course. Whenever I use a website resolution simulator to test, the layout doesn't look right on certain settings. Is there a method to aut ...

Utilize CSS to create a visual buffer at the bottom of the header

I'm having trouble creating a gap between the bottom of "headermenu" and the top of "list". No matter what values I use for margin-bottom or padding-bottom, the table won't budge. I could try adding margin-top to the table, but I would prefer to ...

Guide to using jQuery to load an image

I am using this code to load an image and display it within a dialog box. <div id="image_preview" title="Client Photo Preview"> <p><img src="" alt="client image" id="client_image_preview" /></p> </div> $("#client_image_p ...

adjust the fixed div's width to match the percentage-defined width of its parent element

My goal is to make a div with the position: fixed property have the same width as its parent element, which is a td. However, I am having trouble achieving this. Here is my current code: HTML: <table style="width: 90%; border: 1px solid black;"> & ...

The navbar slide toggle is supposed to slide behind the navbar, but instead it slides in front of

Recently, I created an animated navbar that works perfectly fine. However, there is one issue that bothers me - when the list of menu items slides open, it appears in front of the navbar instead of behind it. If you'd like to see the problem in actio ...

What is the best way to navigate down a page using the <a> tag?

I'm working on creating a mini wiki page on my website that will have a table of contents at the top. Users can click on a link in the table of contents and it will automatically scroll down to the relevant section of the page. I know this involves us ...

An error with rendering in Internet Explorer 8

When I hide a td in a table by setting its display to none, the table does not resize correctly when using IE8. If I have a table and want to remove an entire column, I might try something like this: $("th:first, th:last, tr td:first-child, tr td:last-ch ...

Discovering country code details through the Geonames service API rather than relying on the HTML5 location object

My goal is to retrieve the country code of the user's current location using the Geonames Service API. However, it seems that the API only provides a two-letter country code instead of a three-letter one, which is what I require. To work around this i ...

The initial render of Next.js is not properly loading the CSS files

Encountering an issue with the initial load of the mobile app version; it seems that the CSS of my component covering the page is not loading correctly on the first screen load. However, when resizing to desktop and then switching back to mobile view, the ...

Unable to center div container with margin set to auto

I'm struggling to center my container on the website. My goal is to have it centered and take up about 80% of the page so I can incorporate an image slider and text inside. Using margin: 0 auto doesn't seem to be achieving what I want. The backgr ...

Discrepancy in image dimensions between Android and iOS

Currently, I am in the process of building a website and have encountered an issue with the display of images on Android and iOS phones. The image appears differently on an Android Galaxy J-5 compared to an iOS iPhone 6s screen. My goal is to make it look ...