I want to make 3 blocks with flex.
the first must occupy an entire column and the other 2 must be arranged in the second column with 50% of the height each. the first of the second column being an image, I would like the third, which contains only text, to be the same height.
unfortunately, even if this text block seems to have the same size as my image, the size of the 1st column is limited to the end of the text in this block.
.superposition {
display: flex;
width: 70%;
}
.block-orange {
background-color: #F26522;
color: white;
padding: 10px;
flex: 0 0 30%;
}
.superposition .flex-col {
display: flex;
flex-direction: column;
}
.superposition div div {
flex: 0 0 50%;
}
.bg-white {
background-color: yellow;
color: #627188;
}
.bg-grey{
background-color: grey;
}
<section class="superposition">
<div class="block-orange">
<h2>bright ass orange</h2>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Cumque sunt possimus tenetur porro aliquam, tempora itaque aperiam perspiciatis reiciendis dignissimos assumenda odit incidunt sit voluptatem quae laudantium. Accusamus, cum at?</p>
</div>
<div class="flex-col">
<div class="bg-grey">
<img src="img/header-soleil.png" alt="couché de soleil">
</div>
<div class="bg-white">
<h2>finaly a layout that blows your head off</h2>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit.Totam quod excepturi laboriosam vero numquam tenetur corporis iusto magni quaerat eaque dolore, assumenda unde est nostrum saepe fugiat nam doloremque esse.
</p>
</div>
</div>
</section>
why the first column (block-orange) does not adapt in height to the second column?
It seems that you want a grid in which:
Content can expand column height.
Column heights always match.
Two rows are each 50% column height.
This sounds like a "two-dimensional" layout, controlled by both row and column.
Building such layouts with flexbox will likely be a struggle and/or produce fragile layouts.
For reference, see Relationship of grid layout to other layout methods:
do I only need to control the layout by row or column – use a flexbox
do I need to control the layout by row and column – use a grid
Also see Equal height rows in CSS Grid Layout.
I recommend a grid layout instead.
Here's a demonstration:
body {
margin: 0;
}
.superposition {
display: grid;
grid-template-columns: 30% 40%;
grid-auto-rows: 1fr;
}
.block-orange {
background-color: orange;
grid-row: 1/3;
}
.bg-grey {
background-color: grey;
}
.bg-white {
background-color: yellow;
}
.bg-grey img {
width: 100%;
height: 100%;
object-fit: cover;
}
.cellpad {
box-sizing: border-box;
padding: 1em;
}
<section class="superposition">
<div class="block-orange cellpad">
<h2>bright orange</h2>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Cumque sunt possimus tenetur porro aliquam, tempora itaque aperiam perspiciatis reiciendis dignissimos assumenda odit incidunt sit voluptatem quae laudantium. Accusamus, cum at?</p>
</div>
<div class="bg-grey">
<img src="https://fakeimg.pl/440x320/282828/eae0d0/" alt="">
</div>
<div class="bg-white cellpad">
<h2>finally a layout that blows your mind</h2>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit.Totam quod excepturi laboriosam vero numquam tenetur corporis iusto magni quaerat eaque dolore, assumenda unde est nostrum saepe fugiat nam doloremque esse.
</p>
</div>
</section>
To achieve the result you are looking for, one approach would be to apply
flex-direction: column;
to the entire .superposition parent <div>, in combination with:
flex-wrap: wrap;
which will ensure that if .block-orange occupies 100% of the height of .superposition, then .bg-grey will follow it by starting at the top of .superposition, to the right of .block-orange.
i.e. The divs are still wrapping but they are wrapping horizontally, rather than wrapping vertically.
Working Example:
.superposition {
display: flex;
flex-direction: column;
flex-wrap: wrap;
width: 70%;
height: 500px;
}
.block-orange {
flex: 1 0 100%;
width: 30%;
padding: 0 10px;
color: white;
background-color: #F26522;
}
.bg-grey,
.bg-white {
flex: 0 0 50%;
width: 70%;
padding: 0 10px;
}
.bg-white {
color: #627188;
background-color: yellow;
}
.bg-grey {
background-color: grey;
}
<section class="superposition">
<div class="block-orange">
<h2>bright ass orange</h2>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Cumque sunt possimus tenetur porro aliquam, tempora itaque aperiam perspiciatis reiciendis dignissimos assumenda odit incidunt sit voluptatem quae laudantium. Accusamus, cum at?</p>
</div>
<div class="bg-grey">
<img src="img/header-soleil.png" alt="couché de soleil">
</div>
<div class="bg-white">
<h2>Finally, a layout that blows your head off</h2>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit.Totam quod excepturi laboriosam vero numquam tenetur corporis iusto magni quaerat eaque dolore, assumenda unde est nostrum saepe fugiat nam doloremque esse.</p>
</div>
</section>
Related
I am trying to make a 3 column layout for a part of an interface. I am using flexbox to lay it out since I can use flex-direction: column and let it keep moving to the right. Each content box is a width of 30%, which will ideally give me the 3 columns I am looking for. The problem I am having is when the content grows too big for the container vertically, it begins to overflow in the x-direction.
See this codepen for an example of what I am trying to avoid: https://codepen.io/jtris1/pen/RwBZPNp
I tried setting the min-height of the content container to 100%, but this results in it creating a single column down the container instead of the 3 I need. I also tried setting max-width on the container to see if it would force the content down, but the content still overflows in the x-direction.
HTML
<div className='guideline-detail-overlay-container'>
<div className="overlay-info">
<h2>Title</h2>
</div>
<div className='overlay-flex-content'>
<div className="overlay-demographics overlay-content-box">
<h3>Demographics</h3>
...
</div>
<div className="overlay-med-history overlay-content-box">
<h3>Medical History</h3>
...
</div>
<div className="overlay-family-history overlay-content-box">
<h3>Family History</h3>
...
</div>
<div className="overlay-services overlay-content-box">
<h3>Preventative Screening Services</h3>
...
</div>
</div>
</div>
CSS
.guideline-detail-overlay-container {
/* display: none; */
position: absolute;
background-color: #ffffff;
border: 1px solid black;
width: 100%;
height: 100%;
padding: 2rem 4rem;
box-sizing: border-box;
}
.overlay-flex-content {
min-height: auto;
display: flex;
flex-direction: column;
flex-wrap: wrap;
align-items: center;
}
.overlay-content-box {
width: 30%;
height: auto;
margin-bottom: 1.5rem;
}
.overlay-info {
width: 100%;
height: auto;
text-align: center;
margin-bottom: 2rem;
}
Notice that when you use a 100% height you're assign the same height that the div (guideline-detail-overlay-container) parent. Change the height to auto should fix your problem. You also should delete height property.
guideline-detail-overlay-container {
height : auto;
}
While Flexbox Layout is an easy way to define grids, sometimes it is even easier to use the 'older' CSS columns mechanism to flow a text.
Define a parent columns container (.guideline-detail-overlay-container)
Define the preferred maximum the number of columns it should hold.
Define the preferred width of a single column. This value will resize with the width of the viewport and serves as a trigger to wrap content elements and to calculate whether there is enough room given the number of columns required.
I have disabled all Flexbox Layout related properties in your CSS code, inserted columns layout alternatives and commented the CSS and left the original code in-place for comparison.
snippet
/* * { outline: 1px dashed } /* for debugging */
/* Set for all elements */
*, ::before, ::after { box-sizing: border-box }
.guideline-container {
/* position: relative; /* obsolete, has no use */
/* min-height: 70vh; /* obsolete, content will stretch the parent */
/* justify-content: center; /* obsolete, not a flexbox container */
}
.guideline-detail-overlay-container {
/* display: none; */
/* position: absolute; /* obsolete, has no use */
padding: 2rem 4rem;
background-color: #ffffff;
border: 1px solid black;
/* obsolete, stretching is automatic
width : 100%;
height: 100%;
*/
}
.overlay-flex-content {
/* Set default required columns and column width (wrap trigger) */
columns: 3 250px;
/* 'columns' mechanism will differentiate on viewport resize */
/* height: 100%; /* obsolete, stretched by content */
/*
display: flex;
flex-direction: column;
flex-wrap: wrap;
align-items: center;
*/
}
.overlay-content-box {
/*
width: 30%;
height: auto;
margin-bottom: 1.5rem;
*/
}
.overlay-content-box:first-child>h3 {
/* To remove jagged top of first item in first column */
/* A well know issue */
margin-top: 0;
}
.overlay-info {
column-span: all;
/* width: 100%; /* obsolete, handled by 'column-span' */
/* height: auto; /* obsolete, HTML default */
text-align: center;
margin-bottom: 2rem;
}
<div class='guideline-container'>
<div class='guideline-detail-overlay-container'>
<div class="overlay-info">
<h2>Title</h2>
</div>
<div class='overlay-flex-content'>
<div class="overlay-demographics overlay-content-box">
<h3>Demographics</h3>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Blanditiis possimus iure deserunt explicabo quasi quis aliquam vitae reiciendis nisi dignissimos obcaecati animi iusto cumque eum a, voluptate nesciunt assumenda corrupti?
</div>
<div class="overlay-med-history overlay-content-box">
<h3>Medical History</h3>
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Odio, dolorem reprehenderit. Saepe sunt, aut ratione quasi quaerat voluptatum, iste, fugiat autem dolor velit exercitationem blanditiis nisi. Et in odio ducimus.
</div>
<div class="overlay-family-history overlay-content-box">
<h3>Family History</h3>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Aut, neque cumque voluptatem adipisci nemo harum, hic dolorem accusamus, pariatur debitis velit est rem doloremque. Laboriosam ad corrupti sit excepturi suscipit.
</div>
<div class="overlay-services overlay-content-box">
<h3>Preventative Screening Services</h3>
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Sit expedita saepe architecto quaerat beatae repellendus! Enim natus, totam quaerat officia non voluptatibus facilis, maiores molestias quos quam voluptates mollitia. Quae!
</div>
<div class="overlay-services overlay-content-box">
<h3>Preventative Screening Services</h3>
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Sit expedita saepe architecto quaerat beatae repellendus! Enim natus, totam quaerat officia non voluptatibus facilis, maiores molestias quos quam voluptates mollitia. Quae!
</div>
<div class="overlay-services overlay-content-box">
<h3>Preventative Screening Services</h3>
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Sit expedita saepe architecto quaerat beatae repellendus! Enim natus, totam quaerat officia non voluptatibus facilis, maiores molestias quos quam voluptates mollitia. Quae!
</div>
<div class="overlay-services overlay-content-box">
<h3>Preventative Screening Services</h3>
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Sit expedita saepe architecto quaerat beatae repellendus! Enim natus, totam quaerat officia non voluptatibus facilis, maiores molestias quos quam voluptates mollitia. Quae!
</div>
</div>
</div>
</div>
I tried to set to parent block this:
display: flex;
flex-direction: column;
flex-wrap: wrap;
max-height: 500px;
and it works, but it will break if, as example, the second block will be larger. So I am looking for another decision. (I cannot use css-grid)
Codepen Link
Image how it might looks
Try this
.bigger {
height: 300px !important;
}
.smaller {
height: 99px !important;
margin-bottom: 2px;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css" integrity="sha384-Smlep5jCw/wG7hdkwQ/Z5nLIefveQRIY9nfy6xoR1uRYBtpZgI6339F5dgvm/e9B" crossorigin="anonymous">
<div class="container-fluid">
<div class="row main">
<div class="col-sm-6">
<div class="col-sm-12"><p>
1 Lorem ipsum dolor sit amet, consectetur adipisicing elit. Error nihil consequuntur itaque placeat est voluptates, temporibus iste nesciunt dignissimos excepturi.
</p> </div>
<div class="col-sm-12">
<p>
2 Lorem ipsum dolor sit amet consectetur adipisicing elit. Sint optio laudantium dolorem doloremque non praesentium sit. Corporis quisquam soluta, ullam unde deleniti at expedita facilis animi dicta facere quam iste!
</p>
</div>
</div>
<div class="col-sm-6">
<p>
3 Lorem ipsum dolor sit amet consectetur adipisicing elit. Ullam voluptas maxime eos labore, sed, temporibus tenetur a sunt ratione voluptates excepturi est eaque? Porro, nostrum impedit laborum minima quos at nulla sit officiis. Dignissimos, at. Ipsam delectus dicta ipsum cupiditate. Ullam voluptas maxime eos labore, sed, temporibus tenetur a sunt ratione voluptates excepturi est eaque? Porro, nostrum impedit laborum minima quos at nulla sit officiis. Dignissimos, at. Ipsam delectus dicta ipsum cupiditate.
</p>
</div>
</div>
</div>
Please have a look at the below working example below, hope it helps :)
body .child {
font-family: sans-serif;
}
.parent {
display: flex;
flex-direction: row;
flex-wrap: wrap;
max-width: 90%;
margin: 0 auto;
}
.child {
margin: 10px;
padding: 50px 20px;
min-width: 39%;
box-shadow: inset 0 0 0 2px #000;
}
.parent {
max-height: none;
}
.child--1 {
order: 1;
}
.child--2 {
order: 3;
}
.child--3 {
order: 2;
padding: 100px 20px;
}
#media screen and (max-width: 500px) {
.parent {
flex-direction: column;
}
.child {
min-width: auto;
}
}
<div class="parent">
<div class="child child--1">Child 1</div>
<div class="child child--2">Child 2</div>
<div class="child child--3">Child 3</div>
</div>
How can I fix the title and make sure it will display?
.cont {
display: flex;
flex-direction: column;
width: 250px;
height: 150px;
border: 1px solid red;
overflow: hidden;
}
.title {
display: flex;
background: #ccc;
justify-content: space-between;
}
<div class="cont">
<div class="title">
<div>title that collapse</div>
<div>28/3/2018</div>
</div>
<div>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Ab sapiente provident iure ipsa ipsum nulla distinctio vero nisi officiis, id accusantium perferendis enim quisquam. Optio est deserunt atque, explicabo enim excepturi aliquid expedita rerum
voluptates similique ipsam vitae sapiente sequi at earum.
</div>
</div>
https://codepen.io/anon/pen/xWYZEK
Here are two options for solving this problem: min-height or flex-shrink.
Use min-height
Instead of height: 150px use min-height: 150px.
Since you've forced the box to have a fixed height, the content inside will overflow when necessary. With min-height, the box can expand to accommodate content.
.cont {
display: flex;
flex-direction: column;
width: 250px;
min-height: 150px; /* adjustment */
border: 1px solid red;
overflow: hidden;
}
.title {
display: flex;
background: #ccc;
justify-content: space-between;
}
<div class="cont">
<div class="title">
<div>title that collapse</div>
<div>28/3/2018</div>
</div>
<div>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Ab sapiente provident iure ipsa ipsum nulla distinctio vero nisi officiis, id accusantium perferendis enim quisquam. Optio est deserunt atque, explicabo enim excepturi aliquid expedita rerum
voluptates similique ipsam vitae sapiente sequi at earum.
</div>
</div>
Disable flex-shrink
An initial setting of a flex container is flex-shrink: 1. This means that flex items are permitted to shrink in order to avoid overflowing the container.
Since you have a fixed height on the container, the title is shrinking so that all items can fit inside.
Therefore, an alternative to the min-height option is to disable flex-shrink.
.cont {
display: flex;
flex-direction: column;
width: 250px;
height: 150px; /* back to original */
border: 1px solid red;
overflow: hidden;
}
.title {
flex-shrink: 0; /* new */
display: flex;
background: #ccc;
justify-content: space-between;
}
<div class="cont">
<div class="title">
<div>title that collapse</div>
<div>28/3/2018</div>
</div>
<div>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Ab sapiente provident iure ipsa ipsum nulla distinctio vero nisi officiis, id accusantium perferendis enim quisquam. Optio est deserunt atque, explicabo enim excepturi aliquid expedita rerum
voluptates similique ipsam vitae sapiente sequi at earum.
</div>
</div>
This question already has answers here:
Text in a flex container doesn't wrap in IE11
(13 answers)
Closed 5 years ago.
In spite of all my research, I can not fix the position of my grid with flexbox on IE11. There is no problem on other browsers, including Edge.
I have read the specifications of Flexbox on caniuse, but I still do not see how to solve my problem without breaking the setup on other browsers.
An idea ? Thank you very much.
Codepen here.
CSS:
* {
box-sizing: border-box;
}
.steps {
.steps-list {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.step {
align-items: center;
display: flex;
flex-direction: column;
flex: 1 0 auto;
padding: 20px;
width: 25%;
#media (max-width: 740px) {
padding-bottom: 30px;
width: 48%;
}
}
.step__thumb {
background-color: #f7f7f7;
border-radius: 50%;
color: red;
font-size: 1.4rem;
font-weight: 500;
height: 110px;
line-height: 110px;
margin-bottom: 18px;
width: 110px;
}
.step__text {
color: lighten(#202124, 20%);
font-size: 1.4rem;
font-weight: 300;
list-style: circle;
text-align: left;
}
}
HTML:
<section class="band steps">
<div class="wrapper">
<div class="steps-list">
<div class="step">
<div class="step__thumb"></div>
<div class="step__text">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Molestias similique quidem ab ratione expedita, repellat laborum praesentium, pariatur a nulla ipsa alias corrupti eum illum fugiat saepe quos unde iste.
</div>
</div>
<div class="step">
<div class="step__thumb"></div>
<div class="step__text">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Molestias similique quidem ab ratione expedita, repellat laborum praesentium, pariatur a nulla ipsa alias corrupti eum illum fugiat saepe quos unde iste.
</div>
</div>
<div class="step">
<div class="step__thumb"></div>
<div class="step__text">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Molestias similique quidem ab ratione expedita, repellat laborum praesentium, pariatur a nulla ipsa alias corrupti eum illum fugiat saepe quos unde iste.
</div>
</div>
<div class="step">
<div class="step__thumb"></div>
<div class="step__text">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Molestias similique quidem ab ratione expedita, repellat laborum praesentium, pariatur a nulla ipsa alias corrupti eum illum fugiat saepe quos unde iste.
</div>
</div>
</div>
</div>
</section>
Add width: 100% to .step__text
codepen
I'm not entirely sure why this works, but I had a similar issue before, and defining a width seemed to work.
In the following html code I created a row with two columns.The first column i have an image and on the second I have my heading and a paragraph.
<div class="row">
<div class="col-6">
<img src="image/beds.jpg" alt="">
</div>
<div class="col-6">
<h2>Nevex has the experiencce</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptates velit, inventore praesentium. Delectus nulla, voluptates excepturi earum minima eligendi cumque ullam, opdfgdtio nostrum ipsa maiores cupiditate facilis sint debitis aliquid. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Mollitia id beatae nostrum ducimus possimus, odit eligendi fuga perspiciatis placeat nisi facilis unde adipisci illo fugit doloremque, at porro magni, perferendis?</p>
</div>
</div>
And next is my styling code:
.row {
margin: 0 -10px;
margin-bottom: 10px;
}
.row:last-child {
margin-bottom: 0;
}
[class*="col-"] {
padding: 10px;
}
#media all and ( min-width: 600px ) {
.row {
display: table;
table-layout: fixed;
width: 100%;
}
[class*="col-"] {
display: table-cell;
}
.col-1{
width:100%;
}
.col-6{
width:50%;
}
}
How can I alter the size of the image with responsiveness and align the content of both columns?
Meaning that the image would decrease a bit in terms of height and the content of the other column would also be in the middle of the div.
one solution is to use image as a background to that div, and once you do it, you can give it a width:100%.
If you are using bootstrap, you can add the class="img-responsive" and it will automatically adapt to the width of the screen