I have a basic html markup, where i am trying to use minimal html wrappers to achieve the design.
So my goal is without adding more html wrappers, using flex, force 3rd flex item to start from second column like here
1 2
3
Of course, we can achieve adding padding/margin-left for the 3rd element, but I am looking for a solution with css flex and using minimal html markup.
Here is the screenshot what I am trying to achieve
Basically the title and text should start from the same column.
See the code snippet and sandbox link, if you want to test it more
body {
margin: 0;
padding: 0;
}
.container {
background-color: grey;
overflow: auto;
padding: 20px;
align-items: center;
display: flex;
position: relative;
column-gap: 15px;
flex-wrap: wrap;
width: 100%;
}
.content {
display: flex;
flex-wrap: wrap;
}
.logo-image {
align-self: flex-start;
padding-top: 10px;
order: 1;
}
.headline {
color: white;
order: 2;
padding-left: 10px;
}
.text {
color: white;
font-size: 16px;
margin-bottom: 20px;
order: 3;
}
.btn {
display: flex;
width: 100%;
}
button {
align-items: center;
background-color: black;
color: white;
flex: 0 0 90%;
justify-content: center;
margin: 0;
}
<div class="container">
<div class="content">
<h4 class="headline">
Block Title
</h4>
<img src="https://www.fillmurray.com/200/200" width="50px" class="logo-image" alt="img" />
<p class="text">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Sapiente
aliquid sit, cupiditate
</p>
</div>
<div class="btn">
<button>click</button>
</div>
Ideally, you would use CSS Grid for this layout.
Something like this (no changes to the HTML):
.container {
display: flex;
flex-wrap: wrap;
background-color: grey;
column-gap: 15px;
padding: 20px;
}
.content {
display: grid;
grid-template-columns: 50px 1fr;
}
.logo-image {
padding-top: 10px;
order: 1;
}
.headline {
color: white;
order: 2;
padding-left: 10px;
}
.text {
grid-column: 2;
color: white;
font-size: 16px;
margin-bottom: 20px;
order: 3;
}
.btn {
display: flex;
width: 100%;
}
button {
align-items: center;
background-color: black;
color: white;
flex: 0 0 90%;
justify-content: center;
margin: 0;
}
body {
margin: 0;
padding: 0;
}
<div class="container">
<div class="content">
<h4 class="headline">
Block Title
</h4>
<img src="https://www.fillmurray.com/200/200" width="50px" class="logo-image" alt="img" />
<p class="text">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Sapiente aliquid sit, cupiditate
</p>
</div>
<div class="btn">
<button>click</button>
</div>
But if you can only use flex, then you'll have to:
Define a height on the container.
Set the flex-direction to column.
Set flex-wrap to wrap.
Give the first column (containing the image) full height, so it creates a column and forces its siblings into the second column.
(Again, no changes to the HTML.)
.container {
display: flex;
flex-wrap: wrap;
background-color: grey;
column-gap: 15px;
padding: 20px;
height: 200px; /* new (for demo purposes) */
}
.content {
display: flex;
flex-direction: column; /* new */
flex-wrap: wrap;
}
.logo-image {
flex-basis: 100%; /* new */
object-fit: contain; /* new (for proper image rendering) */
object-position: top; /* new (for proper image rendering) */
align-self: flex-start;
padding-top: 10px;
order: 1;
}
.headline {
color: white;
order: 2;
padding-left: 10px;
}
.text {
color: white;
font-size: 16px;
margin-bottom: 20px;
order: 3;
}
.btn {
display: flex;
width: 100%;
}
button {
align-items: center;
background-color: black;
color: white;
flex: 0 0 90%;
justify-content: center;
margin: 0;
}
body {
margin: 0;
padding: 0;
}
<div class="container">
<div class="content">
<h4 class="headline">Block Title</h4>
<img src="https://www.fillmurray.com/200/200" width="50px" class="logo-image" alt="img" />
<p class="text">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Sapiente
aliquid sit, cupiditate
</p>
</div>
<div class="btn">
<button>click</button>
</div>
If you can't define a height on the container, then use the Grid version.
/* added this --v */
.content {
display: grid; /* ----- new ------- */
grid-template-columns: auto 1fr; /* ----- new ------- */
grid-template-rows: 1fr 1fr; /* ----- new ------- */
column-gap: 15px; /* ----- new ------- */
}
<body>
<div class="container">
<div class="content">
<!-- bring the img element above of h4 because we want it to be in the first item of our grid layout -->
<img src="download.png" width="50px" class="logo-image" alt="img" />
<h4 class="headline">
Block Title
</h4>
<p class="text">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Sapiente
aliquid sit, cupiditate
</p>
</div>
<div class="btn">
<button>link</button>
</div>
</div>
</body>
1.you need to use a two-dimensional layout which is grid (instead of flexbox)
2.you need to use grid for the element that has .content class
.content { display: grid; grid-template-columns: auto 1fr; grid-template-rows: 1fr 1fr; column-gap: 15px; } <br>
3.you need to define the p element that has .text class to start from the 2nd column and ends in the 3rd column with this code: grid-column: 2/3;
and here is the result : https://codesandbox.io/s/brave-zhukovsky-7g12bj?file=/style.css:566-583
Related
I have a basic html markup, where i am trying to use minimal html wrappers to achieve the design.
The button on the bottom should't align, it should always stay in the bottom.
So my goal is without adding more html wrappers, using flex, force a flex item(button) to drop to the next line. and the block title stay next to the image.
You can see what i mean checking it on mobile breakpoints.
Here are the screenshots with flex-wrap: wrap
And here is with flex-wrap: nowrap
As you see, in first example button is in the bottom as it should be, but block title is dropped to the next line, And in the second example (flex-wrap: wrap) block title is positioned correct, but the button is not in the bottom.
Here is the sandbox link and code example
body {
margin: 0;
padding: 0;
}
.container {
background-color: grey;
overflow: auto;
padding: 20px;
align-items: center;
display: flex;
position: relative;
column-gap: 15px;
flex-wrap: wrap;
/* //try nowrap */
width: 100%;
}
.logo-image {
align-self: flex-start;
}
.headline {
color: white;
}
.text {
color: white;
font-size: 16px;
margin-bottom: 20px;
}
.btn {
display: flex;
width: 100%;
}
button {
align-items: center;
background-color: black;
color: white;
flex: 0 0 100%;
justify-content: center;
margin: 0;
}
<div class="container">
<img src="download.png" width="50px" class="logo-image" alt="img" />
<span class="content">
<h4 class="headline">
Block Title
</h4>
<p class="text">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Sapiente
aliquid sit, cupiditate
</p>
</span>
<div class="btn">
<button>link</button>
</div>
</div>
Any help will be appreciated
You can make your span a block level element and set flex-grow to 1 but set flex-basis to something small, like 50% so it tries to be 50% of the width but will grow to fit the width. It then means when shrinking it will try to stay on the same line.
body {
margin: 0;
padding: 0;
}
.container {
background-color: grey;
overflow: auto;
padding: 20px;
align-items: center;
display: flex;
position: relative;
column-gap: 15px;
flex-wrap: wrap;
width: 100%;
}
/* added this --v */
.content {
display: block;
flex: 1 0 50%;
}
.logo-image {
align-self: flex-start;
}
.headline {
color: white;
}
.text {
color: white;
font-size: 16px;
margin-bottom: 20px;
}
.btn {
display: flex;
width: 100%;
}
button {
align-items: center;
background-color: black;
color: white;
flex: 0 0 90%;
justify-content: center;
margin: 0;
}
<div class="container">
<img src="https://www.fillmurray.com/200/200" width="50px" class="logo-image" alt="img" />
<span class="content">
<h4 class="headline">
Block Title
</h4>
<p class="text">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Sapiente
aliquid sit, cupiditate
</p>
</span>
<div class="btn">
<button>link</button>
</div>
</div>
I can make the basic Holy Grail layout, but once it comes to putting boxes inside boxes, things fall apart. I have looked at code for comparison, but this specific layout doesn't seem very common.
What I want to do is have 4 flexboxes inside the main content of the webpage. Above the boxes is a header, maybe a paragraph underneath that. Under the flexboxes are a description for each, that is centered and aligned with the flexbox. The flexboxes will hold a picture, but that is not important right now.
https://codepen.io/ct2k/pen/mdqdpzw
}
html, body {
margin: 0;
padding: 0;
font-family: sans-serif;
font-size: 1.1em;
text-align: center;
color: #FFF;
}
.holy-grail header,
.holy-grail footer,
.hg-sidebar,
.holy-grail-content {
padding: 20px;
}
.holy-grail header,
.holy-grail footer {
background: #0c31aa;
}
.hg-sidebar {
background: #b7d3ec;
}
.holy-grail-content {
color: #777;
}
.holy-grail {
min-height: 100vh;
}
.holy-grail,
.holy-grail-body {
display: flex;
flex: 1 1 auto;
flex-direction: column;
}
.holy-grail-content {
flex: 1 1 auto;
display: flex;
justify-content: center;
}
#media (min-width: 768px) {
.holy-grail-sidebar-1 {
order: -1;
}
.holy-grail-body {
flex-direction: row;
}
.hg-sidebar {
flex: 0 0 260px;
}
.block {
border: solid;
border-color: cornflowerblue;
width: 200px;
height: 200px;
font-size: 48px;
text-align: center;
}
.mc {
display: flex;
justify-content: center;
align-items: center;
}
You can insert those divs of the card inside other major div
I try to solve it quickly using another div to store
the header for the card
paragraph
card
description of card
html, body {
margin: 0;
padding: 0;
font-family: sans-serif;
font-size: 1.1em;
text-align: center;
color: #FFF;}
html, body {
margin: 0;
padding: 0;
font-family: sans-serif;
font-size: 1.1em;
text-align: center;
color: #FFF;
}
.holy-grail header,
.holy-grail footer,
.hg-sidebar,
.holy-grail-content {
padding: 20px;
}
.holy-grail header,
.holy-grail footer {
background: #0c31aa;
}
.hg-sidebar {
background: #b7d3ec;
}
.holy-grail-content {
color: #777;
flex: 1 1 auto;
display: flex;
justify-content: center;
/*Add this line*/
flex-direction: column;
}
.holy-grail {
min-height: 100vh;
}
.holy-grail,
.holy-grail-body {
display: flex;
flex: 1 1 auto;
flex-direction: column;
}
#media (min-width: 768px) {
.holy-grail-sidebar-1 {
order: -1;
}
.holy-grail-body {
flex-direction: row;
}
.hg-sidebar {
flex: 0 0 260px;
}
.block {
border: solid;
border-color: cornflowerblue;
width: 200px;
height: 200px;
font-size: 48px;
text-align: center;
}
.mc {
display: flex;
justify-content: center;
align-items: center;
}
.card-with-header-and-desc-container {
text-align: center;
width: 200px;
/*height: 200px;*/
}
.card-with-header-and-desc-container__header {
font-weight: 700;
font-size: 1.5rem
}
.card-with-header-and-desc-container__sub {
font-weight: 500;
font-size: 1.1rem
}
.extra-text{
margin: 0 10px;
}
}
.holy-grail header,
.holy-grail footer,
.hg-sidebar,
.holy-grail-content {
padding: 20px;
}
.holy-grail header,
.holy-grail footer {
background: #0c31aa;
}
.hg-sidebar {
background: #b7d3ec;
}
.holy-grail-content {
color: #777;
}
.holy-grail {
min-height: 100vh;
}
.holy-grail,
.holy-grail-body {
display: flex;
flex: 1 1 auto;
flex-direction: column;
}
.holy-grail-content {
flex: 1 1 auto;
display: flex;
justify-content: center;
}
#media (min-width: 768px) {
.holy-grail-sidebar-1 {
order: -1;
}
.holy-grail-body {
flex-direction: row;
}
.hg-sidebar {
flex: 0 0 260px;
}
.block {
border: solid;
border-color: cornflowerblue;
width: 200px;
height: 200px;
font-size: 48px;
text-align: center;
}
.mc {
display: flex;
justify-content: center;
align-items: center;
}
<!DOCTYPE html>
<html lang="en">
<body class="holy-grail">
<!--<body class="holy-grail">-->
<header>
<p>Header</p>
</header>
<div class="holy-grail-body">
<section class="holy-grail-content">
<h1>Main content</h1>
<div class="mc">
<div class="card-with-header-and-desc-container">
<p class="card-with-header-and-desc-container__header">Some header</p>
<p class="card-with-header-and-desc-container__sub">maybe a paragraph</p>
<div class="block block1">1
</div>
<p>Description of each card Lorem ipsum dolor sit amet consectetur adipisicing elit. </p>
</div>
<p class="extra-text">Whats</p>
<div class="card-with-header-and-desc-container">
<p class="card-with-header-and-desc-container__header">Some header</p>
<p class="card-with-header-and-desc-container__sub">maybe a paragraph</p>
<div class="block block2">2
</div>
<p>Description of each card Lorem ipsum dolor sit amet consectetur adipisicing elit. </p>
</div>
<p class="extra-text">In</p>
<div class="card-with-header-and-desc-container">
<p class="card-with-header-and-desc-container__header">Some header</p>
<p class="card-with-header-and-desc-container__sub">maybe a paragraph</p>
<div class="block block3">3
</div>
<p>Description of each card Lorem ipsum dolor sit amet consectetur adipisicing elit. </p>
</div>
<p class="extra-text">The</p>
<div class="card-with-header-and-desc-container">
<p class="card-with-header-and-desc-container__header">Some header</p>
<p class="card-with-header-and-desc-container__sub">maybe a paragraph</p>
<div class="block block4">4
</div>
<p>Description of each card Lorem ipsum dolor sit amet consectetur adipisicing elit. </p>
</div>
<p class="extra-text">Box?</p>
</div>
</section>
<div class="holy-grail-sidebar-1 hg-sidebar">
<p>Sidebar 1</p>
</div>
<div class="holy-grail-sidebar-2 hg-sidebar">
<p>Sidebar 2</p>
</div>
</div>
<footer>
<p>Footer</p>
</footer>
</body>
</html>
Example applied
if this does not solve your problem consider adding some images showing what your expected design is.
I have a problem making the page responsive. The property flex-wrap: nowrap is not working properly. Can you please help me to find out where the problem is?
.logo {
text-decoration: none;
color: white;
}
.header {
width: 100%;
max-width: 960px;
min-width: 460px;
min-height: 100px;
margin: 0 auto 30px;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
box-sizing: border-box;
}
.logo {
background: black;
width: 150px;
min-height: 50px;
align-items: center;
display: flex;
flex: none;
margin: 0 10px 40px;
justify-content: center;
}
.contnet {
background: black;
min-height: 50px;
font-size: 20px;
color: white;
margin-bottom: 40px;
flex-basis: 300px;
display: flex;
justify-content: center;
align-items: center;
}
.bottom-content {
min-height: 50px;
display: flex;
flex-wrap: wrap;
flex: auto;
background: black;
width: 100%;
color: white;
font-size: 20px;
justify-content: center;
align-items: center;
}
.main {
width: 100%;
max-width: 960px;
min-width: 430px;
display: flex;
flex: auto;
margin: auto;
box-sizing: border-box
}
.grid {
display: flex;
flex-wrap: wrap;
justify-content: center;
}
.griditem {
margin-bottom: 30px;
display: flex;
flex-basis: calc(33.33% - 20px * 2/3);
flex-wrap: wrap;
}
.img {
width: 200px;
height: 200px;
background-color: black;
margin: 0 auto;
}
.title {
text-align: center;
}
.grid-content {
flex: 0 1 100%;
}
.text {
text-align: center;
}
.footer {
width: 100%;
background-color: black;
max-width: 960px;
min-width: 460px;
margin: 0 auto;
padding: 15px;
color: white;
text-align: center;
}
.img {
color: white;
}
#media screen and (max-width: 800px) {
.contnet {
display: none
}
.griditem {
flex-wrap: nowrap;
flex-basis: 100%;
}
.img {
flex: 0 0 auto;
}
.griditem:nth-child(even) {
margin: 0 0 0 30px;
order: 2
}
.footer{
display: none
}
.griditem:nth-child(odd) {
margin: 0 30px 0 0;
}
}
<hrader class="header">
Logo
<div class="contnet">Content</div>
<div class="bottom-content">2</div>
</hrader>
<main class="main">
<div class="grid">
<div class="griditem">
<div class="img">1</div>
<div class="grid-content">
<h1 class="title">Title</h1>
<p class="text">Lorem ipsum, dolor sit amet consectetur adipisicing elit. Distinctio neque magnam amet, praesentium vel illum error autem voluptatibus veniam consequuntur.</p>
</div>
</div>
</div>
<div class="grid">
<div class="griditem">
<div class="img">2</div>
<div class="grid-content">
<h1 class="title">Title</h1>
<p class="text">Lorem ipsum, dolor sit amet consectetur adipisicing elit. Distinctio neque magnam amet, praesentium vel illum error autem voluptatibus veniam consequuntur.</p>
</div>
</div>
</div> <div class="grid">
<div class="griditem">
<div class="grid-content">
<div class="img">3</div>
<h1 class="title">Title</h1>
<p class="text">Lorem ipsum, dolor sit amet consectetur adipisicing elit. Distinctio neque magnam amet, praesentium vel illum error autem voluptatibus veniam consequuntur.</p>
</div>
</div>
</div>
</main>
<footer class="footer">
Footer
</footer>
Fiddle: https://jsfiddle.net/q9bcpr4L/
Add flex-wrap to main and flex-basis to grid
.main {
width: 100%;
max-width: 960px;
min-width: 430px;
display: flex;
flex: auto;
flex-wrap:wrap;
margin: auto;
box-sizing: border-box
}
.grid {
display: flex;
flex-wrap: wrap;
justify-content: center;
flex-basis: calc(33.33% - 20px * 2/3);
}
That's what do you want? I:
Moved .title and .text elements inside .grid-content element.
Added flex-wrap: wrap to .main selector.
Fixed some typos.
.logo {
text-decoration: none;
color: white;
}
.header {
width: 100%;
max-width: 960px;
min-width: 460px;
min-height: 100px;
margin: 0 auto 30px;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
box-sizing: border-box;
}
.logo {
background: black;
width: 150px;
min-height: 50px;
align-items: center;
display: flex;
flex: none;
margin: 0 10px 40px;
justify-content: center;
}
.content {
background: black;
min-height: 50px;
font-size: 20px;
color: white;
margin-bottom: 40px;
flex-basis: 300px;
display: flex;
justify-content: center;
align-items: center;
}
.bottom-content {
min-height: 50px;
display: flex;
flex-wrap: wrap;
flex: auto;
background: black;
width: 100%;
color: white;
font-size: 20px;
justify-content: center;
align-items: center;
}
.main {
width: 100%;
max-width: 960px;
min-width: 430px;
display: flex;
flex: auto;
margin: auto;
box-sizing: border-box;
}
.grid {
display: flex;
flex-wrap: wrap;
justify-content: center;
}
.griditem {
margin-bottom: 30px;
display: flex;
flex-basis: calc(33.33% - 20px * 2/3);
flex-wrap: wrap;
}
.img {
width: 200px;
height: 200px;
background-color: black;
margin: 0 auto;
}
.title {
text-align: center;
}
.grid-content {
flex: 0 1 100%;
}
.text {
text-align: center;
}
.footer {
width: 100%;
background-color: black;
max-width: 960px;
min-width: 460px;
margin: 0 auto;
padding: 15px;
color: white;
text-align: center;
}
.img {
color: white;
}
#media screen and (max-width: 800px) {
.content {
display: none
}
.main {
flex-wrap: wrap;
}
.griditem {
flex-wrap: nowrap;
flex-basis: 100%;
}
.img {
flex: 0 0 auto;
}
.griditem:nth-child(even) {
margin: 0 0 0 30px;
order: 2
}
.footer {
display: none
}
.griditem:nth-child(odd) {
margin: 0 30px 0 0;
}
}
<header class="header">
Logo
<div class="content">Content</div>
<div class="bottom-content">2</div>
</header>
<main class="main">
<div class="grid">
<div class="griditem">
<div class="img">1</div>
<div class="grid-content">
<h1 class="title">Title</h1>
<p class="text">Lorem ipsum, dolor sit amet consectetur adipisicing elit. Distinctio neque magnam amet, praesentium vel illum error autem voluptatibus veniam consequuntur.</p>
</div>
</div>
</div>
<div class="grid">
<div class="griditem">
<div class="img">2</div>
<div class="grid-content">
<h1 class="title">Title</h1>
<p class="text">Lorem ipsum, dolor sit amet consectetur adipisicing elit. Distinctio neque magnam amet, praesentium vel illum error autem voluptatibus veniam consequuntur.</p>
</div>
</div>
</div>
<div class="grid">
<div class="griditem">
<div class="img">3</div>
<div class="grid-content">
<h1 class="title">Title</h1>
<p class="text">Lorem ipsum, dolor sit amet consectetur adipisicing elit. Distinctio neque magnam amet, praesentium vel illum error autem voluptatibus veniam consequuntur.</p>
</div>
</div>
</div>
</main>
<footer class="footer">
Footer
</footer>
I am trying to learn CSS grid, I have nested CSS grid and in which the parent CSS grid container has multiple columns each of them have 4 rows and I want the rows to be equal to each other for example height of the first row in the first column equal to the that in a second column.
#product-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-gap: 1em;
justify-items: center;
padding: 1em;
}
#product-grid img {
width: 100%;
height: 291px;
}
.product-item {
display: grid;
/* grid-auto-rows:1fr; */
grid-template-rows: 70px, 100px, 200px, 100px;
border-style: solid;
border-color: #2c4251;
border-width: 1px;
border-radius: 5px;
padding: 1em;
}
.cntnt {
text-align: justify;
overflow: hidden;
}
.product-item {}
.more {
text-align: left;
align-self: end;
}
.ttl {
margin-top: 20px;
text-align: center;
align-self: flex-start;
}
<div id="product-grid">
<div class='product-item'>
<img src=imgs/1.png>
<div class='ttl'>this is test title</div>
<div class='cntnt'>this is test caption</div>
<div class='more'>
<div><a href=/view.php?pid=1>more </a></div>
</div>
</div>
<div class='product-item'><img src=imgs/2.jpg>
<div class='ttl'>title</div>
<div class='cntnt'>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Dolores, inventore? Officia perferendis</div>
<div class='more'>
<div><a href=/view.php?pid=2>more </a></div>
</div>
</div>
</div>
I have this code:
.userInfo h2 {
color: #012850;
font-size: 2rem;
font-weight: 800;
line-height: 2.6875rem;
}
.time {
color: #2966A3;
font-size: 1.75rem;
font-weight: 600;
line-height: 2.375rem;
}
.textzone .caption p {
font-size: 1.25rem;
}
.iconsZone {
margin-top: 29px;
display: flex;
height: 60px;
flex-direction: row;
order: 1;
align-content: flex-end;
align-self: end;
}
.textzone .caption {
order: 3;
}
.adHead {
display: flex;
order: 2;
}
.profile-img img {
margin-right: 25px;
width: 150px;
height: auto;
}
<div class="textzone">
<div class="adHead">
<div class="profile-img">
<img src="images/avatar.png" alt="">
</div>
<div class="userInfo">
<h2>Some Name</h2>
<p class="time">05:55 PM</p>
</div>
<div class="caption">
<p> Sed ut perspiciatis, unde omnis iste natus error sit voluptatem accusantium doloremque laudantium</p>
</div>
</div>
<div class="iconsZone">
<div class="comments iconBox">
blah!
</div>
<div class="likes iconBox">
blah blah!
</div>
</div>
</div>
which generates something like the following image:
and I need it to look like this instead:
So I basically almost have it, but can't figure how to make the title and main text go on different rows. I tried with
.caption{flex: 0 1 100%;}
and it makes the heading look correct, but main text is still in the same line. Also, the "blah blah" on the right should be on the same line as some name but guess I can fix that with position absolute.
Right now, my main issue is to "clear the float" (so to speak) of the .caption element
So how should I fix this code? Preferably not changing html (but can do if needed)
Hope these code snippet will help you to understand how the flex-boxes working in css3 and how to arrange items according to our needs without using float property. I added some background colors for all the elements for better understand, what are the behaviors of the certain containers. and used relative(%) sizes to make it somewhat responsive. since it's for the understanding purpose, hope this will help anyone who struggle with the CSS element arranging with flex.
Unfortunately Had to change your HTML base to make it work like you've asked for.
*, body{
box-sizing: border-box;
}
.textzone{
display: flex;
width: 100%;
flex-wrap: wrap;
flex-direction: row;
align-items: flex-start;
justify-content: flex-start;
padding: 10px;
background-color: yellow;
}
.profile-img{
display: flex;
width: 30%;
align-items: center;
justify-content: center;
box-sizing: border-box;
flex-wrap: wrap;
}
.profile-img img{
width: 80%;
height: 80%;
}
.adHead{
display: flex;
width: 70%;
flex-wrap: wrap;
background-color: red;
flex-direction: column;
}
.title-container{
display: flex;
width: 100%;
flex-wrap: wrap;
flex-direction: row;
background-color: brown;
}
.userInfo{
display: flex;
width: 70%;
flex-wrap: wrap;
flex-direction: column;
align-items: flex-start;
justify-content: flex-start;
background-color: tomato;
}
.userInfo h2 {
color: #012850;
font-size: 2rem;
font-weight: 800;
line-height: 2.6875rem;
margin: 0; /* to remove the margin sets by default */
}
.time {
color: #2966A3;
font-size: 1.75rem;
font-weight: 600;
line-height: 2.375rem;
margin: 0;
}
.textzone .caption p {
font-size: 1.25rem;
}
.iconsZone{
display: flex;
width: 30%;
flex-wrap: wrap;
flex-direction: row;
align-items: flex-start;
justify-content: flex-end;
background-color: orange;
}
.comments-iconBox{
display: flex;
width: 50%;
flex-wrap: wrap;
flex-direction: row;
align-items: center;
justify-content: center;
box-sizing: border-box;
padding: 5%;
background-color: skyblue;
}
.likes-iconBox{
display: flex;
width: 50%;
flex-wrap: wrap;
flex-direction: row;
align-items: center;
justify-content: center;
box-sizing: border-box;
padding: 5%;
background-color: aqua;
}
.caption{
display: flex;
width: 100%;
flex-wrap: wrap;
background-color: gray;
}
<div class="textzone">
<div class="profile-img">
<img src="icon2.png" alt="">
</div>
<div class="adHead">
<div class="title-container">
<div class="userInfo">
<h2>Some Name</h2>
<p class="time">05:55 PM</p>
</div>
<div class="iconsZone">
<div class="comments-iconBox">
blah!
</div>
<div class="likes-iconBox">
blah blah!
</div>
</div>
</div>
<div class="caption">
<p> Lorem ipsum dolor sit amet consectetur adipisicing elit.
Corrupti architecto dicta ab, vero minima nesciunt fugiat
perspiciatis nobis eveniet suscipit nostrum, dolore quos molestiae at,
officiis fugit id sit officia? Sed ut perspiciatis, unde omnis iste natus error
sit voluptatem accusantium doloremque laudantium
</p>
</div>
</div>
</div>
I think you need to enable flex items to wrap, and make a few other minor adjustments to your CSS:
.userInfo h2 {
color: #012850;
font-size: 2rem;
font-weight: 800;
line-height: 2.6875rem;
}
.time {
color: #2966A3;
font-size: 1.75rem;
font-weight: 600;
line-height: 2.375rem;
}
.textzone {
display: flex; /* new */
}
.textzone .caption p {
font-size: 1.25rem;
}
.iconsZone {
margin-top: 29px;
display: flex;
height: 60px;
/* flex-direction: row;
order: 1;
align-content: flex-end;
align-self: end; */
}
.textzone .caption {
order: 3;
}
.adHead {
display: flex;
/* order: 2; */
flex-wrap: wrap; /* new */
}
.caption {
flex-basis: 100%; /* new */
}
.profile-img img {
margin-right: 25px;
width: 150px;
height: auto;
}
<div class="textzone">
<div class="adHead">
<div class="profile-img">
<img src="http://i.imgur.com/60PVLis.png" width="50" height="50" alt=""><!-- added for demo -->
</div>
<div class="userInfo">
<h2>Some Name</h2>
<p class="time">05:55 PM</p>
</div>
<div class="caption">
<p> Sed ut perspiciatis, unde omnis iste natus error sit voluptatem accusantium doloremque laudantium</p>
</div>
</div>
<div class="iconsZone">
<div class="comments iconBox">
blah!
</div>
<div class="likes iconBox">
blah blah!
</div>
</div>
</div>