How to place elements like this - html

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>

Related

CSS Layout with a container and two sidebars

I've tried to achieve this layout with CSS, however, the sidebars (in red) expand whenever there is content in them. I would like if the sidebars maintained a constant width regardless of the content inside of them.
.wrapper {
display: flex;
}
.container {
flex-grow: 1;
max-width: 1024px;
width: 100%;
}
.sidebar {
flex-grow: 1;
min-width: fit-content;
}
You can also use flex-basis CSS property to set the width of each section as the code below:
.wrapper {
display: flex;
}
.container {
flex-grow: 1;
flex-shrink: 1;
flex-basis: 70%;
border: 1px solid #000;
}
.sidebar {
flex-grow: 1;
flex-shrink: 1;
flex-basis: 15%;
border: 1px solid red;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>css flex</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="wrapper">
<section class="sidebar">side-left Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ad aliquid dicta facere fuga harum incidunt maiores molestiae necessitatibus nihil, nisi obcaecati odio odit quis quisquam rem reprehenderit totam vel voluptatibus?</section>
<section class="container">container Lorem ipsum dolor sit amet, consectetur adipisicing elit. Animi debitis deserunt dolore eius enim eum exercitationem explicabo, fuga iusto nam nesciunt nostrum obcaecati odio odit quas rem sapiente suscipit tempora tenetur velit. Accusantium aliquam dignissimos ea eos laboriosam molestiae nemo nobis optio pariatur, rerum tenetur.</section>
<section class="sidebar">side-right Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ab assumenda consectetur dignissimos eos et hic in ipsa ipsum nam officiis perferendis qui, quisquam recusandae, repellendus, repudiandae rerum tempore. Asperiores at atque consectetur cum, deleniti deserunt dolorum error exercitationem fuga harum illum ipsam nisi nostrum omnis placeat provident, quaerat, qui quos sed sequi temporibus velit voluptatum?</section>
</div>
</body>
</html>
Here is an example of a basic CSS layout with a container element and two sidebars:
HTML:
<div class="container">
<div class="sidebar-left">
<!-- sidebar content goes here -->
</div>
<div class="main-content">
<!-- main content goes here -->
</div>
<div class="sidebar-right">
<!-- sidebar content goes here -->
</div>
</div>
CSS:
.container {
display: flex;
}
.sidebar-left {
width: 20%;
background-color: #ccc;
}
.main-content {
width: 60%;
background-color: #fff;
}
.sidebar-right {
width: 20%;
background-color: #ccc;
}```
flex-basis is the way.
.wrapper {
display: flex;
}
.container {
flex-shrink: 1;
flex-grow: 1;
flex-basis: 1024px;
}
.sidebar {
flex-shrink: 1;
flex-grow: 1;
flex-basis: calc((100vw - 1024px)/2);
}
Replacing 1024px with whatever you desire the container width to be.

Flex inside flex with overflow-x

I'd like to create 2 columns inline. The first column has fixed width of 200px and second column should take up the rest of the screen. The second column should autoscroll on the x-axis. I've been trying to use flex but I'm very confused by the markup. Can someone please explain what I'm doing wrong.
Path: html
<section className="container">
<div className="container-name">1</div>
<div className="container-time">
<div className="element">
222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999
</div>
</div>
</section>
Path: CSS
.container {
flex: 0 0 auto;
}
.container-name {
width: 200px;
border: 1px dotted;
}
.container-time {
flex: 0 0 auto;
border: 1px solid;
}
.element {
display: flex;
overflow-x: auto;
}
You can get the desired output using:
max-width on the container
display: inline-flex; on the container
max-width on the container-time
.container {
max-width: 100%;
display: inline-flex;
}
.container-name {
width: 200px;
border: 1px solid red;
}
.container-time {
flex-grow: 1;
max-width: calc(100% - 200px);
border: 1px solid green;
}
.element {
display: flex;
overflow-x: auto;
}
<section class="container">
<div class="container-name">1</div>
<div class="container-time">
<div class="element">
222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
</div>
</div>
</section>
Hope this solution will help you!
* {
margin: 0;
padding: 0;
outline: 0;
box-sizing: border-box;
}
.container {
position: relative;
width: 100%;
height: 100vh;
display: flex;
min-height: 100vh;
}
.container .split {
position: relative;
width: 100%;
height: 100%;
}
.container .split__left {
max-width: 400px;
background-color: coral;
}
.container .split__right {
padding: 2rem;
overflow-x: scroll;
background-color: pink;
}
.container .split__right p {
white-space: nowrap;
}
<div class="container">
<div class="split split__left"></div>
<div class="split split__right">
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Nihil repellat sapiente assumenda. Ex fugit at amet sed libero eaque. Debitis obcaecati aperiam hic possimus unde. Voluptatibus cumque illo dolores architecto.</p>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Nihil repellat sapiente assumenda. Ex fugit at amet sed libero eaque. Debitis obcaecati aperiam hic possimus unde. Voluptatibus cumque illo dolores architecto.</p>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Nihil repellat sapiente assumenda. Ex fugit at amet sed libero eaque. Debitis obcaecati aperiam hic possimus unde. Voluptatibus cumque illo dolores architecto.</p>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Nihil repellat sapiente assumenda. Ex fugit at amet sed libero eaque. Debitis obcaecati aperiam hic possimus unde. Voluptatibus cumque illo dolores architecto.</p>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Nihil repellat sapiente assumenda. Ex fugit at amet sed libero eaque. Debitis obcaecati aperiam hic possimus unde. Voluptatibus cumque illo dolores architecto.</p>
</div>
</div>
[NOTE] see this in bigger screen.

wrong Flexbox size

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>

Why is there sometimes a gap between the divs when i resize my browser?

If you resize the browser there is a gap between the bottom of the .services-items and the parent div (.services). Here's the code:
#one {
background-color: #fff;
height: 50%;
width: 100%;
}
#two {
background-color: #fff;
height: 50%;
width: 100%;
}
body,
html {
height: 100%;
background-color: #000;
}
* {
margin: 0;
}
.services {
background: green;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-ms-flex-direction: row;
flex-direction: row;
padding: 0 50px;
color: #fff;
}
.services-items {
-webkit-box-flex: 1;
-ms-flex-positive: 1;
flex-grow: 1;
background-color: rgba(0, 0, 0, 0.5);
padding: 50px;
height: auto;
text-align: center;
position: relative;
}
.services-items h2 {
margin: 20px 0;
}
.services-items p {
line-height: 150%;
}
<div id="one"></div>
<div class="services">
<a>
<div class="services-items">
<h2>Service 1</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Similique amet atque recusandae, consequatur facere nesciunt. Placeat nostrum, aliquam suscipit. Tempore obcaecati sed eligendi cumque! Quo et, quod veniam nulla maxime quos voluptas harum
odio ipsam libero repellat dicta hic. Eos!</p>
</div>
</a>
<a>
<div class="services-items">
<h2>Service 2</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perferendis pariatur vitae illum, alias suscipit ipsa soluta optio eos officia ducimus incidunt maiores molestias velit, delectus libero, ad eaque repellendus. Rerum, rem doloribus, cupiditate
quos ex hic porro distinctio beatae. Vero, harum, autem. Quo itaque assumenda, mollitia et repellendus vel porro.</p>
</div>
</a>
<a>
<div class="services-items">
<h2>Service 3</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Praesentium error et animi, porro omnis facilis voluptatum vel voluptatem pariatur quasi debitis in ratione voluptas eos ex maiores adipisci, nesciunt aliquid alias maxime accusamus veritatis?
Dignissimos, perspiciatis deserunt numquam animi rerum aliquid mollitia, blanditiis dolore architecto.</p>
<h3>Jos haluat tämän palvelun/tuotteen, ota yhteyttä ja kerro viestissä.</h3>
</div>
</a>
</div>
<div id="two"></div>
Add height:100% to service-items and also add
*{box-sizing:border-box;} to your css file
This is require because border-box
Include padding and border in the element's total width and height:
*{box-sizing:border-box;}
#one {
background-color: #fff;
height: 50%;
width: 100%;
}
#two {
background-color: #fff;
height: 50%;
width: 100%;
}
body,
html {
height: 100%;
background-color: #000;
}
* {
margin: 0;
}
.services {
background: green;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-ms-flex-direction: row;
flex-direction: row;
padding: 0 50px;
color: #fff;
}
.services-items {
-webkit-box-flex: 1;
-ms-flex-positive: 1;
flex-grow: 1;
background-color: rgba(0, 0, 0, 0.5);
padding: 50px;
height: 100%;
text-align: center;
position: relative;
}
.services-items h2 {
margin: 20px 0;
}
.services-items p {
line-height: 150%;
}
<div id="one"></div>
<div class="services">
<a>
<div class="services-items">
<h2>Service 1</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Similique amet atque recusandae, consequatur facere nesciunt. Placeat nostrum, aliquam suscipit. Tempore obcaecati sed eligendi cumque! Quo et, quod veniam nulla maxime quos voluptas harum
odio ipsam libero repellat dicta hic. Eos!</p>
</div>
</a>
<a>
<div class="services-items">
<h2>Service 2</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perferendis pariatur vitae illum, alias suscipit ipsa soluta optio eos officia ducimus incidunt maiores molestias velit, delectus libero, ad eaque repellendus. Rerum, rem doloribus, cupiditate
quos ex hic porro distinctio beatae. Vero, harum, autem. Quo itaque assumenda, mollitia et repellendus vel porro.</p>
</div>
</a>
<a>
<div class="services-items">
<h2>Service 3</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Praesentium error et animi, porro omnis facilis voluptatum vel voluptatem pariatur quasi debitis in ratione voluptas eos ex maiores adipisci, nesciunt aliquid alias maxime accusamus veritatis?
Dignissimos, perspiciatis deserunt numquam animi rerum aliquid mollitia, blanditiis dolore architecto.</p>
<h3>Jos haluat tämän palvelun/tuotteen, ota yhteyttä ja kerro viestissä.</h3>
</div>
</a>
</div>
<div id="two"></div>
One more solution for your code
.services a {
display: flex;
align-self: stretch;
}

Flexbox positioning IE11 [duplicate]

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.