I'm trying to get a div in the homepage to fill 100% of the height it can occupy.
I've tried different solutions like applying height: 100% to the body or all the divs etc. but none of it worked.
A solution would be appreciated.
Thanks in advance.
[EDIT]
I applied height: 100% to #__docusaurus and that solved the height but now it does this: https://i.stack.imgur.com/TohTP.png
This is a padding in the Home Page.
Navigate to ./src/components/ and open the HomepageFeatures.js.
Inside this file, look for .features { and remove the line padding: 2rem 0;.
Solved.
I didn't use the height 100% but I applied the following css:
.parent { // For docusaurus/me its .main-wrapper
display: flex;
flex-direction: column;
}
.child { // For me its the feature section that can be seen in the images posted
flex-grow: 1
}
I also removed the height: 100% from the child and parent
Related
I often need that html and body elements have the size of the screen. Typically, in the case when I want to have a svg element fit the whole screen.
To achieve that, I saw that it was possible to use CSS code as follow.
html,body{margin:0;padding:0;height:100%;}
The code that I personnaly use is the following one.
html {
height: 100%;
display: flex;
}
body {
flex-grow: 1;
display: flex;
flex-direction: column;
}
Both seem to work well, but I recently had the following remark.
html { height: 100%; display: flex; } is a useless declaration. html height will always be calculated to fit content. Also 100% means 100% of the parent. html has no parent... also applying flexbox to html is useless as it only has 1 child element that is visible: body.
Actually:
I put 100% of html height in order to have it fit the screen height.
I apply flexbox to html in order to be able to use flex-glow: 1 on its child, and have this child filling its parent.
Is there any better to solution than mine?
I personally use this:
html {
display: grid;
min-height: 100%;
}
This will make your body full height by default and will also respect default margin
html {
display: grid;
min-height: 100%;
background: blue;
}
body {
background: red;
}
And you can easily use height:100% on an inner element without issue:
html {
display: grid;
min-height: 100%;
background: blue;
}
body {
background: red;
}
.box {
height: 100%;
border: 5px solid green;
box-sizing: border-box;
}
<div class="box"></div>
I find that whenever working with elements that need to be the full height of the screen height: 100vh is usually a good place to start. VH = viewport height. I use it over height: 100% as depending on the layout 100% doesn't always equal the page height, so with VH you know exactly what you are getting!
With VH you can also then use a calc() in your CSS, so if you needed your body to fill the whole height of the page, but subtract the height of a header for example you could do something like this:
<header style="height: 64px">
<section style="height: calc(100vh - 64px)"
I currently have a simple header, main, footer structure in my angular project and would like to make the main-component a flex-box in order to arrange all given components horizontally with equal width. Additionally I want to change the flex-direction, when the screen width is lower than 700px to column.
Since I already achieved this with pure HTML + CSS (see jsfiddle: http://jsfiddle.net/aJPw7/443/) I have the feeling that this has something to do with angular parent components.
Expected behaviour: The two <app-content-section> elements each take 50% width of the <app-main-component> and 100% height. When I change the flex-direction to column they should have 100% width and 50% height:
Currrent behaviour: The <app-content-section> elements align when I use "justify-content" but are not influenced by any hight or width attributes.
Style.css
html, body {
height: 100%;
width: 100%;
padding: 0;
margin: 0;
}
app-root HTML:
<app-main-component>
<app-content-section></app-content-section>
<app-content-section></app-content-section>
</app-main-component>
app-main-component HTML:
<div class="main-component">
<ng-content></ng-content>
</div>
app-main-component CSS:
.main-component {
display: flex;
flex-direction: row;
height: 100%;
}
#media screen and (max-width: 700px) {
.main-component {
flex-direction: column;
}
}
app-content-section HTML:
<div class="content-section">
<a>Test</a>
</div>
app-content-section CSS:
.content-section {
width: 100%;
height: 100%;
}
Edit1: I also tried :host{ } but still no luck.
Edit2: I created another jsfiddle where I achieved the correct width, by styling the host-element and adding flex: 1, but elements still won´t use the whole height. https://jsfiddle.net/1c15q243/19/
So the correct answer is adding a :host{ flex: 1; } in the "app-content-section CSS" in order to give its hosting-component <app-content-section> the correct flex-sizing.
I figured it out in the fiddle of my second edit, but #karthikaruna pointed out that I forgot to add HTML- tag in the stylig file.
Set 100% height to html. Here is the updated fiddle.
I've created the following demo to show my issue:
http://francisbaptiste.com/nov17/
Each div is 33.33% wide. Within the div is an image with 100% width. I want it to be a perfect grid of images, but the height of the div is always a little more than the height of the image.
Shouldn't the height of the div be set by the height of the image within it? So why is there that little bit of space at the bottom?
The gap is coming from the actual whitespace after the image tag. You can use this to fix it:
.card img {
display: block;
}
Fiddle
Or a more hacky solution:
.card {
font-size: 0;
}
Fiddle
I thinks the problem is the height of outer div, you cannot use auto since the browser may have some default action for the div and its inside content. Instead, I specify the percentage of height and solved the problem
.card {
width: 33.333%;
height: 50%;
overflow: hidden;
float: left;
background: black;
color: white;
}
Does that make sense to you?
I'm trying to create a div that will expand to 100% of the screen height when there is not enough content for it to do so normally, but will expand normally beyond that if there is enough content. If my div is called container, then whenever I use
#container
{
min-height: 100%;
}
it seems to have no affect on the height at all. When I use
#container
{
height: 100%;
min-height: 100%;
}
it sets the height to a fixed 100%, cutting off any content that would normally be past 100% of the screen height. I'm not sure what I'm doing wrong.
You can try
body, html {
height: 100%;
}
Borrowed from this answer. You can also refer this.
Fiddle
Maybe could you give us a JSfiddle of your HTML ? It would help us helping you.
I think you could use:
#container
{
height: 100%;
overflow: auto;
}
Or play around with position/float/clear.
Is there a way that I could set a DIV element to take up all the height on the page. Something like:
div.left {
height: 100%;
width: 50%;
background-color: blue;
position: absolute;
top: 0;
left: 0;
}
I've Google'd it a few times but they all seem like really really complicated work arounds for what is probably a really really simple problem with a simple solution.
If the div is a direct child of body, this works:
body, html {height: 100%; }
div { height: 100%; }
Otherwise, you have to keep adding height: 100% to each of it's parents, grandparents,... untill you've reached a direct child of body.
It's simple. For a percentage height to work, the parent must have a specified height(px, %... whichever). If it does not, then it's as if you've set height: auto;
Another way to do it is as you have in your answer: it's to give it an absolute position value, relative to the element that defines the page's height.
This is the simplest way to make a div take up the full height of a page.
height: 100vh;
vh is Viewport Height, and 1vh is equal to 1% of the height of the viewport. See here for more details on this and other units of measurement in CSS.
Make sure you set height: 100% to html and body so that the div has a context for height! Hope that helps.
Pretty sure you need to set the html and body to 100%:
html {
height: 100%;
}
body {
height: 100%;
}
div.left {
height: 100%;
}
Fiddle here.
This problem can be solved using CSS flexbox.
Go through the w3schools documentation of flexbox here and another helpful link css-tricks here
In this scenario.
put display: flex; in the parent div container
div.container{
height: 100%;
display: flex;
}
then in the child div put display: 1;
div.left{
height: 100%;
display: 1;
}
note that if the height of the parent div container is set dynamically, the child div will always have the same height as the parent.