Row with 3 columns of fixed and flexible widths - html

I need to create three columns in a row where the right item has a min-width: 300px and the middle item has a fixed width of 595px. The left item has to use the rest of the width! I've tried to use flexbox and table cell but the left container seems to exceed the screen width which causes bottom scrollbar to appear, which is not wanted in this case.
<div class="row">
<div class="column left">
</div>
<div class="column middle">
</div>
<div class="column right">
</div>
</div>
.row {
width: 100%;
& .column {
&.left {
}
&.middle {
width: 595px !important;
}
&.right {
min-width: 300px;
}
}
}

Based on your requirements, you're going to get a horizontal scrollbar when the screen width is less than 895px. That's the length of your width: 595px and min-width: 300px containers.
.row {
display: flex;
height: 100px;
}
.left {
flex: 1; /* consume remaining space */
background-color: aqua;
}
.middle {
flex: 0 0 595px; /* equivalent to width: 595px; flex-grow, flex-shrink, flex-basis */
background-color: orange;
}
.right {
min-width: 300px;
background-color: lightgreen;
}
<div class="row">
<div class="column left"><code>flex: 1</code></div>
<div class="column middle"><code>width: 595px</code></div>
<div class="column right"><code>min-width: 300px</code></div>
</div>
jsFiddle demo

Related

How a sub container can be larger in width than the main one on top of the html hierarchy

I want to style a sub container and make it larger in width than the main one on top of the html structure that force not to exceed the width set for the first container. Which css property should i use for this case? thank you
I tried using max-width property but still not solving the problem
On the content element use
margin-left: calc(A - B);
where
A = 1/2 width of the container
B = 1/2 width of the content
Follow a code Example of 3 nested content of different dimensions.
HTML:
<div class="page-wrapper">
<div class="container container 1">
<p>Container 1 - width: 600px</p>
<div class="content content-1">Content 1: width: 800px</div>
</div>
</div>
<div class="page-wrapper">
<div class="container container 2">
<p>Container 2</p>
<div class="content content-2">Content 2 - width: 160%</div>
</div>
</div>
<div class="page-wrapper">
<div class="container container 3">
<p>Container 3</p>
<div class="content content-3">Content 3 - width: 1024px</div>
</div>
</div>
Code example CSS:
.page-wrapper {
width: 1024px;
display: flex;
align-items: center;
justify-content: center;
border: solid 1px #000000;
padding: 20px 0;
}
.container {
width: 600px;
height: 300px;
background: #FF0066;
text-align: center;
}
.content {
height: 200px;
background-color: #666666;
box-sizing: border-box;
max-width: 100vw; /* do not exceed the viewport width; */
}
.content-1 {
width: 800px;
margin-left: calc(50% - 400px); /* this center the content */
}
.content-2 {
width: 160%;
margin-left: calc(50% - 80%); /* this center the content */
}
.content-3 {
width: 1024px;
margin-left: calc(50% - 512px); /* this center the content */
}
The working codepen here: https://codepen.io/Davevvave/pen/XWBepBM

Force child div to stretch so the parent div captures 100% of screen's height

I have the following html layout:
<div class="wrapper">
<div class="row one">
<div class="col one"><!-- some content here --></div>
<div class="col two"><!-- some content here --></div>
</div>
<div class="row two"><!-- some content here --></div>
</div>
So I have two rows (content and footer) and the first row has two columns.
The footer's (row two) height is not set and is defined from it's content.
How can I force my content area (row one) to stretch so the entire wrapper div takes 100% of screen's height?
Some indicative (not working) css here:
.wrapper {
display: inline-block;
width: 100%;
height: 100%;
}
.row.one {
width: 100%;
display: flex;
}
.row.two {
width: 100%;
}
.row.one .col.one {}
.row.one .col.two {}
Setting the height of the wrapper to the height of the viewport, and then stretching the flexbox contents (column... not row) vertically has always worked well for me.
.wrapper {
display: flex;
flex-flow: column nowrap;
align-items: stretch;
height: 100vh;
width: 100vw; /* or whatever */
}
.row {
flex: auto;
width: 100%;
...
}
Try this:
.wrapper {
display: inline-block;
height: 100vh;
width: 100%;
}
.row.one {
display: flex;
height: 100%;
}
.row.two {
}
.row.one .col.one {}
.row.one .col.two {}
css viewheight will achieve what you want.
100vh applied to .row.one makes the div occupy the full visible height.
.row.one {
background: pink;
height: 100vh;
}
<div class="wrapper">
<div class="row one">
<div class="col one">some content here </div>
<div class="col two">some other content here </div>
</div>
<div class="row two">footer content</div>
</div>

