Element not inheriting parent element's height
I have the following code in App.js:
And the following
Main
component:
Theoretically speaking, since main has height: 100%
, it should take up its parent's height (the parent with flex-grow
), but in my case it doesn't. See the linked screenshot (I changed the colors to make it more visible; the purple and purple border is the parent div; the light red is the Main
component's elements).
Why is the Main
component not inheriting the parent component's height? My theory is that perhaps it has something to do with Routes
interfering, but I'm at a loss.20 Replies
you can only have a % of something that has a set strict* height.
So the parent would have to have a set height:
Ah, I didn't know that. Thank you.
So what would you suggest I do in this scenario?
Is there no way to make it expand to the entire height of parent?
https://codepen.io/b1mind/pen/PojdyQz use Grid π but here is both a flex and grid solution
I can use 100% because I pass it down from html{} (which is the only element it will get value % from document view or w/e)
I use svh in this example as progressive enhancement (meaning if browser supports it it will use it) but know that viewport units will breakout of parents.
Adding the above to my
index.css
does nothing unfortunately. Perhaps there's more I'm supposed to do that I didn't understand in your example, but I believe I'm using flexbox as you are.for #root I would use
display: contents;
and just ignore it
without a demo of your issue there is nothing I can do to solve it.
Also again I think the grid solution is 100x the better solution
I would use it over the flex 100% of the time. I just have both examples to show how.
auto 1fr
is goldI see, thanks. Unfortunately I can't run a demo right now since this is a full-stack app and I haven't hosted it anywhere yet..
I'll try to do what I can with iti
you can just use Stackblitz fyi
https://stackblitz.com/
also you can abstract the CSS issue away, sometimes this is best anyway
minimal demos are better than full application xD
I was just trying some random stuff and I decided to change the App's first div with
min-h-screen
to an h-full
and it suddenly worked (with the html, body set as you'd set it). Very weird behavior with heights.
Just new to all this CSS stuff and height is confusing me very much.
Are you able to diagnose why min-h-screen
(aka min-height: 100vh) doesn't work in this context but h-full
(height: 100%) does?
Guess I'll need to go more in-depth into heights tomorrow morning
At least I got the issue resolved for nowmin-height isn't a height... it's "at least this size, but it could be bigger", where as "height: 100%" is a "this is how big it is"
If you are just learning CSS I would start by learning CSS and stop using Tailwind so you can understand what is happening
Well, I know how to design a website given some basic structure with CSS, I was trying to learn more in depth right now. This website was actually being made to store all the various learning projects I store for frontend and backend.
I have zero idea about responsiveness and more in-depth stuff about heights.
I used to set heights manually on nearly all divs until I was recently told that's not what you're supposed to be doing.
correct best height is no height, let your content determine height when ever you can. min-height is handy for this reason
I don't think tailwind is adding any overhead honestly, it's literally just normal css except much shorter and much more convenient to write, to me at least.
I plan on going through Kevin's responsiveness course after I refactor the website a bit
just another abstraction
like the fact min-h-screen uses
vh
π€’Is that supposed to be bad?
You basically trusting them to do things right
when they do things how they want not per say an actual working group or spec
like how they proposed to make
* { min-width: 0;}
π€£ just yea you really gotta know what things they add
Kevin made me a video just so I don't have to rant anymore lolKevin Powell
YouTube
Use these instead of vh
Looking to step up your CSS game? π https://kevinpowell.co/courses?utm_campaign=general&utm_source=youtube&utm_medium=viewportunits I have a bunch of courses, including several free ones.
I see people use
vh
a lot, and then complain that it doesnβt work the way they thought it would, so in this one, I explore a few other options that we have,...Thanks, will watch
Kevin Powell
YouTube
The problems with viewport units
Conquering Responsive Layouts (free course): https://courses.kevinpowell.co/conquering-responsive-layouts
Join the Discord: https://kevinpowell.co/discord
Viewport units often feel like this cheat code that makes things so much easier when you first discover them, but they actually are problematic for a number of reasons, from creating horizon...