Flexbox one long and short columns - html

I'm trying to implement a layout like this:
On a narrower screen it look like this:
here is my code so far:
.cont {
display: flex;
flex-direction: column;
flex-wrap: wrap;
height: 500px;
}
.cell{
border: 2px solid black;
}
.cell-1 {
flex-basis: 100%;
width: 70%;
margin-right: 25px;
}
.cell-2,
.cell-3 {
width: 30%;
}
#media (max-width: 1000px) {
.cont{
flex-wrap: nowrap;
}
.cell {
width: 100%;
}
.cell-1, .cell-2, cell-3 {
width: 100%;
}
.cell-1 {
order: 2;
}
.cell-2 {
order: 1;
}
.cell-3 {
order: 3;
}
<div class="cont">
<div class="cell cell-1">
<h2>One</h2>
</div>
<div class="cell cell-2">
<h2>Two</h2>
</div>
<div class="cell cell-3">
<h2>Three</h2>
</div>
</div>
The problem is that I need to set height to the .cont in order for columns to wrap in a widescreen mode, and I can't do that due to the variable content size. For example if I had only 2 small paragraphs in cell-1 and a height of 500px that would lead to footer being too far below from .cont. Or if I had to many content in cell-1 and a height: 500px, it would lead to content inside .cont go under footer.
What would you suggest to solve this problem?
codepen

You can "easily" achieve it with grid:
.cont {
display: grid;
grid-template: 'content side-1' 'content side-2';
grid-template-columns: 7fr 3fr;
grid-column-gap: 1em;
}
.cell-1 {
grid-area: content;
}
.cell-2 {
grid-area: side-1;
}
.cell-3 {
grid-area: side-2;
}
#media(max-width: 768px) {
.cont {
grid-template: 'side-1' 'content' 'side-2'
}
}
<div class="cont">
<div class="cell cell-1">
<h2>One</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Sem viverra aliquet eget sit amet. Viverra nibh cras pulvinar mattis nunc. Ut pharetra sit amet aliquam id diam maecenas. Nunc eget lorem dolor sed viverra. Congue quisque egestas diam in arcu cursus euismod quis. Non quam lacus suspendisse faucibus interdum posuere lorem. Iaculis urna id volutpat lacus laoreet non curabitur gravida. Tincidunt praesent semper feugiat nibh sed pulvinar proin gravida hendrerit. Quis eleifend quam adipiscing vitae proin sagittis nisl. In pellentesque massa placerat duis ultricies lacus. Curabitur vitae nunc sed velit dignissim sodales.
<p>Congue quisque egestas diam in arcu cursus euismod quis. Non quam lacus suspendisse faucibus interdum posuere lorem. Iaculis urna id volutpat lacus laoreet non curabitur gravida. Tincidunt praesent semper feugiat nibh sed pulvinar proin gravida hendrerit. Quis eleifend quam adipiscing vitae proin sagittis nisl. In pellentesque massa placerat duis ultricies lacus. Curabitur vitae nunc sed velit dignissim sodales.
</div>
<div class="cell cell-2">
<h2>Two</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Sem viverra aliquet eget sit amet. Viverra nibh cras pulvinar mattis nunc.
</div>
<div class="cell cell-3">
<h2>Three</h2>
<p>Non quam lacus suspendisse faucibus interdum posuere lorem. Iaculis urna id volutpat lacus laoreet non curabitur gravida. Tincidunt praesent semper feugiat nibh sed pulvinar proin gravida hendrerit.
</div>
</div>

Related

Two column layout - content one colulmn centered but the other column top aligned to the top of the centered content