Nested Flexbox with horizontal overflow

I am using a nested flexbox layout.
I would like a left nav to always be 1/3rd of the page, and the right side always be 2/3rds.
The left nav should always stay in view.
The right side (an image carousel in my case) should always take up 2/3rds and have a horizontal scrollbar on the boxes.
In the code below, it simply stretches and ignores the overflow.
<div>
Top Header (should stay in view)
</div>
<div style="display: flex">
<div style="flex: 1 0 auto">
LeftNav
</div>
<div style="flex: 2 0 auto">
<div style="display: flex; flex-direction: row; overflow-x: scroll">
<div style="background-color: blue; min-width: 400px; height: 500px">
</div>
<div style="background-color: red; min-width: 400px; height: 500px">
</div>
<div style="background-color: green; min-width: 400px; height: 500px">
</div>
</div>
</div>
Instead of flex-grow, which simply distributes free space in the container, use flex-basis, which explicitly sizes your items 1/3 and 2/3.
Then, because the default minimum width of flex items is min-width: auto, meaning they cannot be smaller than the size of their content, use min-width: 0 to override that default on the carousel.
<div>
Top Header (should stay in view)
</div>
<div style="display: flex">
<div style="flex: 0 0 33%">LeftNav</div>
<div style="flex: 0 0 67%; min-width: 0;">
<div style="display: flex; flex-direction: row; overflow-x: scroll">
<div style="background-color: blue; min-width: 400px; height: 500px">
</div>
<div style="background-color: red; min-width: 400px; height: 500px">
</div>
<div style="background-color: green; min-width: 400px; height: 500px">
</div>
</div>
</div>
First, I've moved your styles to classes. Don't use inline CSS.
flex CSS property is shorthand for setting flex: [flex-grow] [flex-shrink] [flex-basis].
You can set fixed percentage to your flex-basis values and zeros to flex-grow and flex-shrink to avoid flex items growing and shrinking.
Also you show move scroll CSS to your right nav block.
*,
*:before,
*:after {
box-sizing: border-box;
}
.main-container {
display: flex;
}
.left-nav {
flex: 0 0 calc(100% / 3); /* One third width */
}
.right-nav {
flex: 0 0 calc(200% / 3); /* Two third width */
overflow-x: scroll;
}
.right-nav-container {
display: flex;
}
.right-nav-item {
min-width: 400px;
height: 500px
}
.right-nav-item:nth-child(1) {
background-color: blue;
}
.right-nav-item:nth-child(2) {
background-color: red;
}
.right-nav-item:nth-child(3) {
background-color: green;
}
<div>
Top Header (should stay in view)
</div>
<div class="main-container">
<div class="left-nav">
LeftNav
</div>
<div class="right-nav">
<div class="right-nav-container">
<div class="right-nav-item">
</div>
<div class="right-nav-item">
</div>
<div class="right-nav-item">
</div>
</div>
</div>
</div>

Make div in div in div scrollable with overflow

