react split pane shows above other components when using `display: flex` - css

For my new react project I need a split pane.
I am using https://github.com/tomkp/react-split-pane for this.
After I implemented everything, I wanted to my header above so it would look like this.
So I added the header to my root component.
render() {
return (
<div className='App'>
<h1>This is my heading</h1>
<SplitPane split='vertical' minSize={50} defaultSize={100}>
<div>split 1</div>
<div>split 2</div>
</SplitPane>
</div>
);
}
}
Just like this without any css it gave me nearly a correct result. And the only problem here is that the split pane seems to take 100vh as its height and therefore the overall application is bigger. Which gives me the nice scroll bar, which I don't want.
My next idea was to just put everything into css grid (I know that it probably isn't the best use case but at least I would know there how to solve the sizing problem) and then resize it using the relative units.
The css I added to my main component is.
.App {
display: grid;
grid-template-rows: auto 1fr;
}
This change didn't get me the effect I wanted it to. Instead of neatly stacking everything it somehow put the split pane above the header.
I thought that I did something wrong with css grid, so I applied display: flex; which gave me the same problem.
I don't really know what the problem here is, so I'm curious if anybody had encountered such a problem before.

SplitPane source code
Add this to your .App selector:
.App {
position: relative;
}
Also, if you want the widths of both panes to be exactly half, change your SplitPane component to this:
<SplitPane split="vertical" minSize="50%" defaultSize="50%">
Unfortunately, there is a problem where the panes stops resizing and the application goes out of bounds at very small widths.
In response to:
SplitPane shrinking down to a size where it's not really
usable even though the height is set to 100%.
Content inside SplitPane is not visible/usable because:
SplitPane has the property height: 100%. This means SplitPane's height is 100% of its parent's height.
SplitPane has the property overflow: hidden. This will hide any content that exceeds SplitPane's dimensions.
Since SplitPane's height = .App's height = h1's height and the height for h1 was about 30-40px, SplitPane's height was also about 30-40px. This meant any child of SplitPane with a height greater than 30-40px had its content cut off.
SplitPane is most likely calculating how much to offset itself from the top by calculating the total height of its preceding siblings.
So, now we know SplitPane's CSS properties look like this:
{
position: absolute;
top: 0 || /* auto-calculated by SplitPane */;
left: 0 || /* auto-calculated by SplitPane */;
overflow: hidden;
height: 100%; /* total height of preceding siblings */
...
}
Your next steps would be to decide on how you would like your application to look and function and make choices based on your decision. To start:
Do you want your navigation bar fixed to the top of the viewport?
How would you like to handle excess content inside of the panes if you don't want a scroll bar?
Is your website mobile-friendly? If so, how would you like to display the split panes on small screens?
In response to:
How do I change to position: relative while assigning all space below the header to the split view?
Some possible solutions would be to use Javascript or possibly Sass/SCSS/Less to set the total height of SplitPane equal to the viewport's height minus how much SplitPane was offset from the top.
It is hard to give a definitive answer because I do not know how you want to handle viewing content that exceeds 100vh without a scroll bar.
In response to:
[I] can't use display: grid or flex since it would still overwrite the header.
Flexbox/Grid isn't working because SplitPane isn't living in the same space as its siblings. You'd have to overwrite SplitPane's position property to static.
CodePen
.App {
display: flex; /* Introduce Flexbox */
/* This is added to change the orientation of elements from
left-right (row) to top-bottom (column). */
flex-direction: column;
}
<SplitPane ... style={{ position: "static" }}>
Next steps
The only thing I can recommend at this stage is to add height: 100vh and width: 100vw to .App.

Related

Cant make inline-flex column take 100% height of screen

I cant seem to give my parent div a 100% height due to the fact that the React app div is not extending.
i have 3 children to the main Div which is class named as side-bar-container. I want the middle child to flex grow and take up all space and i did provide it a flex grow of 1 and others of 0 but the problem is there is no room to grow as shown in the picture.
edit: sorry i edited the question no react code is present im just trying to explain my issue
You'd want to utilize the entire screen height on your parent container. You have 2 options:
Apply 100vh on the App class, and then ensure your side-bar-container spans 100% height.
.App {
height: 100vh;
}
.side-bar-container {
height: 100%;
}
Apply 100vh on side-bar-container.
.side-bar-container {
height: 100vh;
}

Layout, where many containers need to take up rest of space but one inner scroll. CSS

I have a problem that I have spent many hours on and could not find a solution in any way. I will link the code in CodePen. It is just a subset of my layout. This is the reason for some of the root element's styling.
I basically have a layout where the page/screen/window should not have a scroll, but the inner body of the table widget should, when there are enough elements that go beyond the expected area of the table.
Basically I have a top content on the page, and a table widget. The table widget is to take up the rest of the space of the screen. The table has a title and a header. The body is to take up the rest of the table space and to have a scroll when it has elements that go beyond that space.
I have searched many resources over stack-overflow and tried many things. I will provide the current state of the layout in the pen. Here you can see all that I think is my best try.
https://codepen.io/anon/pen/KLogbJ
The central area of interest is the .body element. Based on things I've read I have styled it:
.body {
display: flex;
flex-direction: column;
flex: 1;
overflow: auto;
padding: 0.5rem;
min-height: 0;
}
I would appreciate any help on this.
You could add overflow: scroll; to .body and give the .item a min-height
Also give your .table a max-height: 100%;
See this fiddle
The problem is that the contents of the area you want to scroll is set to scale to fit it's container. For the internal scroll you are looking for you would need to have:
A set height for the container so it won't expand to fit the content (in this case you want it to be 100% of the screen)
The content must not scale in height to fit it's container. It has to maintain it's height so that it remain larger than it's container.
If you have those 2 conditions you should find the scroll bars appear.

How to set div height depending on screen height minus the height of an absolutely positioned element?

I have a panel with a height of 100vh, so 100% of the screen (but height: 100% doesn't work, for some reason).
This panel must show a div with its own contents and the footer.
The footer is normally displayed under that panel, but in the front page it must be inside it, so I have to disable the normal one and call it inside the panel.
Thus, it must have position: absolute and bottom: 0.
Now the problem is that the footer takes its own height (which changes a bit when resizing the window's width), and the other div in the panel must take all the remaining height.
So, is there a way to set that div's height dynamically, rather than filling the CSS with media queries for each window width where the footer's height changes, setting it as height: calc(100vh - [footer height])?
Firstly, if you don't set height for parent elements, setting height in percentages on the child won't work. Your parent elements should have their height set to 100% (including html and body elements).
Secondly, if your browser support is IE10+, I recommend using flexboxes.
Here's how you do it (without browser prefixes):
.parent-container {
height: 100%;
display: flex;
flex-direction: column;
}
This will set the parent container as flexbox and change its direction to "column" (so its children stack one under the other).
.expanding-child {
height: 100%;
flex-basis: 0;
flex-shrink: 1;
flex-grow: 1;
}
This is the wrapper for your content. It will expand as much as it can, keeping in mind your footer's height.
.sticky-child {
flex-basis: auto;
flex-shrink: 0;
flex-grow: 0;
}
This is your footer that will now always be at the bottom, pinned, without overlapping the scrollable content.
Here is what your HTML would look like:
<div class="parent-container">
<div class="expanding-child">
</div>
<div class="sticky-child">
</div>
</div>
And I made a quick fiddle to demonstrate it here
This will work as intended only if you set height to 100% on all parent elements.
Edit: here is a good source to learn more about flexbox, I recommend looking into it. And here is one I used when I first started using flexbox.
I think you are asking about sticky footer. I hope it will helps you. Always footer fixed at bottom using FlexBox
Fiddle

Expanding the parent container with 100% height to account for floated content

I'm struggling with a client project. All of my divs have no absolute positioning, height:100% for html, body, and container divs, and yet the static-content stops short of its contents (at 910px).
I can change the overflow property to auto, and the background will continue down to the end of the content, but it adds a scroll bar, and the bottom border of the static-content div stays in the same place (at 910px).
UPDATE: Development link was no longer valid, so I removed it. Suffice to say that Animuson's thorough explanation is the valuable part of this thread, and solved the problem of containers not expanding to match their content. – Ty
You used the wrong overflow-y property for clearing, and you should set a min-height instead of a regular height. Try this:
#static-content {
background-color: #FFFFFF;
margin: 0 auto;
min-height: 100%; /* Set to minimum height so overflow doesn't get hidden */
overflow-y: hidden; /* HIDE overflow; I know, it doesn't make much sense */
position: relative;
width: 960px;
}
Floating Content by Itself
Given this green box which has a padding of 20px (for visibility), notice how a single red box floated to the left will expand past the boundary of its parent box. This is because floating content doesn't actually take up any "space" in the visual area. All other elements will expand underneath it, and only text will wrap around it.
Clearing Floated Content in the Parent
In order to counter this and make the green box completely encompass the area of its child red box, we can add overflow: hidden to its styles. This will expand the box down far enough.
Expanding the Parent to 100% Height
You might think that just adding height: 100% is the simplest way to make it expand to where it needs to be.However, the height property specifies an absolute height. Since the content which is floated does not actually take up any vertical space, our overflow: hidden property will cut off all the content that goes past the parent's height.
Using a Minimum Height Instead
Since we want it to expand to at least a 100% height, we can use the min-height property to force it there and still maintain the "automatic" height needed to make the parent green box fully encompass the child red box, letting it push past the 100% only when it needs too.
How You Were Set Up
All elements, by default, are set to overflow: visible so that property didn't really change anything. The only difference you had between this and the first example I provided was that you had a height: 100% set on the element. So the parent was expanding to 100% height but still not encompassing the full height of its child red box.
If you have to use overflow:visible for some reason, there's other way to force container to stretch to contain all floated content. You have to put element with clear:both as a last container's elements. If you ignore ancient IEs (<8) you can do it with very simple css (vide https://css-tricks.com/snippets/css/clear-fix/):
.your-container:after {
content: "";
display: table;
clear: both;
}
If height: 100% doesn't work well for you, you can try this calc function from CSS3:
/* Firefox */
height: -moz-calc(100%);
/* WebKit */
height: -webkit-calc(100%);
/* Standard */
height: calc(100%);
You can try this either with height, or with min-height, as already said. You can with this calc functions also other calculations like:
height: -moz-calc(100% - 50px);
And this is sometimes very useful, as you might guess.
height:100% is the height of the content that flows with your container at hand and is not taking into account your floated content, so that is why the height of your container is stopping short. Remove it and clear your container properly to clear your floated elements within and it will work:
#static-content:before, #static-content:aftr {
display:table;
content:"";
}
#static-content:after {
clear:both;
}
#static-content {
zoom:1; /*ie fix*/
}
You have a float in static-maincontent, which removes it from the regular flow of the content of the document, and hence static-content doesn't care about its height any more, and so won't expand to cover it.
Additionally, remove height:100% for static-content.
READ FOR ANSWER!!!-- Okay so I had the same problem, All that was needed was to remove the "Positioning" Style. Should work perfectly fine.

div width in css

i have a div on a web page that basically acts as a panel container. i want it to:
have a minimum width of 1000px; So no matter how small the content inside the div is, it will at least keep the panel to 1000px in width:
in terms of max width, it should keep going as big as the content within it. So if a person has a 24 inch monitor and they want to maximize the browser it should keep growing until the content inside doesn't have any scroll bars and then stop.
needs to work in all browsers.
how would i do this in css?
Assuming this item is a block element (i.e. "display: block"), it should scale automatically as wide as its containing element (in this case the browser window).
In CSS, just specify "min-width: 1000px." This will work in IE8+ and all modern browsers.
try this
#panel {
min-width: 1000px;
diplay: block;
overflow: hidden; }
Try this:
#panel
{
/* Other styles */
min-width:1000px;
/*width:100%; - removed as it will create horizontal scrollbar if margin and padding aren't 0 as per Josh's comment.*/
}
However, you will problems with older browsers like IE6 which do not like the min-width thingy in which case you will need to use JavaScript.

Resources