I'm looking for a way to create this two column layout, the content on the right is centred horizontally and vertically but the content on the left is centred horizontally and vertically aligned with the top of the content in column twos as the length of the content in column two changes the content in column one always stays aligned to the top.
Please take a look at the image attached as this is easier to explain visually
This can't just be a padded box because as the content on the right grows the padding reduces to stay centered, and the main columns need to stay a min height
Updated layout image
Based on Кольо Пеев answer below I've modified my codepen
https://codepen.io/nitrokev/pen/RwMQZeJ
<div class="fifty-fifty-project-details-grid">
<article class="fifty-fifty-content left lightblue">
<div class="entry-content" >
<h3>Content 1</h3>
</div>
</article>
<article class="fifty-fifty-content right" >
<div class="entry-content" >
<h3>Content 2</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In enim lorem, sollicitudin ut accumsan in, porta sed dui. Sed sagittis est risus, ac luctus odio porta at. Vivamus at nibh et mi euismod sagittis et sed justo. Nulla pretium pellentesque eros, vel aliquam elit egestas eu. Aliquam erat lorem, tristique sit amet est eu, elementum porta augue. Morbi consequat magna felis, placerat convallis nisl placerat a. Nullam porttitor suscipit metus a condimentum. Nunc eleifend ex sed tristique tempus. Nunc elementum ligula nec pulvinar mattis. Aenean tincidunt, odio in congue iaculis, ipsum quam hendrerit velit, id commodo mauris ante rhoncus odio. Sed eget nibh vitae ipsum consectetur porta sit amet eget ante. Donec ultricies lacinia ultricies. Nullam id porttitor leo. Quisque sit amet nisl ultrices sapien aliquet gravida. Nam auctor mi ut orci dictum, sit amet tempor metus eleifend. Donec rhoncus et justo ac sollicitudin. </p>
</div>
</article>
</div>
.fifty-fifty-project-details-grid {
display: flex;
flex-flow: row wrap;
overflow: hidden;
min-height:45rem;
}
.fifty-fifty-content {
display: flex;
flex-flow: row wrap;
align-items: center;
flex: 0 0 auto;
width: 50%;
margin-left: 0;
margin-right: 0;
height: auto;
padding:3rem;
}
.left{
background-color:#52AACB;
}
.right{
background-color:#52CB8F;
}
I think if there was a way to calculate the current height of the content in column two and apply it to column one, that might work?
Try running this code snippet. I am not fully aware of what you expect since there is no real content given anywhere from your side, but maybe with a few more lines of CSS you can achieve what you desire.
.container {
min-height: 400px;
background-color: #52CB8F;
display: grid;
}
.container__parent {
display: grid;
grid-template-columns: 1fr 1fr;
align-self: center;
}
.container__child {
padding: 16px;
background-color: #555;
text-align: center;
color: #fff;
}
.container__child:first-child {
border: 1px solid red;
}
.container__child:last-child {
border: 1px solid blue;
}
<div class="container">
<div class="container__parent">
<div class="container__child">
test string
</div>
<div class="container__child">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Facilisis mauris sit amet massa vitae tortor condimentum lacinia quis. Aliquet enim tortor at auctor. Facilisi etiam dignissim diam quis enim lobortis. Eget nulla facilisi etiam dignissim diam quis enim. Amet nisl suscipit adipiscing bibendum est ultricies integer. Id aliquet lectus proin nibh. Interdum consectetur libero id faucibus. Ornare lectus sit amet est placerat in egestas erat imperdiet. Felis imperdiet proin fermentum leo vel. Arcu dui vivamus arcu felis bibendum ut. Amet luctus venenatis lectus magna fringilla urna. Lobortis elementum nibh tellus molestie. Nibh praesent tristique magna sit amet purus gravida. Odio facilisis mauris sit amet massa vitae. Vel quam elementum pulvinar etiam non quam lacus suspendisse faucibus. Orci phasellus egestas tellus rutrum.
</div>
</div>
</div>

Making outer columns of flexbox sticky

