Variable sizes on a fixed layout with scrolling - html

I've run into an issue with the page I'm working on. The basic idea of the page is it is a list of items and you click a row to go the a details page for that item, fairly straight forward. My issue is with the CSS.
Basically almost everything on the page is static (doesn't scroll) and just the stuff in the table scrolls (yes, I hid the scroll bar). I was able to accomplish this using a good bit of positin:fixed; but now I've got a problem.
Each category has its own page with a table (categories are the links on the left side). Some categories require extra buttons along the top, like a second row of blue pill buttons. The problem is that the second row of buttons makes the top area larger so the table has to be smaller. But, since most of the page is position:fixed; the size of the scrolling table is based on the sizes of the fixed regions around it using `height:calc(100vh - 170px);' But when there is a second row of buttons the 170px no longer works.
So here is the question: Is there a way to accomplish the scrolling behavior required via pure css with a variable sized row of buttons?
I've tried several things including flexbox but in the end I can't seem to get this to work without setting the height of the table body using the calc function.

It sounds like what you need is flexbox. You have a header section that determines the height of a content section, essentially. Flex columns with grow/shrink parameters accomplish this.
.container {
bottom: 0px;
display: flex;
flex-direction: column;
left: 0px;
position: absolute;
right: 0px;
top: 0px;
}
.container > .header {
background: yellow;
flex-shrink: 1;
}
.container > .content {
background: black;
color: white;
flex-grow: 1;
}
<div class="container">
<div class="header">
Header content<br>
This will keep expanding in height.
</div>
<div class="content">
The height of this black content box depends on the height of the header above.
</div>
</div>

Related

How to push other elements to the right using my sidebar?

I want to create a simple side-navigation that takes up the entire screen's height. I am using Milligram for my base, and I want my side-nav to work with it. I have the following set up:
Codepen demo
As you can see, my sidebar is the following element
<div class="sidebar"></div> with the following styles:
div.sidebar {
position: absolute;
width: 250px;
height: 100%;
z-index: 99;
background-color: black;
}
This sort of works, the sidebar appears above all else, but everything else does not get pushed to the side. And if the screen is small, the content clashes with the sidebar.
How can I make it so the sidebar pushes everything else (including the navbar) to the right by 250px(its width)? I know this will make things unusable on smaller screens, but I will give the user a way to toggle it.
Any help is appreciated.
You can set the left margin on your equal to the width of your sidebar.
section .container {
margin-left: 250px;
}

How to fix position of layer with CSS while maintaining minimum height?

I have a two column layout, where the left side consists out of a menu that should stick and the right side contains a long form. On the bottom of the page is a footer:
There are two problems with this:
If the browser window is smaller then the menu height, it is not possible to see the lower menu items as it is fixed and therefore does not scroll.
If one scrolls down the form to the bottom, the menu will hide the footer
My CSS looks like this:
#menu_side{
color:black;
background-color: #ffffff;
margin:67px 5px 5px 5px;
position: fixed;
width: 250px;
}
As an alternative mentioned inside the comments, one could use a container for the menu and use vh. Unfortunately this seems not to work as the inner elements simply outgrow the div. Illustrated in this img with a red border for the container:
How could I manage to keep the menu in sight of the user while he scrolls down the form and in the same time solve the mentioned 2 problems? Thank you for any help on this.
You should wrap #menu_side in a new container and let that container be fixed and make sure its height equals the viewport height. This can be done with vh units or with Javascript.
<div class="menu_container">
<div id="menu_side">
<!-- your menu -->
</div>
</div>
CSS:
.menu_container{
position: fixed;
height: 100vh;
width: 260px;
left: 0;
top: 0;
}
#menu_side{
margin:67px 5px 5px 5px;
}
As for your second issue: This can best be achieved using Javascript. You could for instance calculate the visible height of the footer element and use Javascript to calculate the appropriate height for .menu-container

Make div go to the bottom without overlapping previous div's content

I have the following example:
fiddle: http://jsfiddle.net/yisera/yLty3552/2/
Pen: http://codepen.io/yisera/pen/KpzbQp
Where I have a flex grid and I have elements that are also display:flex;. The problem I have is that the div.card has another div, div.od-card-action which has the actions of that card, comment, upvote, downvote. However, whenever the content of one of the cards is bigger than the others, they will stretch, making the card bigger to match the biggest one on that row.
This is a desired behaviour, but the problem is the div.od-card-action will also grow (I don't want this to happen) and make the elements seem out of order like it is shown on the first card in the fiddle.
I tried:
.od-card-action{
position: absolute;
bottom: 0;
width: 100%;
padding: 10px !important;
}
but this only makes the content from the upper div overlap with the content of the actions div.
Is there a way where I can make the div.od-card-action go all the way to the bottom regardless of the size of the card and maintain the same size (eg: 50px to say a value)?
Thanks in advance!
EDIT
Here's a picture demonstration what I want to accomplish:
See how everything is aligned horizontally despite the content of the above div not being of the same size? That's what I need to achieve.
I realised that as you're already using Flexbox in .od-card, then .card-content could be set to take as much space as possible (vertically, as the flex direction is column) using:
.card-content {
flex: 1;
}
Change the od-card-action CSS back to:
.od-card-action{
position: absolute;
bottom: 0;
width: 100%;
padding: 10px !important;
}
Add new css to card-content
.card-content{
margin-bottom:50px;
}

CSS and DIV with header and body with scrollable content, and fixed sidebar to right

I've been looking around all over, but I can't solve this, so I'm turning here.
I want to make a layout that looks like this:
The layout consists of three fields:
A header at the top with a fixed height, dynamic width, and vertically scrollable content.
Body below header, with dynamic width and height, with vertically scrollable content.
A sidebar to the right, with a fixed width, dynamic height, and no scroll. (This should remain fixed when you scroll the body content)
Dynamic height and/or width means it will resize with the window, not that it resizes with content.
If anything is unclear or there's any questions, I'll do my best to answer.
edit: one of my (very failed) attempts here: http://jsfiddle.net/uYTht/34/
html structure:
<body>
<div id="header">
header content
</div>
<div id="content">
body content
</div>
<div id="sidebar">
sidebar content
</div>
</body>
css code:
#header {
width: 100%;
height: 100px;
margin-right: 150px;
background-color: green;
overflow-y: scroll;
}
#content {
background-color: blue;
height: 100%;
overflow-y: scroll;
}
#sidebar {
position: absolute;
top: 0;
left: 100%;
margin-left: -150px;
width: 150px;
height: 100%;
float: right;
background-color: red;
overflow: hidden;
}
edit: David below helped me find the way. Basically what I had to use to make it work as I wanted was the calc()-function.
edit edit: Jack below came up with a solution that didn't use calc(), which I must say I prefer. Thank you all very much for the help!
I created a simple fiddle, that doesn't use calc (support isn't great - http://caniuse.com/calc, and then there's the big unknown of any performance penalty you may/may not hit using it..)
It's very straight forward, using simple CSS.
http://jsfiddle.net/ruYGH/3/
You can do this by using defined heights and widths for each of the elements with the overflow property.
To make a box scrollable (if the content doesn't fit inside):
overflow:auto;
To make a box not scrollable:
overflow:hidden;
Note that if the height and width are undefined, the element will grow to fit all of the contents.
I made a (not very pretty, but functional) example here:
JSFiddle
Edit:
You can make the sidebar a fixed width and adjust the other elements accordingly with calc:
.sidebar{
width: 200px;
}
.left{
width: calc(100% - 200px);
}
The JSFiddle has been updated to reflect this.
Style the divs with "overflow" to put the scroll bars where you want them and prevent them where you don't want them. You will also use overflow to specify what you want to happen to your content if it should happen to be too big to fit in your fixed width areas.
Chris Coyer is always a knowledgeable CSS resource
As far as the layout goes, it is a walk in the park if you use a two column table with rowspan="2" on the second column of the first row and only one column in the second row.
If you don't want to use tables (there is no good reason not to, but there are thousands of people that will look down on you if you do) then look at using divs with style="display: table...."
Once again Chris Coyer has an explanation
Thanks for the fiddle, your overflow css is working it is just that your header and content divs are 100% wide (full screen) and the scroll bars are conceptually under the sidebar. I need to sell you on using that table layout so that you can "dynamically" fix your dimensions so that the browser can know when to scroll instead of expanding the content down indefinitely to fit the size of the content instead of overflowing with the scroll bar.

Rows of flexible and fixed div's within full-size window

I'm writing a mobile/desktop chat application that is supposed to utilize the entire screen. The bottom <div> shown in yellow can be fixed-height if it needs to be.
presently it's Absolutely positioned to the bottom of the window.
My problem: the top <div>, in cyan, doesn't fit to the rest of the window, regardless of whether I use padding, margin, border, etc. Presently it appears to allow the content to wrap, but that's only because the bottom overwrites the scroll bar.
My only solution so far is to have a final <div> or <br> that pads the end of the scrollable div, but that doesn't make the div smaller, or make the scroll bars properly align.
Here is my source code so far in Fiddle.
Can you edit your CSS and set the DIV with the chat text a class like .break-word and then in CSS declare it with word-wrap:
.break-word {
word-wrap: break-word;
}
Unsure on the covering of scrollbars. You should post your code for others to view and might be able to pick something out.
This style code basically sums up what I'm doing to compensate for my issue. (Instead of, say, using HTML tables.) This may not be the best solution.
#topPart {
position: absolute;
width: 100%;
top: 0;
bottom: 40px; /* or however high the bottom is */
}
#bottomPart {
position: absolute;
width: 100%;
bottom: 0;
height: 40px; /* same as above */
}