I am wanting #homeContainer to have the full width of the page. A grandparent element is controlling the width and margin.
Below is the DOM. When I uncheck margin: 0 auto the full width is achieved. How can I control the .p-body-inner code for only code associated with #homeContainer?
.p-body
{
display: flex;
align-items: stretch;
flex-grow: 1;
min-height: 1px;
background: gray;
}
.p-body-inner
{
display: flex;
flex-direction: column;
width: 100%;
max-width: 1200px;
padding: 0 10px;
margin: 0 auto;
padding-left: 10px;
padding-right: 10px;
padding-top: 10px;
padding-bottom: 20px;
}
.p-body-main
{
display: table;
table-layout: fixed;
width: 100%;
margin-bottom: auto;
min-height: 1px; // IE11 workaround - related to #139187
}
#homeContainer {
width: 100vw;
height: 80vh;
background: red;
}
<div class="p-body">
<div class="p-body-inner">
<div class="p-body-main">
<section id="homeContainer">
Need full width of .p-body
</section>
</div>
</div>
</div>
Simply use percentage instead of VW it's because 100% is the entire width of the parent element. However, 100vw is the entire width of the window. Width of the window is more than the width of the element. Hence, the child element overflows out of the parent element.
.p-body
{
display: flex;
align-items: stretch;
flex-grow: 1;
min-height: 1px;
background: gray;
}
.p-body-inner
{
display: flex;
flex-direction: column;
width: 100%;
max-width: 1200px;
padding: 0 10px;
margin: 0 auto;
padding-left: 10px;
padding-right: 10px;
padding-top: 10px;
padding-bottom: 20px;
}
.p-body-main
{
display: table;
table-layout: fixed;
width: 100%;
margin-bottom: auto;
min-height: 1px; // IE11 workaround - related to #139187
}
#homeContainer {
width: 100%;
height: 80vh;
background: red;
}
<div class="p-body">
<div class="p-body-inner">
<div class="p-body-main">
<section id="homeContainer">
Need full width of .p-body
</section>
</div>
</div>
</div>
If this answer works for you then select this answer as the accepted answer to help others who checkout this question in furture.
Related
In below column flex layout, the top and bottom paddings has been defined for .Layout-MainContent (orange part):
<div class="Layout">
<div class="Layout-Header">
<div class="Layout-Header-DummyLogo"></div>
</div>
<div class="Layout-MainContent">
<div class="SignInForm">
<div class="SignInForm-DummyHeading"></div>
<div class="SignInForm-DummyInputField"></div>
<div class="SignInForm-DummyInputField"></div>
<div class="SignInForm-DummyInputField"></div>
</div>
</div>
</div>
html {
height: 100%;
}
body {
height: 100%;
overflow: hidden;
}
.Layout {
display: flex;
flex-direction: column;
height: 100%;
background: #FFF9C4;
}
.Layout-Header {
flex: 0 0 auto;
padding: 12px 8px;
background: #5C6BC0;
}
.Layout-Header-DummyLogo {
width: 100px;
height: 30px;
background: #303F9F;
}
.Layout-MainContent {
flex: 1 1 auto;
overflow-y: auto;
display: flex;
justify-content: center;
align-items: center;
padding: 24px 0 36px;
background: #FFCC80;
}
.SignInForm {
flex: 0 0 auto;
width: 320px;
border-radius: 8px;
padding: 32px 40px 20px;
background: #42A5F5;
}
.SignInForm-DummyHeading {
width: 100px;
height: 30px;
background: #1976D2;
}
.SignInForm-DummyInputField {
margin-top: 24px;
height: 30px;
border-radius: 4px;
background: #1976D2;
}
🌎 Fiddle
The first strange thing is bottom padding is not 36px as defined (update: looks like it's because of the JSFiddle console):
But this question topic is incorrect behavior on low viewports. I am expecting the vertical scrolling in .Layout-MainContent, but it's height must not become lower than natural (sum of paddings and children height). The real behavior is top and bottom paddings .Layout-MainContent are being completely ignored and also a part of .SignInForm has been truncated:
I know that flex: 1 1 auto; is contradicts to non-shinking requirement, but if we change to flex: 1 0 auto; the scrolling will completely disappear. How to keep both scrolling and minimal natural height if .Layout-MainContent
I need to make y-axis scrollable block inside left-navbar. And height of this block must fill all free space of the left-navbar. This way, that left-navbar height is 100% of the page and no more.
But history-overflow is not scrollable, and all history-item elements are shown, so they made all left-navbar height bigger than the page height.
Also, when page height shrinks, history-overflow should fill only free space to make left-navbar height not more than 100%. How to make this?
Codepen sandbox example:
https://codepen.io/car1ot/pen/zYqLqKB
HTML code:
<div className="left-navbar">
<div className="history">
<label>History</label>
<div className="history-overflow">
<div className="history-item">*...some content here...*</div>
*...more history-item(s) here...*
</div>
</div>
</div>
CSS (scss) code:
div.left-navbar {
display: flex;
flex-direction: column;
justify-content: space-between;
width: 290px;
height: 100%;
padding: 25px 20px;
box-sizing: border-box;
div.history {
display: flex;
flex-direction: column;
div.history-overflow {
margin-top: 8px;
margin-right: -20px;
padding-right: 14px;
overflow-y: scroll;
div.history-item {
display: flex;
align-items: center;
flex-shrink: 0;
padding: 0 16px 0 6px;
height: 40px;
width: 100%;
border-radius: 7px;
margin-bottom: 8px;
box-sizing: border-box;
}
}
}
}
If you set overflow: hidden to .history and max-height: 100vh to .left-navbar, I think it does what you want. Not sure in the context of your complete layout though (maybe you don't want to use 100vh but a different value there). The important part is that you have to limit the height somewhere.
If I correctly understan you, this is your solution:
body { padding:0; margin:0; }
div.left-navbar {
display: flex;
flex-direction: column;
justify-content: space-between;
width: 290px;
height: 100vh; /* This */
padding: 25px 20px;
box-sizing: border-box;
background: rgba(#000, 0.1);
div.history {
display: flex;
flex-direction: column;
height:100%; /* This */
div.history-overflow {
margin-top: 8px;
margin-right: -20px;
padding-right: 14px;
background: rgba(blue, 0.1);
overflow-y:scroll;
div.history-item {
display: flex;
align-items: center;
padding: 0 16px 0 6px;
height: 100px;
width: 100%;
border-radius: 7px;
margin-bottom: 8px;
box-sizing: border-box;
background: rgba(#000, 0.075);
}
}
}
}
I have an horizontal scrollbar class="filter_list" into a wrapper div class="wrapper". I want this scrollbar to be always 100% of the wrapper div and I want this wrapper div to be responsive.
It's working fine if I only have one item in my filter list but as soon as I put more than the wrapper width size, it's not responsive anymore.
Here are some pictures to illustrate the problem :
Responsive and working fine :
OK
The scrollbar is blocking the width of the wrapper that doesn't shrink to fit the dimension of the window (we can see that the picture of the girl is no longer it's 100% square size):
NOT OK
Here is the code :
body {
display: flex;
align-items: center;
justify-content: center;
}
.wrapper {
width: 800px;
display: flex;
justify-content: flex-start;
flex-direction: column;
align-items: center;
}
.magic_wand {
margin: 15px 0px 20px;
max-width: 50px;
}
.ico_magic_wand {
width: 100%;
height: 100%;
object-fit: contain;
}
.picture_preview {
width: 100%;
margin-bottom: 50px;
height: 100px;
}
.picture_preview img {
width: 100%;
height: 100%;
object-fit: contain;
}
.filter_list {
width: 100%;
background-color: blueviolet;
overflow-x: auto;
white-space: nowrap;
font-size: 0;
}
.filter:last-child {
margin-right: 0px;
}
.filter {
display: inline-block;
height: 150px;
width: 150px;
background-color: blue;
margin-right: 15px;
}
<body>
<div class="wrapper">
<div class="magic_wand">
<img src="img/ico/magic_wand.png" class="ico_magic_wand">
</div>
<div class="picture_preview">
<img src="https://images.unsplash.com/photo-1527514086375-0a7bae9089be">
</div>
<div class="filter_list">
<div class="filter">
</div>
<div class="filter">
</div>
<div class="filter">
</div>
<div class="filter">
</div>
</div>
</div>
</body>
I would like to understand why the div class="filter_list" width won't shrink with it's parent div while reducing the width of the window and how to fix the problem, thanks a lot !
Try this code.. I can't understand your question.. it may ur expectation,, else explain it clearly..
css
.filter {
display: inline-block;
height: 150px;
width: 21.3%;
background-color: blue;
margin-right: 15px;
}
.filter:nth-child(4n+4) {
margin-right: 0px;
}
Please remove ur css code and add this codes.. I think display:flex; is the issue for ur code..
body {
margin:0px;
}
img {
max-width: 100%;
height: auto;
}
.wrapper {
width: 800px;
margin: 0 auto;
text-align: center;
}
.magic_wand {
margin: 15px auto 20px;
max-width: 50px;
}
.picture_preview {
width: 100%;
margin-bottom: 50px;
height: 100px;
}
.picture_preview img {
height: 100%;
}
.filter_list {
width: auto;
background-color: blueviolet;
overflow-x: auto;
white-space: nowrap;
font-size: 0;
}
.filter:last-child {
margin-right: 0px;
}
.filter {
display: inline-block;
height: 150px;
width: 150px;
background-color: blue;
margin-right: 15px;
}
#media only screen and (max-width: 1024px) {
.wrapper {
width: 100%;
}
}
I want to fix div with class sidebar to the bottom of the container, but position: absolute with bottom:0 is not working with a container having display: flex.
how to solve that problem?
code: https://jsfiddle.net/zgmg48z1/1/
/*******************page layout**************************/
.container{
width: 100%;
background-color: #d5d5d5;
display: flex;
align-items: flex-start;
}
.sidebarcontainer{
width: 250PX;
/*height: 6000px;*/
display: inline-block;
box-sizing: border-box;
padding: 5px;
padding-right: 2px;
}
.innersidebarcontainer{
position: relative;
width: 100%;
height: 100%;
}
.sidebar{
width: 243px;
background-color: white;
height: 500px;
/*top: 1px;*/
/*bottom: 0;*/
/*position: absolute;*/
}
.mainpage{
width: calc(100% - 250px);
padding: 5px;
padding-left: 2px;
height: 600px;
display: inline-block;
box-sizing: border-box;
}
.page{
width: 100%;
height: 100%;
background-color: white;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
align-items: baseline;
align-content: flex-start;
}
.footer{
height: 500px;
width: 100%;
margin: 0 auto;
background-color: #031003;
}
/***************end of pagelayout******************/
.card{
width: 250px;
/*height: 400px;*/
align-self: flex-start;
margin: 10px;
display: inline-block;
}
.image{
width: 200px;
margin: 0 auto;
height: 250px;
}
.image img{
width: 100%;
height: 100%;
}
<div class="container">
<div class="sidebarcontainer">
<div class="innersidebarcontainer">
<div class="sidebar">
</div>
</div>
</div><!--
--><div class="mainpage">
<div class="page">
<h1>something in the page</h1>
</div>
</div>
</div>
<div class="footer"></div>
Try this:
.sidebarcontainer{
/*OTHER STUFF*/
align-self: flex-end;
}
Explanation here: https://css-tricks.com/snippets/css/a-guide-to-flexbox/#article-header-id-14
"This allows the default alignment (or the one specified by align-items) to be overridden for individual flex items."
If you want the sidebar to be at the bottom of the container, you can use align-self: flex-end on the sidebar container.
In this case you don't have to use an absolute position on your sidebar. But i'm not sure that's what your trying to do, maybe you need to have a 100% height (of the container) sidebar container and to align bottom the content of the sidebar. If you need that you can set an height on your sidebar container and a relative position. Then use position: absolute and bottom: 0 on the sidebar child.
/*******************page layout**************************/
.container{
width: 100%;
background-color: #d5d5d5;
display: flex;
align-items: flex-start;
}
.sidebarcontainer{
width: 250PX;
/*height: 6000px;*/
display: inline-block;
box-sizing: border-box;
/* Add align-self: flex-end to the sidebar-container */
align-self: flex-end;
padding: 5px;
padding-right: 2px;
}
.innersidebarcontainer{
position: relative;
width: 100%;
height: 100%;
}
.sidebar{
width: 243px;
background-color: white;
height: 500px;
/*top: 1px;*/
/*bottom: 0;*/
/*position: absolute;*/
}
.mainpage{
width: calc(100% - 250px);
padding: 5px;
padding-left: 2px;
height: 600px;
display: inline-block;
box-sizing: border-box;
}
.page{
width: 100%;
height: 100%;
background-color: white;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
align-items: baseline;
align-content: flex-start;
}
.footer{
height: 500px;
width: 100%;
margin: 0 auto;
background-color: #031003;
}
/***************end of pagelayout******************/
.card{
width: 250px;
/*height: 400px;*/
align-self: flex-start;
margin: 10px;
display: inline-block;
}
.image{
width: 200px;
margin: 0 auto;
height: 250px;
}
.image img{
width: 100%;
height: 100%;
}
<div class="container">
<div class="sidebarcontainer">
<div class="innersidebarcontainer">
<div class="sidebar">
</div>
</div>
</div><!--
--><div class="mainpage">
<div class="page">
<h1>something in the page</h1>
</div>
</div>
</div>
<div class="footer"></div>
This exact same problem happened to me recently. In my case it wasn't the fault of flex or even the positioning at all in the end, turns out I had another class that was cascading down and also effecting the element's absolute position making it look like my new values weren't working.
I have used CSS flex to display two divs side by side which are contained inside a wrapper and I have been trying so that inside #myClippetWrapper is where I set the height, so in the child elements of #myClippetWrapper I can just set height: 100%;.
But as you can see from running the snippet below all of the elements inside #myClippetWrapper go outside of the main section, they are all hanging out of the main content div?
I don't want to use overflow: auto because I do not want a scroll bar there, I just need the child elements of #myClippetWrapper to not be outside of the main section/ div.
main {
margin: 0 auto;
margin-top: 10px;
margin-bottom: 10px;
padding: 8px;
background-color: red;
width: 100%;
max-width: 50%;
height: auto;
}
#myClippetWrapper {
display: flex;
height: 700px;
}
#clippetNav {
padding: 10px;
width: 250px;
height: 100%;
background-color: #222222;
margin-right: 10px;
}
#codeAndNotesWrapper {
display: flex;
width: 100%;
}
#codeAndNotesWrapper>div {
flex-basis: 100%;
height: 100%;
}
#codeView {
padding: 10px;
/*flex: 0 0 40%;*/
height: 100%;
background-color: #222222;
margin-right: 10px;
}
#noteView {
padding: 10px;
/*flex: 1;*/
height: 100%;
background-color: #222222;
}
#codeNotesEditor {
height: 100%;
background-color: #EAEAEA;
}
<main>
<div id="myClippetWrapper">
<div id="clippetNav">
</div>
<div id="codeAndNotesWrapper">
<div id="codeView">
</div>
<div id="noteView">
<div id="codeNotesEditor">
</div>
</div>
</div>
</div>
</main>
In many cases, flexbox eliminates the need to use percentage heights.
An initial setting of a flex container is align-items: stretch. This means that in flex-direction: row (like in your code) flex items will automatically expand the full height of the container.
Alternatively, you can use flex-direction: column and then apply flex: 1 to the children, which can also make a flex item expand the full height of the parent.
main {
max-width: 50%;
margin: 10px auto;
padding: 8px;
background-color: red;
}
#myClippetWrapper {
display: flex;
height: 700px;
}
#clippetNav {
display: flex;
padding: 10px;
width: 250px;
margin-right: 10px;
background-color: #222222;
}
#codeAndNotesWrapper {
display: flex;
width: 100%;
}
#codeAndNotesWrapper>div {
display: flex;
flex-basis: 100%;
}
#codeView {
display: flex;
padding: 10px;
margin-right: 10px;
background-color: #222222;
}
#noteView {
display: flex;
flex-direction: column;
padding: 10px;
background-color: #222222;
}
#codeNotesEditor {
flex: 1;
background-color: #EAEAEA;
}
<main>
<div id="myClippetWrapper">
<div id="clippetNav"></div>
<div id="codeAndNotesWrapper">
<div id="codeView"></div>
<div id="noteView">
<div id="codeNotesEditor"></div>
</div>
</div>
</div>
</main>
jsFiddle
Add
box-sizing: border-box;
To your child elements. This will make the padding show on the inside of the box rather than the outside and will not increase the overall size.
Add the box-sizing property..
* {
box-sizing: border-box;
}
main {
margin: 0 auto;
margin-top: 10px;
margin-bottom: 10px;
padding: 8px;
background-color: red;
width: 100%;
max-width: 50%;
height: auto;
}
#myClippetWrapper {
display: flex;
height: 700px;
}
#clippetNav {
padding: 10px;
float: left;
width: 250px;
height: 100%;
background-color: #222222;
margin-right: 10px;
}
#codeAndNotesWrapper {
display: flex;
width: 100%;
}
#codeAndNotesWrapper>div {
flex-basis: 100%;
height: 100%;
}
#codeView {
padding: 10px;
/*flex: 0 0 40%;*/
height: 100%;
background-color: #222222;
margin-right: 10px;
}
#noteView {
padding: 10px;
/*flex: 1;*/
height: 100%;
background-color: #222222;
}
#codeNotesEditor {
height: 100%;
background-color: #EAEAEA;
}
<main>
<div id="myClippetWrapper">
<div id="clippetNav">
</div>
<div id="codeAndNotesWrapper">
<div id="codeView">
</div>
<div id="noteView">
<div id="codeNotesEditor">
</div>
</div>
</div>
</div>
</main>
A big factor with setting your
display: flex;
Is padding and height can make a nasty couple;
Take this example into account:
display: flex;
height: 100%;
padding-top: 1vh;
This would essentially make your element the pages height, plus 1% of the view height, and of course give you a child element thats taller than its parent element.
This isn't a direct answer to your question, instead one to people looking here for why their child elements may be acting up.