I have content on page and I would like to make both sidebars to be sticky, something like:
I am using flex:
<div className="homePageFeed">
<div className="homePageFeedWrapper">
<HomePageFeedMenu/>
<HomePageFeedContent/>
<HomePageFeedUtil/>
</div>
</div>
.homePageFeed{
position: relative;
width: 100%;
}
.homePageFeedWrapper{
display: flex;
align-items: center;
position: relative;
height: 100%;
padding-left: 22px;
padding-right: 16px;
z-index: 30;
flex-direction: row;
}
Other components, left-sidebar:
const HomePageFeedMenu = () => {
return (
<div className="homeFeedMenu">
<ol>
<li> Mammals</li>
<li> Lizards</li>
<li> Birds</li>
<li> Spiders</li>
</ol>
</div>
)
}
export default HomePageFeedMenu;
.homeFeedMenu{
flex: 10 0 0;
width: 100%;
height: 500px;
border-right: 1px solid hsl(210,8%,35%);
}
ol{
list-style: none;
}
li{
color: hsl(210,8%,35%);
margin: 0;
}
Scrollable content ( with test item in it ):
const HomePageFeedContent = () => {
return (
<div className="homeFeedContent">
<div className="homeFeedItem">
<div className="content">
<div className="homeFeedItemTitle"><p>Animal name</p></div>
<div className="homeFeedItemContent">
Animal description
</div>
<div className="homeFeedItemMetaInfo">Age and adoption info</div>
</div>
<div className="img">Animal picture</div>
</div>
</div>
)
}
.homeFeedContent{
padding-top: 25px;
flex: 70 0 0;
width: 100%;
border-right: 1px solid hsl(210,8%,35%);
display: flex;
justify-content: center;
flex-direction: column;
align-items: center;
}
.homeFeedItem{
width: 90%;
height: 200px;
display: flex;
margin-top:25px;
flex-direction: row;
justify-content: center;
border-bottom: 1px solid hsl(210,8%,35%);;
}
.content{
flex: 80 80 0;
display: flex;
flex-direction: column;
}
.img{
flex: 20 20 0;
width: 100%;
height: 100%;
border: 1px solid black;
}
.homeFeedItemTitle{
width: 100%;
flex: 20 20 0;
}
.homeFeedItemContent{
width: 100%;
flex: 60 60 0;
border-bottom: 1px hsl(210,8%,35%);;
}
.homeFeedItemMetaInfo{
width: 100%;
flex: 20 20 0;
}
export default HomePageFeedContent;
And right static sidebar
const HomePageFeedUtil = () => {
return (
<div className="homeFeedUtil">
</div>
)
}
export default HomePageFeedUtil;
.homeFeedUtil{
flex: 20 0 0;
width: 100%;
height: 500px;
}
Now I am trying to use sticky positioning for both sidebars, however, it does not work as they are part of the flexbox. I would also like to fix their height, as you can see I attempted to use 500px, hover when the middle flex element gets lots of element and the site become scrollable, it readjusts the position of both sidebars ( as they have fixed height ) and thus their content does not appear on top of it "column".
Are there any tricks to use both, flex and sticky positioning? Or do I need to do it without flex?
Thanks for the help!
I'd not use flexbox. I'd use position: sticky for the top then position: fixed for each sidebar. Use css variables to work out the width of the scrollable area. Here's an example:
body {
box-sizing: border-box;
margin: 0;
}
.main-container {
--header-height: 50px;
--header-gap: 0.5rem;
--sidebar1-width: 200px;
--sidebar2-width: 100px;
--sidebar-gap: 0.5rem;
}
.sticky-header {
position: sticky;
height: var(--header-height);
background-color: lightblue;
border: 1px solid blue;
top: 0;
z-index: 1;
}
.sticky-sidebar1 {
position: fixed;
top: var(--header-height);
left: 0;
width: var(--sidebar1-width);
height: calc(100vh - var(--header-height));
background-color: lightgreen;
border: 1px solid darkgreen;
}
.sticky-sidebar2 {
position: fixed;
top: var(--header-height);
right: 0;
width: var(--sidebar2-width);
height: calc(100vh - var(--header-height));
background-color: lightpink;
border: 1px solid darkred;
}
.scrollable-content {
border: 1px solid red;
padding: 0.25rem;
overflow: hidden;
margin-left: calc(var(--sidebar1-width) + var(--sidebar-gap));
margin-right: calc(var(--sidebar2-width) + var(--sidebar-gap));
margin-top: var(--header-gap);
}
#media only screen and (max-width: 600px) {
.main-container {
--sidebar1-width: 100px;
--sidebar2-width: 0px;
}
}
<div class='main-container'>
<div class="sticky-header">Sticky Header</div>
<div class="sticky-sidebar1">Sticky Sidebar1</div>
<div class="sticky-sidebar2">Sticky Sidebar2</div>
<div class="scrollable-content">
<h1>Scrollable Content</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore
magna aliqua. In eu mi bibendum neque egestas congue quisque egestas. Adipiscing enim eu turpis egestas
pretium.
Accumsan sit amet nulla facilisi morbi tempus iaculis urna id. In massa tempor nec feugiat nisl. Mattis nunc
sed
blandit libero volutpat sed. Magna ac placerat vestibulum lectus mauris ultrices eros in. Senectus et netus et
malesuada fames ac turpis egestas. Tincidunt nunc pulvinar sapien et ligula ullamcorper malesuada. Vel elit
scelerisque mauris pellentesque pulvinar. Egestas egestas fringilla phasellus faucibus scelerisque eleifend
donec pretium. Tristique risus nec feugiat in fermentum posuere urna nec tincidunt. Lectus vestibulum mattis
ullamcorper velit sed. Risus ultricies tristique nulla aliquet enim tortor at auctor. Vitae congue mauris
rhoncus aenean vel elit scelerisque mauris pellentesque. Lacus suspendisse faucibus interdum posuere lorem
ipsum
dolor. Suspendisse interdum consectetur libero id. Vestibulum lorem sed risus ultricies tristique nulla
aliquet.
Nunc eget lorem dolor sed viverra ipsum nunc. Diam sit amet nisl suscipit adipiscing bibendum est.
Diam phasellus vestibulum lorem sed risus ultricies tristique. Ultrices sagittis orci a scelerisque. Iaculis
at
erat pellentesque adipiscing commodo elit at imperdiet dui. Donec enim diam vulputate ut pharetra sit.
Fringilla
urna porttitor rhoncus dolor purus. Turpis massa tincidunt dui ut ornare lectus. Et netus et malesuada fames
ac
turpis egestas maecenas pharetra. Malesuada nunc vel risus commodo viverra maecenas. Purus sit amet volutpat
consequat mauris nunc. Vel fringilla est ullamcorper eget nulla. Duis ultricies lacus sed turpis tincidunt id
aliquet risus. Arcu ac tortor dignissim convallis aenean et. Elementum nibh tellus molestie nunc non blandit
massa.
Magna sit amet purus gravida quis. Amet tellus cras adipiscing enim eu turpis egestas pretium aenean. Sagittis
nisl rhoncus mattis rhoncus urna neque. Feugiat scelerisque varius morbi enim nunc faucibus. Parturient montes
nascetur ridiculus mus mauris vitae ultricies leo. Enim nulla aliquet porttitor lacus luctus accumsan tortor
posuere. Rhoncus aenean vel elit scelerisque mauris pellentesque. Velit aliquet sagittis id consectetur purus.
Id porta nibh venenatis cras sed felis eget velit aliquet. Mattis nunc sed blandit libero. Suspendisse in est
ante in. Duis at tellus at urna condimentum mattis. Consequat semper viverra nam libero justo laoreet sit amet
cursus.
Sed turpis tincidunt id aliquet risus feugiat. Aliquam purus sit amet luctus. Suspendisse faucibus interdum
posuere lorem. Cursus turpis massa tincidunt dui ut ornare. Donec ultrices tincidunt arcu non sodales. Tellus
integer feugiat scelerisque varius morbi enim nunc faucibus. Leo integer malesuada nunc vel risus. Ut pharetra
sit amet aliquam id diam. Condimentum vitae sapien pellentesque habitant morbi tristique. Vestibulum lectus
mauris ultrices eros. Aenean sed adipiscing diam donec adipiscing tristique risus. Nulla aliquet porttitor
lacus
luctus accumsan tortor. Semper feugiat nibh sed pulvinar. Placerat in egestas erat imperdiet sed.
Pulvinar pellentesque habitant morbi tristique senectus et netus. Vitae turpis massa sed elementum tempus
egestas sed. Aliquam sem et tortor consequat id porta nibh venenatis cras. Orci dapibus ultrices in iaculis
nunc
sed augue lacus. Blandit turpis cursus in hac habitasse platea. Volutpat blandit aliquam etiam erat velit
scelerisque. Massa ultricies mi quis hendrerit dolor magna eget est lorem. Lectus sit amet est placerat. Eu mi
bibendum neque egestas congue. Dictum non consectetur a erat nam at. Facilisis magna etiam tempor orci eu
lobortis. Sit amet venenatis urna cursus eget nunc. Sed risus pretium quam vulputate dignissim suspendisse.
Vivamus at augue eget arcu dictum. Ultricies tristique nulla aliquet enim tortor. Gravida neque convallis a
cras
semper auctor neque.
Malesuada pellentesque elit eget gravida cum sociis natoque penatibus. Est lorem ipsum dolor sit amet. Tempor
orci dapibus ultrices in iaculis nunc. Lorem ipsum dolor sit amet consectetur adipiscing. Volutpat diam ut
venenatis tellus in metus vulputate eu. Sed nisi lacus sed viverra tellus. Penatibus et magnis dis parturient.
Ipsum consequat nisl vel pretium lectus quam. Mollis aliquam ut porttitor leo a diam. Cras sed felis eget
velit.
Euismod lacinia at quis risus. Neque viverra justo nec ultrices dui. Pellentesque habitant morbi tristique
senectus et netus et. Pharetra vel turpis nunc eget lorem dolor. Ac auctor augue mauris augue neque gravida
in.
</p>
</div>
</div>
For the result you are looking for you would need to use position: fixed; in your css for all 3 elements you want to be fixed;
For your top header it would be something like:
#enterIDhere {
position: fixed;
top: 0;
left: 0;
right: 0;
width: 100%;
margin: 0 auto;
}
For your left sidebar it would be something like:
#EnterIDhere {
position: fixed;
left: 0;
bottom: 0;
}
and last but not least your right sidebar would need something like:
#EnterIDhere {
position: fixed;
right: 0;
bottom: 0;
}

