I cannot get my list to be full height. My code is more complicated with nested components. But I can still get this to replicate using this code. Here is a plunk. http://plnkr.co/edit/R0QgLz8cjyRHYOLf4uJW
styles.css
html, body {
min-height: 100%;
height: auto;
margin: 0;
}
app.component.css
.container {
height: 100%;
background: black;
color: white;
list.component.css
.row {
display: flex;
flex-direction: row;
}
.list {
width: 33%;
height: 100%;
flex-direction: column;
display: flex;
border-right: groove white 1px;
border-top: groove white 1px;
}
.item {
width: auto;
height: 100%;
flex-direction: column;
display: flex;
}
list.component.html
<div class="contents">
<button (click)="updateDocuments()">Update Document</button>
<div class="row">
<div class="list">
<div *ngFor="let document of documents; let i = index;">
{{i + 1}}. {{document}}
</div>
</div>
<div class="item">
this is an item
</div>
</div>
</div>
I got this to work by switching to height 100vh and also adding a overflow-y: scroll css attribute to the list and item classes.
http://plnkr.co/edit/R0QgLz8cjyRHYOLf4uJW
styles.css
html, body {
min-height: 100vh;
height: auto;
margin: 0;
}
app.component.css
.container {
height: 100vh;
background: black;
color: white;
list.component.css
.row {
display: flex;
flex-direction: row;
}
.list {
width: 33%;
height: 100vh;
flex-direction: column;
display: flex;
border-right: groove white 1px;
border-top: groove white 1px;
overflow-y: scroll;
}
.item {
width: auto;
height: 100vh;
flex-direction: column;
display: flex;
overflow-y: scroll;
}
list.component.html
<div class="contents">
<button (click)="updateDocuments()">Update Document</button>
<div class="row">
<div class="list">
<div *ngFor="let document of documents; let i = index;">
{{i + 1}}. {{document}}
</div>
</div>
<div class="item">
this is an item
</div>
</div>
</div>
try to write this css
.container{
min-height:100vh;
}
Had the same issue, and found that the best solution was:
html, body {
min-height:100vh;
height: auto;
}
and for the container:
.container{
min-height: 100vh;
}
Use position: fixed if that's acceptable:
.container {
position:fixed;
background: black;
color: white;
height: 100%;
}
Hi everyone who faced this problem
Just go to global css file, it has the comment
/* You can add global styles to this file, and also import other style files */
written in it. Add
*{margin:0; padding:0}
that's it
Somewhere in the Internet:
The reason for this issue is concealed in the way a browser interprets
the host element, which doesn’t know it’s an HTML element at all and
so the browser sets the default display value (inline) for the host
element.
So probably it's enough just to redefine again "display" property for "host" tag (add in your component code) :
host: {
display: flex; /*or whatever is fit your needs*/
}
try in your style.css
html, body {
height: 100%;
margin: 0;
}
Related
I have a component with a router-view inside it that can display a flexbox. I've tried several different solutions to flex-boxes not scrolling properly and they all either result in no scrolling, or scrolling, but it doesn't quite reach the bottom (the last element in the v-for ends up getting cut off.)
Here is the template and relevant styles for the router view
<template>
<div class="modal" ref="modal">
<div class="modalcontent" ref="content">
<p class="goback" #click="closeAnimation" ref="goback">←</p>
<div class="title">
<h1>Questions & Answers</h1>
</div>
<div class="routerview">
<router-view :posts="posts" v-slot="{ Component }">
<transition name="slide-in" mode="out-in">
<component :is="Component" />
</transition>
</router-view>
</div>
</div>
</div>
</template>
<style>
.routerview {
position: relative;
width: 80%;
margin: auto;
overflow-y: scroll;
left: 0;
right: 0;
outline: 10px red;
}
</style>
and for the flexbox:
<template>
<div class="container">
<div class="flex-container" ref="flexcontainer">
<div class="question" v-for="post in posts" :key="post._id" #click="this.$router.push(`/forum/question/${post._id}`)">
<h1 class="qTitle">{{ post.title }}</h1>
<p class="qReplyAmt">{{ post.replies.length }} repl<span v-if="!plural(post.replies.length)">y</span><span v-else>ies</span></p>
</div>
</div>
<p>You've reached the end</p>
</div>
</template>
<style scoped>
.question {
width: 98%;
height: fit-content;
min-height: 0;
background-color: whitesmoke;
border-radius: 10px;
padding: 10px 10px 2px 15px;
cursor: pointer;
transition: all 200ms ease-out;
}
.question:hover {
background-color: rgb(255, 107, 107);
color: white;
}
.qTitle {
display: block;
}
.qReplyAmt {
position: relative;
top: -5px;
}
.flex-container {
display: flex;
align-items: center;
flex-direction: column-reverse;
width: 100%;
gap: 15px;
flex: 1;
}
</style>
I've tried:
setting a height on .container, .routerview, .flex-container
setting overflow-y to auto & scroll on .container, .routerview, .flex-container
and a bunch of other answers i've found on how to fix flexboxes not scrolling
I fixed the issue. Here is the updated styles:
.flex-container {
display: flex;
align-items: center;
justify-content: space-between;
flex-direction: column-reverse;
width: 100%;
gap: 15px;
flex: 1;
margin-top: auto;
margin-bottom: 125px;
}
.container {
overflow-y: scroll;
height: 100vh;
}
I added the .container styles to make it actually scroll and added margin-bottom: 125px; to fix the issue with the last item being cut off.
I want to have a container that includes an image and a caption.
The container should always be the same size, the caption height might change.
In my mind the caption should get the auto height, depending on it’s size and the rest of the containers height will be allocated to the image.
I tried doing that with a div and i worked flawlessly. When I exchange the placeholder div with an actual image tag, the image will take the 100% height of the container, not of its allocated flex space in the container.
Why is that and how can I fix it?
Example showing the difference between div and image tag:
https://codepen.io/lkssmnt-the-lessful/pen/QWqbxNK?editors=1100
.project {
height: 500px;
width: 500px;
display: flex;
flex-direction: column;
}
.project img {
height: 100%;
width: 100%;
object-fit: cover;
}
Add overflow: hidden to the .img tag. - This has the negative effect of snipping the bottom of the image off, however.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.wrapper {
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
.project {
height: 500px;
width: 500px;
border: 5px solid red;
margin: 1rem;
display: flex;
flex-direction: column;
}
.project p {
padding: 1rem;
}
.project img {
overflow: hidden;
height: 100%;
width: 100%;
object-fit: cover;
}
.project .test {
height: 100%;
width: 100%;
background: beige;
}
<div class="wrapper">
<div class="project">
<div class="test"></div>
<p>Project 1</p>
</div>
<div class="project">
<img src="https://images.unsplash.com/photo-1518676590629-3dcbd9c5a5c9?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=987&q=80">
<p>Project 2</p>
</div>
</div>
Sorry, another flexbox related question :)
I have two flex elements :
A container (red) containing a centered div (yellow)
A footer (blue) with an undefined height
The red container has a flex-grow:1 attribute, forcing it to take the remaining space on the screen
The issue happens when the yellow element is bigger than the screen size. I would like my red container to grow based on its content. Any idea of how I could do that ?
HTML:
<div class="container">
<div class="content"></div>
</div>
<div class="footer"></div>
CSS:
body,
html {
margin: 0;
height: 100%;
display: flex;
flex-direction: column;
}
.container {
flex-grow: 1;
display: flex;
align-items: center;
justify-content: center;
background: red;
}
.content {
background: yellow;
height: 2000px;
width: 100px;
}
.footer {
flex-shrink: 0;
height: 50px;
background-color: blue;
}
https://codepen.io/stepinsight/pen/roRVGQ
== EDIT ==
Andre helped me find the answer, thanks heaps !
The only thing you need to change in the code above is to replace height by min-height and the % by vh for the body/html tags 🎉
body,
html {
margin: 0;
min-height: 100vh;
display: flex;
flex-direction: column;
}
Simply remove the height property on the body element and add height: 100% to html
* { box-sizing: border-box; }
html {
height: 100%
}
body {
display: flex;
flex-direction: column;
margin: 0;
padding: 0;
}
.container {
display: flex;
align-items: center;
justify-content: center;
background: red;
}
.content {
background: yellow;
height: 2000px;
width: 100px;
}
.footer {
height: 50px;
background-color: blue;
}
Corrected: https://codepen.io/ferreirandre/pen/maoVvb
Feel free to play around with the height of .content
i have doing my portfolio but i'm not good with CSS.
I'm using the Flexbox to do the design desktop and mobile but it not working...
It is like this, as i want, using flex-direction: column,:
Code of the div parent:
display: flex;
justify-content:center;
align-items:center;
background-color:#C4C4C4;
min-height: 100vh;
flex-direction: column;
But when i put in responsive, it stay like this:
The elements outside of div parent..
The code is the same, only changes the background-color.
background-color: red;
width:800px;
height:650px;
margin: 30px;
It not stay corrects.
If i dont use the flex-direction: column, it stay like this:
Someone why?
Your main issue was missing max-width: 100%; in the children so the width:800px would not overflow the container parent, take a look at the snippet
section {
display: flex;
justify-content: center;
align-items: center;
background-color: #C4C4C4;
min-height: 100vh;
padding: 15px 30px;
box-sizing: border-box;
}
#media(max-width:800px) {
section {
flex-direction: column;
}
}
div {
max-width: 100%;
width: 800px;
height: 650px;
margin: 15px
}
div:first-of-type {
background-color: red;
}
div:last-of-type {
background-color: blue
}
<section>
<div>red</div>
<div>blue</div>
</section>
max-width not set the width of the children elements.
Make sure you set a width to all of your containers; it looks like you want the gray container to fill the viewport, and the blocks to be evenly distributed.
Here's a working example:
.container {
display: flex;
flex-direction: column;
justify-content: space-evenly;
align-items: center;
text-align: center;
background-color: gray;
width: 100vw;
height: 100vh;
}
.block {
background-color: #C4C4C4;
min-height: 33vh;
width: 90vw;
}
<div class="container">
<div class="block" style="background-color: red">
A
</div>
<div class="block" style="background-color: blue">
B
</div>
</div>
I need the .content div use all the available space
body {
height: 100%;
}
.nav {
padding: 20px;
}
.content {
height: 100%;
}
<body>
<div class="nav">nav</div>
<div class="content">content</div>
</body>
Since I don't know the height of the .nav I can't use height: calc(100%-Xpx)
is there any other way to make .content use the remaining height of the page?
Thanks
Use min-height: 100vh on body, then set the parent (body in this case) to display: flex; flex-direction: column and use flex-grow: 1 on .content for it to use the available space.
body {
min-height: 100vh;
display: flex;
flex-direction: column;
margin: 0;
}
.nav {
padding: 20px;
}
.content {
flex-grow: 1;
background: #eee;
}
<div class="nav">nav</div>
<div class="content">content</div>