I have an React application and having a slightly bigger problem with some CSS stuff.
I have an view which is divided in 2 parts. But those two parts are lying in one bigger component. The left part is displaying some contacts and on the right I want to display details of those contacts. Now I want to make the left part scrollable like a list, but the right part just stay fixed on its position. Also the height of the left part should always stay as high as the current screen size. I am using Bulma CSS as my base CSS framework.
This is my HTML:
<div class="pane main-content" id="mainPane">
<div class="contacts-view">
<h1 class="title">My Title</h1>
<div class="">Other Stuff</div>
<div class="columns">
<div class="column is-3">
<div class="columns is-multiline">
<div class="column"></div>
<div class="column"></div>
<div class="column"></div>
</div>
</div>
<div class="column is-9"></div>
</div>
</div>
</div>
This is a quick sketch of how it looks:
Current relevant CSS:
.main-content {
background-color: #fff;
padding: 20px;
}
.pane {
position: relative;
overflow-y: auto;
flex: 1;
}
.columns {
margin-left: -0.75rem;
margin-right: -0.75rem;
margin-top: -0.75rem;
}
.column {
display: block;
-ms-flex-preferred-size: 0;
flex-basis: 0;
-webkit-box-flex: 1;
-ms-flex-positive: 1;
flex-grow: 1;
-ms-flex-negative: 1;
flex-shrink: 1;
padding: 0.75rem;
}
For better explanation. The component with class column is-3 should be scrollable but all other parts should stay fixed with no scroll.
I tried:
.is-3
overflow:hidden;
overflow-y:scroll;
But I found out that I have to set the height of is-3 because otherwise my screen is just expanded to the bottom. But I can not set a fixed height to it, because my screen size is dynamic and depended on the size of #mainPane. But I can also not set it to 100% because then the screen is also expanded at the bottom. Do you have any suggestions how I can solve this with CSS ?
Thanks in advance :)
You can use flexbox layout.
jsFiddle
body {
margin: 0;
}
.container {
height: 100vh;
display: flex;
flex-direction: column;
}
.header {
background: lightblue;
}
.content {
flex: 1;
display: flex;
min-height: 0; /*ADDED 2021*/
}
.sidebar {
background: lightgreen;
overflow: auto;
}
.main {
flex: 1;
background: pink;
overflow: auto;
}
<div class="container">
<div class="header">header</div>
<div class="content">
<div class="sidebar">
<div style="height:200vh;">sidebar</div>
</div>
<div class="main">
<div style="height:200vh;">main</div>
</div>
</div>
</div>

Having an issue with div layout positioning

I have been fighting with this for a while, I'm trying to make a specific setup and I've gotten so frustrated at it I've resorted to using tables (very bad). So what I'm trying to do:
5 divs.
1 on the right side of the screen, ~120px width, 100% of the page
height
1 in the bottom left of the page, 120px height, 120px width
1 above that one, 120 width, all remaining height
in the middle between these 1 div on the top, with height of 80px,
and width filling between the other divs
and the last div in the middle taking up all remaining space
Any solution I have come up with required at least some JS, which I am doing everything I can to avoid, so I am looking for a purely CSS3 solution!
You could do it using HTML5 and CSS3 using display flex
Something I quickly mocked up http://codepen.io/tom-maton/pen/mbJAs
HTML:
<div class="main">
<div class="left">
<div class="top-left-column">Top left</div>
<div class="bottom-left-column"> bottom left</div>
</div>
<div class="center">
<div class="center-top-column">Top Center</div>
<div class="center-bottom-column">Bottom center</div>
</div>
<div class="right">
<div class="right-column">Right Column</div>
</div>
</div>
CSS:
div {
border: 1px solid #333;
}
.main {
border: 0;
display: flex;
flex-direction: row;
height: 100vh;
}
.top-left-column {
height: calc(100vh - 120px);
width: 120px;
}
.bottom-left-column {
height: 120px;
width: 120px;
}
.center {
display: flex;
align-content: stretch;
flex-direction: column;
flex: 1 1 0;
}
.center-top-column {
height: 80px;
}
.center-bottom-column {
height: calc(100vh - 80px);
}
.right-column {
height: 100vh;
width: 120px;
}
You just need to check your browser support beforehand as flex not supported in IE8/9