What to do if justify content space between doesn't work

When I try to use justify-content: space-between, it won't work, and I'm assuming that it may be because I don't have space left for this to work. What can I do instead of this?
This is what happens:
However I want it to look like this:
HTML:
<div class = "container">
<main role = "main">
<div class = "group">
<img src = "izonebg.jpg" alt = "group" class = "groupbg">
</div>
<div class = "content-wrapper content-flex">
<div class = "about">
<p id = "aboutiz">ABOUT</p>
</div>
<div class = "info">
<p id = "about-content">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla gravida metus fermentum pulvinar eleifend. Aenean condimentum, sapien dapibus interdum porttitor, arcu eros congue enim, sed fermentum erat urna non mi. Duis sed volutpat ex. Vestibulum sit amet fringilla purus. Vivamus ut ipsum sed diam finibus sollicitudin ac lacinia velit. Pellentesque ultrices odio non ante suscipit, nec ullamcorper nulla interdum. Morbi facilisis cursus pharetra. Fusce finibus interdum ligula. Aenean ac sodales velit, eget ullamcorper ante. Duis metus elit, elementum in sollicitudin non, fringilla eu enim. Quisque pharetra orci in odio efficitur, sit amet lacinia quam imperdiet. In tempor pellentesque eros vel semper. Nam neque nibh, posuere eu euismod a, elementum vitae dolor.</p>
</div>
</div>
</main>
</div>
CSS:
body{
margin: 0;
font-size: 1.125rem;
font-weight: 400;
}
.container{
width: 100%;
}
.groupbg{
width: 100%;
top: 0;
left: 0;
}
#aboutiz{
font-family: Kiona;
font-size: 4em;
font-weight: 500;
}
.content-wrapper{
width: 85%;
margin: 0 auto;
}
.content-flex{
display: flex;
justify-content: space-between;
}
#about-content{
font-family: Acid;
font-size: 1.75em;
}
<div class="section-wrap"> <!-- flex container -->
<div class="heading"><!-- flex item -->
<span class="head">about</span></div>
<div class="description-wrapper"><!-- flex item -->
<p class="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla gravida metus fermentum pulvinar eleifend. Aenean condimentum, sapien dapibus interdum porttitor, arcu eros congue enim, sed fermentum erat urna non mi. Duis sed volutpat ex. Vestibulum sit amet fringilla purus. Vivamus ut ipsum sed diam finibus sollicitudin ac lacinia velit. Pellentesque ultrices odio non ante suscipit, nec ullamcorper nulla interdum. Morbi facilisis cursus pharetra. Fusce finibus interdum ligula. Aenean ac sodales velit, eget ullamcorper ante. Duis metus elit, elementum in sollicitudin non, fringilla eu enim. Quisque pharetra orci in odio efficitur, sit amet lacinia quam imperdiet. In tempor pellentesque eros vel semper. Nam neque nibh, posuere eu euismod a, elementum vitae dolor.</p>
</div>
</div>
.section-wrap {
display: flex;
justify-content: space-between;
width: 550px;/* try to reduce a flex width container,
see what happens, flex container need some space sometimes */
}
.heading {
width: 100px;
background: orange;
}
.description-wrapper {
background: black;
color: white;
}
.content {
width: 400px;
}
There was extra margins applying to the About and the content. Hence the difference. Please check the below example where I have removed extra margins.
.container{
width: 100%;
}
.groupbg{
width: 100%;
top: 0;
left: 0;
}
#aboutiz{
font-family: Kiona;
font-size: 4em;
font-weight: 500;
margin: 0;
padding-right: 10px;
}
.content-wrapper{
width: 85%;
margin: 0 auto;
}
.content-flex{
display: flex;
justify-content: space-between;
}
#about-content{
font-family: Acid;
font-size: 1.75em;
margin: 0;
}
<div class = "container">
<main role = "main">
<div class = "group">
<img src = "izonebg.jpg" alt = "group" class = "groupbg">
</div>
<div class = "content-wrapper content-flex">
<div class = "about">
<p id = "aboutiz">ABOUT</p>
</div>
<div class = "info">
<p id = "about-content">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla gravida metus fermentum pulvinar eleifend. Aenean condimentum, sapien dapibus interdum porttitor, arcu eros congue enim, sed fermentum erat urna non mi. Duis sed volutpat ex. Vestibulum sit amet fringilla purus. Vivamus ut ipsum sed diam finibus sollicitudin ac lacinia velit. Pellentesque ultrices odio non ante suscipit, nec ullamcorper nulla interdum. Morbi facilisis cursus pharetra. Fusce finibus interdum ligula. Aenean ac sodales velit, eget ullamcorper ante. Duis metus elit, elementum in sollicitudin non, fringilla eu enim. Quisque pharetra orci in odio efficitur, sit amet lacinia quam imperdiet. In tempor pellentesque eros vel semper. Nam neque nibh, posuere eu euismod a, elementum vitae dolor.</p>
</div>
</div>
</main>
</div>
Using CSS grid would be better to use and set gutters for the desired gaps.
The main structure of the page should be consistent between pages, flexbox could cause gaps and widths to change page to page based on its content and CSS grid can help with that.
Try to only use Flexbox for smaller elements like a collection of buttons or pills together and CSS grid for Structure.
justify-content: space-between; is nt working because, there is no space between about and content. Make them display: flex and set flex-grow to 1 and adds a flex-basis: 0. These two properties makes the div to grow from a minimum value of 0%. Ths will make both of the element to consume 50% of container width. And make the UI look like the requirement.
body {
margin: 0;
font-size: 1.125rem;
font-weight: 400;
}
.container {
width: 100%;
}
.groupbg {
width: 100%;
top: 0;
left: 0;
}
.about, .info {
display: flex;
flex: 1;
}
#aboutiz {
font-family: Kiona;
font-size: 4em;
font-weight: 500;
}
.content-wrapper {
width: 85%;
margin: 0 auto;
}
.content-flex {
display: flex;
justify-content: space-between;
}
#about-content {
font-family: Acid;
font-size: 1.75em;
}
<div class="container">
<main role="main">
<div class="group">
<img src="izonebg.jpg" alt="group" class="groupbg">
</div>
<div class="content-wrapper content-flex">
<div class="about">
<p id="aboutiz">ABOUT</p>
</div>
<div class="info">
<p id="about-content">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla gravida metus fermentum
pulvinar eleifend. Aenean condimentum, sapien dapibus interdum porttitor, arcu eros congue enim, sed
fermentum erat urna non mi. Duis sed volutpat ex. Vestibulum sit amet fringilla purus. Vivamus ut ipsum sed
diam finibus sollicitudin ac lacinia velit. Pellentesque ultrices odio non ante suscipit, nec ullamcorper
nulla interdum. Morbi facilisis cursus pharetra. Fusce finibus interdum ligula. Aenean ac sodales velit,
eget ullamcorper ante. Duis metus elit, elementum in sollicitudin non, fringilla eu enim. Quisque pharetra
orci in odio efficitur, sit amet lacinia quam imperdiet. In tempor pellentesque eros vel semper. Nam neque
nibh, posuere eu euismod a, elementum vitae dolor.</p>
</div>
</div>
</main>
</div>

