I am trying to design a landing page where different sections have different background-colors. The first section container (brown background) is a Flexbox to position the child elements. Below the first section comes another container (blue background) that also spans the whole width of the page.
Problem: There is some whitespace between the two containers, that I can't remove.
body {
margin: 0;
}
.about-container {
width: 100%;
height: 490px;
display: flex;
justify-content: space-around;
align-items: center;
flex-wrap: wrap;
background: #605B56;
}
#title {
font-size: 28px;
font-weight: 200;
color: #8EB8E5;
}
.pic {
width: 200px;
height: 200px;
border-radius: 50%;
background: #8EB8E5;
}
p {
text-align: right;
color: $white;
}
h3 {
text-align: center;
}
.section-container {
background: #8EB8E5;
}
<div class="about-container">
<div class="about-text">
<h3 id="title">Title</h3>
<p> Lorem ipsum dolor sit amet</p>
</div>
<div class="pic"></div>
</div>
<div class="section-container">
<h3>
Section Title
</h3>
Some text for the next section
</div>
JSFiddle: https://jsfiddle.net/z4oecan1/
Your <h3> elements have a default margin; remove it. use padding on the <h3> instead if you need to push it down.
body {
margin: 0;
}
.about-container {
width: 100%;
height: 490px;
display: flex;
justify-content: space-around;
align-items: center;
flex-wrap: wrap;
background: #605B56;
}
#title {
font-size: 28px;
font-weight: 200;
color: #8EB8E5;
}
.pic {
width: 200px;
height: 200px;
border-radius: 50%;
background: #8EB8E5;
}
p {
text-align: right;
color: $white;
}
h3 {
text-align: center;
margin: 0;
}
.section-container {
background: #8EB8E5;
}
<div class="about-container">
<div class="about-text">
<h3 id="title">Title</h3>
<p> Lorem ipsum dolor sit amet</p>
</div>
<div class="pic"></div>
</div>
<div class="section-container">
<h3>
Section Title
</h3>
Some text for the next section
</div>
Another option is to leave the margins as-is and add overflow:auto to the section-container div to fix the collapsed margins.
body {
margin: 0;
}
.about-container {
width: 100%;
height: 490px;
display: flex;
justify-content: space-around;
align-items: center;
flex-wrap: wrap;
background: #605B56;
}
#title {
font-size: 28px;
font-weight: 200;
color: #8EB8E5;
}
.pic {
width: 200px;
height: 200px;
border-radius: 50%;
background: #8EB8E5;
}
p {
text-align: right;
color: $white;
}
h3 {
text-align: center;
}
.section-container {
background: #8EB8E5;
overflow:auto;
}
<div class="about-container">
<div class="about-text">
<h3 id="title">Title</h3>
<p> Lorem ipsum dolor sit amet</p>
</div>
<div class="pic"></div>
</div>
<div class="section-container">
<h3>
Section Title
</h3>
Some text for the next section
</div>
It's due to the default margin-top of the h3 in the second section, which exceeds its container (collapsing margins....)
To avoid that, set margin-top: 0 for that h3, and to recreate the space above it, add a padding-top to it.
https://jsfiddle.net/031p3m04/1/
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>
This seems like an easy question but I've been trying to fix it for a couple of hours now and I still cannot find a solution. I have a box with two columns like in here:
p {
margin: 0;
padding: 0;
margin-right: 2px;
}
.container {
padding: 5px;
width: 90%;
height: 200px;
margin: auto;
border: 1px black solid;
}
.row {
display: flex;
justify-content: space-between;
width: 100%;
}
.half {
width: 50%;
}
.left-col {
display: flex;
}
.right-col {
text-align: right;
}
.tooltip {
position: relative;
border: 1px black solid;
border-radius: 100%;
width: 14px;
height: 14px;
font-size: 12px;
display: flex;
justify-content: center;
align-items: center;
}
<div class="container">
<div class="row">
<div class="half">
<div class="left-col">
<p>Username picked on regitration:</p>
<div class="tooltip">?</div>
</div>
</div>
<div class="half">
<p class="right-col">
John WithLongSurname
</p>
</div>
</div>
</div>
The problem is, that when I open the page on mobiles, the text on the left column is too long and it wraps (which is good), but its width still takes a whole column, so the tooltip is not next to the text but in the center of the box (it sticks to the right side of the column). Example:
I tried to add width: min-content to the "label" class, but then the whole paragraph just collapses to the smallest possible width. How can I adjust the width of the paragraph, so it will take only as much width as it needs to, so the tooltip will always be next to it?
It is because you are using display: flex; for the .left-col class. By default it will distribute the width automatically and evenly.
Try the styling below to see if it works:
p {
margin: 0;
padding: 0;
margin-right: 2px;
}
.container {
padding: 5px;
width: 90%;
height: 200px;
margin: auto;
border: 1px black solid;
}
.row {
display: flex;
justify-content: space-between;
width: 100%;
}
.half {
width: 50%;
}
.left-col {
display: inline;
}
.right-col {
text-align: right;
}
.tooltip {
position: relative;
border: 1px black solid;
border-radius: 100%;
width: 14px;
height: 14px;
font-size: 12px;
display: inline;
}
p.label {
width: auto;
}
<div class="container">
<div class="row">
<div class="half">
<div class="left-col">
<p class="label">Username picked on regitration:
<span class="tooltip">?</span>
</p>
</div>
</div>
<div class="half">
<p class="right-col">
John WithLongSurname
</p>
</div>
</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 would like my site to look as in this design:
so I tried to create a flexbox with a horizontal display, and each activity will be a flexbox with a column display.
for some reason, it did not work as expected.
I also looked int a possibility of using grid, but it does not seem to offer a solution
something is not working right. wondering whether anyone can enlighten me.
thanks!!!
<!-- **** launch container ****** -->
<section class = "launch-container">
<div class = "launch">
<div>
<h1>Launch</h1>
<p>
Set up your first campaign and get
your reps right to work on our fully
integrated, browser-based platform.
</p>
</div>
<div>
<img src="./images/launch.svg" alt="launch">
</div>
</div>
<div class = "launch-activities"
<div class="upload" >
<img src="./images/upload.svg" alt="upload">
<div class="info">
<h6>Upload your leads</h6>
<p >
Easily upload and manage your contacts
with custom fields and dynamic lists.
</p>
</div>
</div>
<div class="calling" >
<img src="./images/calling.svg" alt="calling">
<div class="info">
<h6>Start Calling</h6>
<p>
Use custom outbound numbers, calling
queues and our preview dialer to ensure
success with your call campaigns.
</p>
</div>
</div>
<div class="script" >
<img src="./images/script.svg" alt="script">
<div class="info">
<h6>Write your script</h6>
<p>
Create personalized scripts to ensure
brand consistency by specifying exactly
what agents should say on the phone.
</p>
</div>
</div>
</div>
</section>
/* *** launch container **** */
.launch-container {
/* display: flex; */
color: #1E95EE;
width: 1280px;
height: 529px;
/* justify-content: space-around; */
}
.launch {
margin-top: 105px;
display: flex;
position: relative;
}
.launch h1 {
color: #1E95EE;
text-align: left;
font-weight: 600;
font-size: 42px;
/* margin-bottom: 0;
margin-top: 16.5px; */
}
.launch p {
color: #1E95EE;
width: 420px;
height: 99px;
text-align: left;
font-weight: 350;
opacity: 0.9;
}
.launch-activities {
display: flex;
justify-content: space-between;
}
.launch-activities
.upload, .calling, .script,
.info p {
color: #1E95EE;
width: 250px;
text-align: left;
display: inline-block;
}
.launch-activities
.upload, .calling, .script,
.info h6 {
font-size: 20px;
font-weight: bolder;
color: #1E95EE;
text-align: left;
}
.launch-activities .upload{
display: flex;
flex-direction: column;
}
.launch-activities .calling{
display: flex;
flex-direction: column;
}
.launch-activities .script{
display: flex;
flex-direction: column;
}
.launch-activities
.upload, .calling, .script,
img {
display: inline;
}
Instead of having all the code for Rome, I suggest that you build the skeleton first, and then add onto it. It seems your wanted .launch-container to be a flex container, which is correct, but for some reason you commented it out, making it a non-flex container. So how can items flow as flex items inside of it?
You also seem to make each flex item in turn another flexbox. That is possible, but from your layout for each section, it seems they don't have to be... they can just be old traditional CSS.
But I suggest you get the skeleton right, and then add a little bit on top of it, and ask another question if one thing doesn't seem to work correctly. Right now you are like putting the whole Rome here and ask how to fix it.
A skeleton:
also on https://jsfiddle.net/gyuL0e3s/2/
/* *** launch container **** */
.launch-container {
display: flex;
color: #1E95EE;
width: 600px;
height: 200px;
align-items: center;
justify-content: space-around;
border: 1px dotted blue;
}
.launch-container .container-item {
border: 1px dotted orange;
width: 100px;
height: 80px;
}
<!-- **** launch container ****** -->
<section class="launch-container">
<div class="launch container-item">
</div>
<div class="launch-activities container-item">
</div>
<div class="calling container-item">
</div>
<div class="script container-item">
</div>
</section>
Need to fix your html mark up first. And in your CSS, you have specified flex-direction as "column" under .upload, .script and .calling. That's why you are seeing the image, heading and description in vertical alignment.
/* *** launch container **** */
.launch-container {
/* display: flex; */
color: #1E95EE;
width: 1280px;
height: 529px;
/* justify-content: space-around; */
}
.launch {
margin-top: 105px;
display: flex;
position: relative;
}
.launch h1 {
color: #1E95EE;
text-align: left;
font-weight: 600;
font-size: 42px;
/* margin-bottom: 0;
margin-top: 16.5px; */
}
.launch p {
color: #1E95EE;
width: 420px;
height: 99px;
text-align: left;
font-weight: 350;
opacity: 0.9;
}
.launch-activities {
display: flex;
justify-content: space-between;
}
.launch-activities
.upload, .calling, .script,
.info p {
color: #1E95EE;
width: 250px;
text-align: left;
}
.launch-activities
.upload, .calling, .script,
.info h6 {
font-size: 20px;
font-weight: bolder;
color: #1E95EE;
text-align: left;
margin: 2px 0 0 0;
}
.info {
margin:0 0 0 15px;
}
.upload, .calling, .script {
display: flex;
}
<!-- **** launch container ****** -->
<section class = "launch-container">
<div class = "launch">
<div>
<h1>Launch</h1>
<p>
Set up your first campaign and get
your reps right to work on our fully
integrated, browser-based platform.
</p>
</div>
<div>
<img src="./images/launch.svg" alt="launch">
</div>
</div>
<div class = "launch-activities">
<div class="upload" >
<img src="./images/upload.svg" alt="upload">
<div class="info">
<h6>Upload your leads</h6>
<p >
Easily upload and manage your contacts
with custom fields and dynamic lists.
</p>
</div>
</div>
<div class="calling" >
<img src="./images/calling.svg" alt="calling">
<div class="info">
<h6>Start Calling</h6>
<p>
Use custom outbound numbers, calling
queues and our preview dialer to ensure
success with your call campaigns.
</p>
</div>
</div>
<div class="script" >
<img src="./images/script.svg" alt="script">
<div class="info">
<h6>Write your script</h6>
<p>
Create personalized scripts to ensure
brand consistency by specifying exactly
what agents should say on the phone.
</p>
</div>
</div>
</div>
</section>
ok, solved it.
with nested flexboxes, as follows:
<!-- **** launch container ****** -->
<section class = "launch-container">
<div class = "launch">
<div>
<h1>Launch</h1>
<p>
Set up your first campaign and get
your reps right to work on our fully
integrated, browser-based platform.
</p>
</div>
<div>
<img src="./images/launch.svg" alt="launch">
</div>
</div>
<div class = "launch-activities">
<div class="upload container-item" >
<div >
<img src="./images/upload.svg" alt="upload">
</div>
<div class="information">
<h6>Upload your leads</h6>
<p>
Easily upload and manage your contacts
with custom fields and dynamic lists.
</p>
</div>
</div>
<div class="calling container-item" >
<div>
<img src="./images/calling.svg" alt="calling">
</div>
<div class="information">
<h6>Start Calling</h6>
<p>
Use custom outbound numbers, calling
queues and our preview dialer to ensure
success with your call campaigns.
</p>
</div>
</div>
<div class="script container-item" >
<div class="information">
<img src="./images/script.svg" alt="script">
</div>
<div class="information">
<h6>Write your script</h6>
<p>
Create personalized scripts to ensure
brand consistency by specifying exactly
what agents should say on the phone.
</p>
</div>
</div>
</div>
</section>
/* *** launch container **** */
.launch-container {
display: flex;
flex-direction: column;
color: #1E95EE;
width: 1280px;
height: 529px;
/* justify-content: space-around; */
}
.launch {
margin-top: 105px;
display: flex;
position: relative;
}
.launch h1 {
color: #1E95EE;
text-align: left;
font-weight: 600;
font-size: 42px;
/* margin-bottom: 0;
margin-top: 16.5px; */
}
.launch p {
color: #1E95EE;
width: 420px;
height: 99px;
text-align: left;
font-weight: 350;
opacity: 0.9;
}
.launch-activities {
display: flex;
color: #1E95EE;
width: 1280px;
/* height: 700px; */
margin-right: 120px;
margin-left: 120px;
align-items: top;
justify-content:space-between;
border: 1px dotted blue;
}
.container-item {
border: 1px dotted orange;
display: flex;
width: 300px;
justify-content: space-between;
/* height: 110px; */ */
}
.container-item img {
margin-left: 0;
margin-top: 0;
}
.container-item h6 {
font-size: 20px;
font-weight: 550;
color: #1E95EE;
text-align: left;
padding: 0;
margin-top: 0;
margin-bottom: 0;
/* margin: 2px 0 0 0; */
}
.container-item p {
font-size: 14px;
font-weight: 400;
color: #1E95EE;
width: 250px;
text-align: left;
margin-top: 6px;
}
.information {
display: flex;
flex-direction: column;
}
.launch-activities .upload{
display: flex;
}
.launch-activities .calling{
display: flex;
}
.launch-activities .script{
display: flex;
}
I want to stretch the image vertically based on the content by using flex properties without using height. If the content size is increases or decreases image should be stretch automatically.
please, can anyone suggest me in the right direction?
Thanks in advance...
below is my code snippet
.wrapper {
background-color: red;
height: 100%;
width: 100%;
padding-top: 20px;
}
.section-inner {
position: relative;
max-width: 1100px;
margin: 0 auto;
}
.at-crop-box-content {
background: #ffffff;
flex-basis: 60%;
align-items: stretch;
display: flex;
flex-direction: column;
align-self: stretch;
}
.at-crop-box {
display: flex;
align-items: stretch;
width: 100%;
margin-bottom: 60px;
border-radius: 10px;
overflow: hidden;
}
.at-crop-box-thumb {
flex-basis: 40%;
display: flex;
align-items: stretch;
align-content: stretch;
}
.at-crop-img {
max-width: 100%;
}
.at-crop-head {
font-family: sans-serif;
font-size: 40px;
font-weight: bold;
line-height: 0.8;
color: #000000;
margin-bottom: 22px;
}
.at-crop-info {
font-family: sans-serif;
font-size: 24px;
line-height: 1.8;
color: #000000;
}
<div class="wrapper">
<div class="section-inner">
<div class="at-crop-box">
<div class="at-crop-box-thumb">
<figure><img class="at-crop-img" src="https://i.ibb.co/wCjFWjB/apple-2819015-340.jpg"></figure>
</div>
<div class="at-crop-box-content">
<h2 class="at-crop-head">Heading is here</h2>
<p class="at-crop-info">It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model.</p>
</div>
</div>
</div>
</div>
Are you looking to fit the image vertically like this?
Then provide
.figure {
display: flex;
}
Since you have already provided stretch for items, the content should be display flex to get it reflected.
.figure {
display: flex;
}
.wrapper {
background-color: red;
width: 100%;
padding-top: 20px;
}
.section-inner {
position: relative;
max-width: 1100px;
margin: 0 auto;
}
.at-crop-box-content {
background: #ffffff;
flex-basis: 60%;
align-items: stretch;
display: flex;
flex-direction: column;
align-self: stretch;
}
.at-crop-box {
display: flex;
align-items: stretch;
width: 100%;
margin-bottom: 60px;
border-radius: 10px;
overflow: hidden;
}
.at-crop-box-thumb {
flex-basis: 40%;
display: flex;
align-items: stretch;
align-content: stretch;
}
.at-crop-img {
max-width: 100%;
height: 100%;
}
.at-crop-head {
font-family: sans-serif;
font-size: 40px;
font-weight: bold;
line-height: 0.8;
color: #000000;
margin-bottom: 22px;
}
.at-crop-info {
font-family: sans-serif;
font-size: 24px;
line-height: 1.8;
color: #000000;
}
<div class="wrapper">
<div class="section-inner">
<div class="at-crop-box">
<div class="at-crop-box-thumb">
<figure><img class="at-crop-img" src="https://i.ibb.co/wCjFWjB/apple-2819015-340.jpg"></figure>
</div>
<div class="at-crop-box-content">
<h2 class="at-crop-head">Heading is here</h2>
<p class="at-crop-info">It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model.</p>
</div>
</div>
</div>
</div>
TL;DR; You have 2 options:
.at-crop-box-thumb img {
height: 100%;
}
or
.at-crop-box-thumb figure {
display: flex;
align-items: stretch; /* in this case without this it still works btw */
}
Long answer version:
I want to stretch the image vertically based on the content
Add height: 100% to the img
by using flex properties without using height
Why? height: 100% is super simple, it does exactly what you want
If the content size is increases or decreases image should be stretch automatically.
height: 100% does exactly that
can anyone suggest me in the right direction?
Use height: 100%. Here's the image as I inspect the DOM.
As you can see, the figure element content already fully vertical stretches with the align something: stretch you set. There's only the img element inside it is not stretched yet. You then have 2 options: simply set img{ height: 100%; }, or again make the figure a flex container, then align-items: stretch; to align its content (img), yet it's more complicated and doesn't make as semantical sense as height: 100%. I suggest using height: 100% despite you said you wanted a solution without using height.
Here's the code after add 1 line of code height: 100% in img. But it'll likely look terrible, because its width is relatively smaller than its height if the content on the right is too long, set an image's sizes based on dynamic text isn't a good idea. But as what you want is to stretch the image's height base on the content height, here's the code.
.wrapper {
background-color: red;
height: 100%;
width: 100%;
padding-top: 20px;
}
.section-inner {
position: relative;
max-width: 1100px;
margin: 0 auto;
}
.at-crop-box-content {
background: #ffffff;
flex-basis: 60%;
align-items: stretch;
display: flex;
flex-direction: column;
align-self: stretch;
}
.at-crop-box {
display: flex;
align-items: stretch;
width: 100%;
margin-bottom: 60px;
border-radius: 10px;
overflow: hidden;
}
.at-crop-box-thumb {
flex-basis: 40%;
display: flex;
align-items: stretch;
align-content: stretch;
}
.at-crop-box-thumb img {
height: 100%;
}
.at-crop-img {
max-width: 100%;
}
.at-crop-head {
font-family: sans-serif;
font-size: 40px;
font-weight: bold;
line-height: 0.8;
color: #000000;
margin-bottom: 22px;
}
.at-crop-info {
font-family: sans-serif;
font-size: 24px;
line-height: 1.8;
color: #000000;
}
<div class="wrapper">
<div class="section-inner">
<div class="at-crop-box">
<div class="at-crop-box-thumb">
<figure><img class="at-crop-img" src="https://i.ibb.co/wCjFWjB/apple-2819015-340.jpg"></figure>
</div>
<div class="at-crop-box-content">
<h2 class="at-crop-head">Heading is here</h2>
<p class="at-crop-info">It is a long established fact that a reader will be distracted by the readable content
of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal
distribution of letters, as opposed to using 'Content here, content here', making it look like readable
English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model.</p>
</div>
</div>
</div>
</div>
In the case you don't want to use height: 100%, here's the code using flex. Add
.at-crop-box-thumb figure {
display: flex;
align-items: stretch;
}
.wrapper {
background-color: red;
height: 100%;
width: 100%;
padding-top: 20px;
}
.section-inner {
position: relative;
max-width: 1100px;
margin: 0 auto;
}
.at-crop-box-content {
background: #ffffff;
flex-basis: 60%;
align-items: stretch;
display: flex;
flex-direction: column;
align-self: stretch;
}
.at-crop-box {
display: flex;
align-items: stretch;
width: 100%;
margin-bottom: 60px;
border-radius: 10px;
overflow: hidden;
}
.at-crop-box-thumb {
flex-basis: 40%;
display: flex;
align-items: stretch;
align-content: stretch;
}
.at-crop-box-thumb figure {
display: flex;
align-items: stretch;
}
.at-crop-img {
max-width: 100%;
}
.at-crop-head {
font-family: sans-serif;
font-size: 40px;
font-weight: bold;
line-height: 0.8;
color: #000000;
margin-bottom: 22px;
}
.at-crop-info {
font-family: sans-serif;
font-size: 24px;
line-height: 1.8;
color: #000000;
}
<div class="wrapper">
<div class="section-inner">
<div class="at-crop-box">
<div class="at-crop-box-thumb">
<figure><img class="at-crop-img" src="https://i.ibb.co/wCjFWjB/apple-2819015-340.jpg"></figure>
</div>
<div class="at-crop-box-content">
<h2 class="at-crop-head">Heading is here</h2>
<p class="at-crop-info">It is a long established fact that a reader will be distracted by the readable content
of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal
distribution of letters, as opposed to using 'Content here, content here', making it look like readable
English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model.</p>
</div>
</div>
</div>
</div>
Maybe this is something you need?
<div class="wrapper">
<div class="section-inner">
<div class="at-crop-box">
<div class="at-crop-box-thumb">
<figure><img class="at-crop-img" src="https://i.ibb.co/wCjFWjB/apple-2819015-340.jpg"></figure>
</div>
<div class="at-crop-box-content">
<h2 class="at-crop-head">Heading is here</h2>
<p class="at-crop-info">It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model.</p>
</div>
</div>
</div>
</div>
.wrapper {
background-color: red;
height: 100%;
width: 100%;
padding-top: 20px;
}
.section-inner {
position: relative;
max-width: 1100px;
margin: 0 auto;
}
.at-crop-box-content {
background: #ffffff;
flex-basis: 60%;
align-items: stretch;
display: flex;
flex-direction: column;
align-self: stretch;
}
.at-crop-box {
display: flex;
width: 100%;
margin-bottom: 60px;
border-radius: 10px;
}
.at-crop-box-thumb {
flex-basis: 40%;
overflow: hidden;
}
figure {
display: flex;
height: 100%;
margin: 0;
/* padding: 10px;
padding-right: 0;
margin-right: 10px; */ /* Use margin and padding as you like */
box-sizing: border-box;
overflow: hidden;
justify-content: center;
}
.at-crop-img {
width: auto;
height: 100%;
flex-shrink: 0;
flex-grow: 0;
}
.at-crop-head {
font-family: sans-serif;
font-size: 40px;
font-weight: bold;
line-height: 0.8;
color: #000000;
margin-bottom: 22px;
}
.at-crop-info {
font-family: sans-serif;
font-size: 24px;
line-height: 1.8;
color: #000000;
}
A Working codepen: https://codepen.io/leo-melin/pen/xxbgNxK
You can give display block and give height 100% to your image;
.at-crop-img {
max-width: 100%;
height:100%;
display:block;
}
.wrapper {
background-color: red;
height: 100%;
width: 100%;
padding-top: 20px;
}
.section-inner {
position: relative;
max-width: 1100px;
margin: 0 auto;
}
.at-crop-box-content {
background: #ffffff;
flex-basis: 60%;
align-items: stretch;
display: flex;
flex-direction: column;
align-self: stretch;
}
.at-crop-box {
display: flex;
align-items: stretch;
width: 100%;
margin-bottom: 60px;
border-radius: 10px;
overflow: hidden;
}
.at-crop-box-thumb {
flex-basis: 40%;
display: flex;
align-items: stretch;
align-content: stretch;
}
.at-crop-img {
max-width: 100%;
height:100%;
display:block;
}
.at-crop-head {
font-family: sans-serif;
font-size: 40px;
font-weight: bold;
line-height: 0.8;
color: #000000;
margin-bottom: 22px;
}
.at-crop-info {
font-family: sans-serif;
font-size: 24px;
line-height: 1.8;
color: #000000;
}
<div class="wrapper">
<div class="section-inner">
<div class="at-crop-box">
<div class="at-crop-box-thumb">
<figure><img class="at-crop-img" src="https://i.ibb.co/wCjFWjB/apple-2819015-340.jpg"></figure>
</div>
<div class="at-crop-box-content">
<h2 class="at-crop-head">Heading is here</h2>
<p class="at-crop-info">It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model.</p>
</div>
</div>
</div>
</div>