The height of inner divs in a flexbox child

We've been looking all over the web, but can't find a solution to a seemingly unsolvable problem basically we've got two divs who need to be equal in height. In them we've got multiple other divs who need to scale in height with them.
We tried 100% height, flexbox, inherit, overflow hidden and other things we could think of. To no avail.
This is a simplistic view of what we've got:
.col-sm-12 {
width: 100%;
display: flex
}
.col-sm-6 {
width: 50%;
float: left;
flex: 1;
}
.c1 {
}
.c2 {
padding: 20px;
}
.c3 {
border: 1px solid grey;
padding: 20px;
}
.image {
width: 100%;
height: 300px;
background-color: grey;
}
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div class="col-sm-12">
<div class="col-sm-6">
<div class="c1">
<div class="c2">
<div class="image">
</div>
<div class="c3">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean consectetur dui quis arcu varius, sit amet consectetur risus auctor. Nulla id mattis ligula. Aliquam euismod dui et viverra ultrices. Praesent eget quam quam. Aenean sit amet lectus et leo ultrices sodales id sed nulla. Proin fringilla, dui vitae tincidunt tincidunt, nisi tellus efficitur lacus, ac facilisis libero elit ut tellus. In finibus tortor leo, hendrerit sagittis libero maximus sed. Sed rhoncus maximus odio, nec vestibulum enim fringilla ac. Nulla faucibus, justo nec fermentum blandit, est nisl eleifend purus, non pretium orci sapien at eros. Fusce non laoreet augue. Aenean ac eros augue. Sed sit amet enim sit amet lorem finibus volutpat. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris placerat, diam sed vulputate aliquet, augue erat luctus massa, molestie egestas diam metus at dolor. Vivamus a metus vitae magna dignissim pulvinar.
</p>
</div>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="c1">
<div class="c2">
<div class="image">
</div>
<div class="c3">
<p>
Etiam id ullamcorper augue, a pharetra nisi. Sed justo enim, malesuada elementum erat non, vehicula varius turpis. Sed quis scelerisque eros, in vestibulum mi. Maecenas et consectetur risus, sed sagittis ex. Aliquam vestibulum fermentum hendrerit. Nulla eget hendrerit purus. Suspendisse commodo vel tortor ut sollicitudin.
</p>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
How can we get the two boxes below the image to equal height?
Any help is appreciated!
There is no CSS method of equalising heights of elements that do not share a parent. If the top image is always the same height between columns you can use flexbox to expand the smaller/shorter column though.
.col-sm-12 {
display: flex;
}
.col-sm-6 {
width: 50%;
flex: 1;
display: flex;
flex-direction: column;
}
.c1 {
flex: 1;
display: flex;
flex-direction: column;
}
.c2 {
padding: 20px;
flex: 1;
display: flex;
flex-direction: column;
}
.c3 {
border: 1px solid grey;
padding: 20px;
flex: 1;
}
.image {
width: 100%;
height: 300px;
background-color: grey;
}
<div class="col-sm-12">
<div class="col-sm-6">
<div class="c1">
<div class="c2">
<div class="image">
</div>
<div class="c3">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean consectetur dui quis arcu varius, sit amet consectetur risus auctor. Nulla id mattis ligula. Aliquam euismod dui et viverra ultrices. Praesent eget quam quam. Aenean sit amet lectus et leo
ultrices sodales id sed nulla. Proin fringilla, dui vitae tincidunt tincidunt, nisi tellus efficitur lacus, ac facilisis libero elit ut tellus. In finibus tortor leo, hendrerit sagittis libero maximus sed. Sed rhoncus maximus odio, nec vestibulum
enim fringilla ac. Nulla faucibus, justo nec fermentum blandit, est nisl eleifend purus, non pretium orci sapien at eros. Fusce non laoreet augue. Aenean ac eros augue. Sed sit amet enim sit amet lorem finibus volutpat. Lorem ipsum dolor sit
amet, consectetur adipiscing elit. Mauris placerat, diam sed vulputate aliquet, augue erat luctus massa, molestie egestas diam metus at dolor. Vivamus a metus vitae magna dignissim pulvinar.
</p>
</div>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="c1">
<div class="c2">
<div class="image">
</div>
<div class="c3">
<p>
Etiam id ullamcorper augue, a pharetra nisi. Sed justo enim, malesuada elementum erat non, vehicula varius turpis. Sed quis scelerisque eros, in vestibulum mi. Maecenas et consectetur risus, sed sagittis ex. Aliquam vestibulum fermentum hendrerit. Nulla
eget hendrerit purus. Suspendisse commodo vel tortor ut sollicitudin.
</p>
</div>
</div>
</div>
</div>
</div>
Just use inline-style on the text div tags:
style="height:30em;overflow:scroll"
lol. There might be a lot of new, flashy and sexy frameworks & technologies out there (which I really like), but sometimes going back to the old school methods is a lot simpler and more efficient.

Height 100% on child floated elements of parent with definite height

I need to fix the following code so that child elements were 100% height of its parent. Chromium and Firefox debugging tools show that parent element (footer) has non-zero height. So children should have the same height.
HTML
<div class="footer">
<footer class="clearfix">
<section class="path">
<img height="474px" src="../../src/images/api-maps.yandex.ru.png">
</section>
<section class="info">
<p>bla</p>
</section>
<section class="links">
<p>bla</p>
</section>
<footer class="clearfix"></footer>
</footer>
</div>
CSS
* {
box-sizing: border-box;
}
body {
margin: 0;
padding: 0;
}
.clearfix {
margin: 0;
padding: 0;
}
.clearfix:before, .clearfix:after {
content: " ";
display: table;
}
.clearfix:after {
clear: both;
}
div.footer {
width: 100%;
}
div.footer footer {
background-color: black;
width: 100%;
overflow: hidden;
}
footer.clearfix {
border-top: 6px solid grey;
}
footer section {
float: left;
width: 33.333%;
height: 100%;
}
section.path {
background-color: red;
}
section.path img {
width: 100%;
display: block;
}
section.info {
background-color: blue;
}
section.links {
background-color: yellow;
}
I can't figure out why it doesn't work.
The footer has no height of its own, just what is implied by the image in the content so height:100% won't work.
As mentioned in the comments by raplh.m
the height on the container would have to be explicit. A better approach is to use flexbox, or display: table, which is better supported. That is, display: table on the container and display: table-cell on the sections within.
In fact you can use both and if the browser supports flexbox it will use that in preference to display:table.
As a bonus...you don't need to clear any floats because there aren't any.
footer {
display: table;
table-layout: fixed;
width: 100%;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
}
section {
display: table-cell;
-webkit-box-flex: 1;
-webkit-flex: 1;
-ms-flex: 1;
flex: 1;
text-align: center;
}
img {
display: block;
margin: auto;
}
.path {
background: red;
}
.info {
background: yellow;
}
.links {
background: blue;
}
<footer>
<section class="path">
<img height="474px" src="http://lorempixel.com/output/city-h-c-200-474-10.jpg">
</section>
<section class="info">
<p>bla</p>
</section>
<section class="links">
<p>bla</p>
</section>
</footer>
Codepen Demo
Since you are using percentage heights, you need to specify the height of parent elements.
Try this:
html, body { height: 100%; }
.footer { height: 100%; }
footer { height: 100%; }
DEMO: http://jsfiddle.net/1krrxb87/
For a clear understanding of how the height property works with percentage values, see my answers here:
Why is the 'height' property with percentage value not working on my div?
Percentage height not working in nested flexbox layout in Chrome
This is also possible without use off flexbox or display:table
When you need footer to be atleast have an cross browser height off 100% off the parent you need these CSS rules
footer {
min-height: 100%;
height: auto !important;
height: 100%;
}
To have three floated sections that will have 100% height and appear equal height you can use this HTML and CSS code.
HTML
<footer>
<section>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sit amet nunc eget massa congue scelerisque ac at ex. Ut odio nibh, interdum ac tempus vel, tempus vitae elit. Phasellus vel massa luctus, condimentum leo id, malesuada lectus. Aenean elit risus, consequat et dolor porta, mattis porta sem. Donec id commodo magna, sit amet mollis augue. Vestibulum id imperdiet massa. Maecenas accumsan pharetra est, quis imperdiet diam molestie eu. Aenean lobortis condimentum pharetra. Integer eget sem dictum, tempor arcu non, tincidunt purus. Sed nisi arcu, eleifend non maximus quis, porttitor id sem. Aliquam erat volutpat. Vivamus maximus tempus velit sit amet blandit. Quisque eleifend arcu at nisi elementum efficitur. Praesent consectetur nibh eget accumsan convallis. In pharetra nibh lorem, ac venenatis ipsum tincidunt venenatis. Donec eros justo, ultrices sit amet quam condimentum, placerat sollicitudin justo.
</p>
</section>
<section>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sit amet nunc eget massa congue scelerisque ac at ex. Ut odio nibh, interdum ac tempus vel, tempus vitae elit. Phasellus vel massa luctus, condimentum leo id, malesuada lectus. Aenean elit risus, consequat et dolor porta, mattis porta sem. Donec id commodo magna, sit amet mollis augue. Vestibulum id imperdiet massa. Maecenas accumsan pharetra est, quis imperdiet diam molestie eu. Aenean lobortis condimentum pharetra. Integer eget sem dictum, tempor arcu non, tincidunt purus. Sed nisi arcu, eleifend non maximus quis, porttitor id sem. Aliquam erat volutpat. Vivamus maximus tempus velit sit amet blandit. Quisque eleifend arcu at nisi elementum efficitur. Praesent consectetur nibh eget accumsan convallis. In pharetra nibh lorem, ac venenatis ipsum tincidunt venenatis. Donec eros justo, ultrices sit amet quam condimentum, placerat sollicitudin justo.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sit amet nunc eget massa congue scelerisque ac at ex. Ut odio nibh, interdum ac tempus vel, tempus vitae elit. Phasellus vel massa luctus, condimentum leo id, malesuada lectus. Aenean elit risus, consequat et dolor porta, mattis porta sem. Donec id commodo magna, sit amet mollis augue. Vestibulum id imperdiet massa. Maecenas accumsan pharetra est, quis imperdiet diam molestie eu. Aenean lobortis condimentum pharetra. Integer eget sem dictum, tempor arcu non, tincidunt purus. Sed nisi arcu, eleifend non maximus quis, porttitor id sem. Aliquam erat volutpat. Vivamus maximus tempus velit sit amet blandit. Quisque eleifend arcu at nisi elementum efficitur. Praesent consectetur nibh eget accumsan convallis. In pharetra nibh lorem, ac venenatis ipsum tincidunt venenatis. Donec eros justo, ultrices sit amet quam condimentum, placerat sollicitudin justo.
</p>
</section>
<section>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sit amet nunc eget massa congue scelerisque ac at ex. Ut odio nibh, interdum ac tempus vel, tempus vitae elit. Phasellus vel massa luctus, condimentum leo id, malesuada lectus. Aenean elit risus, consequat et dolor porta, mattis porta sem. Donec id commodo magna, sit amet mollis augue. Vestibulum id imperdiet massa. Maecenas accumsan pharetra est, quis imperdiet diam molestie eu. Aenean lobortis condimentum pharetra. Integer eget sem dictum, tempor arcu non, tincidunt purus. Sed nisi arcu, eleifend non maximus quis, porttitor id sem. Aliquam erat volutpat. Vivamus maximus tempus velit sit amet blandit. Quisque eleifend arcu at nisi elementum efficitur. Praesent consectetur nibh eget accumsan convallis. In pharetra nibh lorem, ac venenatis ipsum tincidunt venenatis. Donec eros justo, ultrices sit amet quam condimentum, placerat sollicitudin justo.
</p>
</section>
<div style="clear:both;"></div>
</footer>
CSS
html, body {
height: 100%;
background-color: green;
}
footer {
background-color: yellow;
min-height: 100%;
height: auto !important;
height: 100%;
overflow: hidden;
}
footer section {
float: left;
width: 33.33%;
background-color: red;
padding-bottom: 999999em;
margin-bottom: -999999em;
}
see demo http://jsfiddle.net/gfoff12w/3/
Note the CSS rules padding-bottom: 999999em and margin-bottom: -999999em these CSS rules will force the browser to create an "height" on the floated section elements.