HTML CSS : put flexbox elements next to each other - html

I'm working on a project where I have to create an online bookstore webpage using only HTML and CSS . I want to display "about us" information for the shop using a style like in the image below :
Basically I want to put an image and a text in the way displayed above . Using flexbox however I have trouble syncing the image and the text I have because I have difficulties setting the image width to cover half the flex container and the part of my text the other half .
This is my code :
.flex-container {
display: flex;
justify-content: flex-start;
flex-direction: row;
background-color: orange;
opacity: 0.7;
}
.flex-container>div {
margin: 0;
width: 100%;
height: auto;
}
#fleximg>img {
width: 60%;
height: auto;
}
#about {
width: 50%;
margin-right: 300px;
height: auto;
}
<div class="flex-container">
<div id="fleximg"><img src="https://placehold.it/400x400" alt=d esk/></div>
<div id="about">
<!-- text i want to place next to image -->
<h1> ABOUT US </h1>
<p>
In these rough times we experience right now being forced to stay at home staring at nothing does actually nothing.This is why we have created this online book delivery website to provide the company of a book to those who can't go outside to buy or read
a book at a local bookshop .
</p>
</div>
</div>
When i run my page I get the picture below where the image and the text are not next to each other and I have trouble readjusting their sizes
I would appreciate your help with guiding me to solve my problem

First, if the image height is taller than the right-col content - even simple width: 100%; height: auto for the image could work.
div{
border: 2px solid black;
}
#fleximg img{
width: 100%;
height: auto;
vertical-align: middle;
}
.flex-container {
display: flex;
background-color: orange;
}
#fleximg{
flex-basis: 40%;
}
#about {
flex-basis: 60%;
display: flex;
align-items: center; /* align v */
}
<div class="flex-container">
<div id="fleximg" class="col">
tall image
<img src="https://placehold.it/400x700" alt=d esk/>
</div>
<div id="about" class="col">
<!-- text i want to place next to image -->
<div>
<h1> ABOUT US </h1>
</div>
</div>
</div>
But the idea above it less useful for dynamic sites.
More responsive approaches:
By background image
For the "left-col" Use background-image and background-size: cover.
div{
border: 2px solid black;a
}
.flex-container {
display: flex;
background-color: orange;
}
#fleximg{
flex-basis: 40%;
background-image: url("https://picsum.photos/1111/1300");
background-repeat: no-repeat;
background-size: cover
}
#about {
flex-basis: 60%;
padding: 100px 10px;
display: flex;
align-items: center; /* align v */
}
<div class="flex-container">
<div id="fleximg" class="col">
</div>
<div id="about" class="col">
<!-- text i want to place next to image -->
<div>
<h1> ABOUT US </h1>
<p>
In these rough times we experience right now being forced to stay at home staring at nothing does actually nothing.This is why we have created this online book delivery website to provide the company of a book to those who can't go outside to buy or read
a book at a local bookshop .
</p>
</div>
</div>
</div>
By image element
Without using background-image for the left-col this idea is more "tricky".
For img element - One idea/solution is to use this "trick":
https://css-tricks.com/aspect-ratio-boxes/
Set image col "parent" position to relative and put inside an absolute image (100% width/height + object-fit: cover).
div{
border: 2px solid black;
}
.flex-container {
display: flex;
background-color: orange;
}
#fleximg{
flex-basis: 40%;
top-padding: 100%;
position: relative;
}
#fleximg > img {
width: 100%;
height: 100%;
position: absolute;
object-fit: cover ;
}
#about {
flex-basis: 60%;
padding: 100px 10px;
display: flex;
align-items: center; /* align v */
}
<div class="flex-container">
<div id="fleximg" class="col">
<img src="https://placehold.it/400x400" alt=d esk/>
</div>
<div id="about" class="col">
<!-- text i want to place next to image -->
<div>
<h1> ABOUT US </h1>
<p>
In these rough times we experience right now being forced to stay at home staring at nothing does actually nothing.This is why we have created this online book delivery website to provide the company of a book to those who can't go outside to buy or read
a book at a local bookshop .
</p>
</div>
</div>
</div>
Important: From the design aspect - There is no magic solution to suit all situations. It also depends on the amount of content (text/images and so on) you place in the right "content" column and the width of the screen (min-width/height/padding/margin and Media query useful her).

You should set css class flex-container is width: 100% and #fleximg is width:50%, #about is width:50% and use the background in css instead for img tag.
Example:
.flex-container {
display: flex;
justify-content: flex-start;
flex-direction: row;
background-color: orange;
opacity: 0.7;
width: 100%;
height: auto;
};
#fleximg {
width: 50%;
height: auto;
background: url('') center no-repeat;
background-size: cover;
};
#about {
width: 50%;
margin-right: 0;
height: auto;
};

Related

How to make this image move to the right?

So, I was doing this Frontend Mentor challenge (at https://www.frontendmentor.io/challenges/notifications-page-DqK5QAmKbC) while I had run into this problem - I couldn't align the "Chess" image in the "Kimberly Smith" notification to the right.
Here is all the code I have written related to the notification:
The HTML:
<div class="notification">
<div class="notification__container">
<img src="assets\images\avatar-kimberly-smith.webp" class="image" />
<div class="notification-formatting">
<div class="align-right">
<div><strong>Kimberly Smith</strong> commented on your picture
<br /><time>1 week ago</time>
</div>
<div class="img-container"><img src="assets/images/image-chess.webp" alt="Chess" class="image chess"></div>
</div>
</div>
</div>
</div>
The CSS:
img,
picture,
svg,
video {
display: block;
max-width: 100%;
}
.notification {
background-color: #f6fafd;
display: flex;
align-items: center;
}
.notification__container {
display: flex;
align-items: center;
}
.image {
display: flex;
align-items: center;
width: 50px;
margin-right: 5px;
}
.notification_image--main-message-content {
display: flex;
}
.align-right {
display: flex;
}
Here is the Output
Here is the Expected Output
Here are the solutions I have tried:
display: block;
margin-left: auto;
float: right;
text-align: right;
display: flex;
justify-content: right;
Here is the live website: https://prismatic-capybara-4ba8da.netlify.app/
Here is the GitHub Repository for deeper reference: https://github.com/vishalscodes/frontendmentor-notifications-page
Thank You.
It's possible to massively simplify your markup as follows:
Class notification. This is a flex box so items will try to fit side by side on one line. As the user's image, the main text and the 'chess' image are all on one line we don't need to add any more divs to this. We can just insert them directly, especially as you've made all img elements as blocks (this is always a good move imho).
Class notification-formatting is used to isolate the text so that the text and time stack on top of each other. As this is a flex item, this will try to shrink to fit the content.
We don't need a wrapper around the image with the chess class as that's already a block level element so to get that to move to the right I've added an align-right class. That simply has an inline-margin of auto 0. This is a fairly standard way of moving elements to the right of the page.
Some good resources here:
Complete guide to flexbox on css tricks
Margin on css tricks
Useful css reset by Kevin Powell (e.g. setting img to block)
Any questions just drop me a comment and I'll try help out.
img,
picture,
svg,
video {
display: block;
max-width: 100%;
}
.notification {
background-color: #f6fafd;
display: flex;
gap: 5px; /* I've removed the margin-right from your image and set the gap on the parent element so your 'chess' image moves all the way to the right */
}
.image {
width: 50px;
border-radius: 5px;
}
.align-right {
margin-inline: auto 0; /* if we set the right margin to 0 then setting the left margin to 'auto' causes it to expand to fit the available width */
}
.round {
border-radius: 100vw; /* make the radius massive so it defaults to a circle */
}
<div class="notification">
<img src="https://picsum.photos/id/64/50/50" class="image round" />
<div class="notification-formatting">
<strong>Kimberly Smith</strong> commented on your picture
<br /><time>1 week ago</time>
</div>
<img src="https://picsum.photos/id/237/50/50" alt="Chess" class="image align-right">
</div>
Base on your code you can set to
.align-right {justify-content: space-between; width: 100%; display: flex;}
and set 100% width to all parents divs you can see code bellow
img,
picture,
svg,
video {
display: block;
max-width: 100%;
}
.notification {
width: 100%;
background-color: #f6fafd;
display: flex;
align-items: center;
}
.notification-formatting {
width: 100%;
}
.notification__container {
display: flex;
align-items: center;
width: 100%;
}
.image {
display: flex;
align-items: center;
width: 50px;
margin-right: 5px;
}
.notification_image--main-message-content {
display: flex;
}
.align-right {
display: flex;
justify-content: space-between;
width: 100%;
}
<div class="notification">
<div class="notification__container">
<img src="assets\images\avatar-kimberly-smith.webp" class="image" />
<div class="notification-formatting">
<div class="align-right">
<div><strong>Kimberly Smith</strong> commented on your picture
<br /><time>1 week ago</time></div>
<div class="img-container"><img src="assets/images/image-chess.webp" alt="Chess" class="image chess"></div>
</div>
</div>
</div>
</div>

How to place divs over background image and keeping relative position and size when the browser is resized

I am trying to place 4 divs over a background image that would keep relative position and size as the browser is resized.
Here is the desired layout:
I have a big background (pink) that is placed with:
#screenFiller {
width: 100vw;
height: 100vh;
background-size: contain;
background-image: url("myimg.png");
background-repeat: no-repeat;
}
There are 4 main divs (red boxes). The two tops ones (side by side) contain a button each (blue boxes) with text (white squiggly lines) above the buttons but still in the red. I am positioning the divs next to each other using:
.flex {
display: flex;
justify-content: Left;
flex: none;
}
The main problem I am having is with the two top divs in that one is not keeping its height (it shrinks to content). I do understand that I will need to handle reducing the text size using a media query or something.
The stripped-down HTML looks like:
<div class="flex ">
<div class="boxme">
<div>
<p class="boldtext">Blha blah balh</p>
<div style="margin:10%;">
<button type="button" class="bigbut gborder5" onclick="window.location.href=''">Syart New</button>
</div>
</div>
</div>
<div class="boxme marl100">
<div>
<p class="boldtext">blah</p>
<div>
<button type="button" class="bigbut gborder5" onclick="window.location.href=''">Start New</button>
</div>
</div>
</div>
</div>
With boxme being:
.boxme {
background-color: white;
width: 25%;
height: 10%;
text-align: center;
}
Finally, all four divs are wrapped in a div with the following css
.relpos {
position: relative;
top: 36%;
left: 4%;
width: 85%
}
Please feel free to take me on an alternate path.
Bootstrap is available if that helps but currently, everything is just HTML and CSS.
Thank you in advanced for any consideration.
Normally, you never want to have fixed width, height, margin or paddings.
For your question, your flex values should be to put your content in the bottom left corner:
.container {
display: flex;
align-items: flex-end;
flex-direction: row; // default
}
Here is the full example that can be run as code snippet:
body {
height: 100vh;
}
body {
background-color: #fcf;
}
.container {
display: flex;
align-items: flex-end;
gap: 20px;
height: 100%;
padding: 20px;
}
.container>div {
background-color: #faa;
padding: 10px;
}
<div class="container">
<div>
<p>Text</p>
<button>Cick</button>
</div>
<div>
<p>Text</p>
<button>Cick</button>
</div>
</div>
I would strongly advise you to learn the fundamentals of html and css from other resources.

How to adjust rectangular images to show up as a square in an instagram-like grid of images without losing page responsiveness

If you guys take a look at the code, when I add squared images (first row), the grid will fit perfectly just like instagram. I want to make different shaped images fits in this same squared width and height when I add them (second row).
The problem is, if I just try to make it a square by changing the width and height of the .column > img selector from 100% to 300px for example, the images won't resize in page responsiveness and everything becomes a mess of images overlaying each other.
body {
font-family: "Open Sans", Arial, sans-serif;
}
* {
box-sizing: border-box;
}
.container {
width: 100%;
max-width: 930px;
margin-right: auto;
margin-left: auto;
}
.column {
width: 33.33%;
margin-right: 30px;
}
.row {
display: flex;
flex-direction: row;
justify-content: center;
margin-bottom: 28px;
}
.column>img {
width: 100%;
height: 100%;
}
#media (max-width: 760px) {
.row {
margin-bottom: 3px;
}
.column {
margin-right: 3px;
}
}
#media (max-width: 450px) {
.row {
flex-direction: column;
justify-content: center;
}
.column {
width: 100%;
margin-bottom: 6px;
}
}
<div class="container">
<div class="row">
<div class="column">
<img src="https://images.unsplash.com/photo-1498471731312-b6d2b8280c61?w=500&h=500&fit=crop">
</div>
<div class="column">
<img src="https://images.unsplash.com/photo-1515023115689-589c33041d3c?w=500&h=500&fit=crop">
</div>
<div class="column">
<img src="https://images.unsplash.com/photo-1502630859934-b3b41d18206c?w=500&h=500&fit=crop">
</div>
</div>
<div class="row">
<div class="column">
<img src="https://images.unsplash.com/photo-1523354177913-be035fcee55e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1567&q=80">
</div>
<div class="column">
<img src="https://images.unsplash.com/photo-1563281746-48bb478e9b2a?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1400&q=80">
</div>
<div class="column">
<img src="https://images.unsplash.com/photo-1563170446-9c3c0622d8a9?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1534&q=80">
</div>
</div>
</div>
Is there a way to make all images a square and at the same time keep the responsiveness of the width and height when resizing the page? Thanks in advance.
I made a solution. In my solution I've used object-fit property to resize image. Check it. Hope it will be helpful to you.
body {
font-family: "Open Sans", Arial, sans-serif;
}
* {
box-sizing: border-box;
}
.container {
width: 100%;
max-width: 930px;
margin-right: auto;
margin-left: auto;
}
.column {
width: 33.33vw; /*These properties are changed*/
height: 33.33vw; /*These properties are changed*/
margin-right: 30px;
}
.row {
display: flex;
flex-direction: row;
justify-content: center;
margin-bottom: 28px;
}
.column>img {
width: 33.33vw; /*These properties are changed*/
height: 33.33vw; /*These properties are changed*/
object-fit: cover; /*These properties are changed*/
}
#media (max-width: 760px) {
.row {
margin-bottom: 3px;
}
.column {
margin-right: 3px;
}
}
#media (max-width: 450px) {
.row {
flex-direction: column;
justify-content: center;
}
.column {
width: 100%;
margin-bottom: 6px;
}
}
<div class="container">
<div class="row">
<div class="column">
<img src="https://images.unsplash.com/photo-1498471731312-b6d2b8280c61?w=500&h=500&fit=crop">
</div>
<div class="column">
<img src="https://images.unsplash.com/photo-1515023115689-589c33041d3c?w=500&h=500&fit=crop">
</div>
<div class="column">
<img src="https://images.unsplash.com/photo-1502630859934-b3b41d18206c?w=500&h=500&fit=crop">
</div>
</div>
<div class="row">
<div class="column">
<img src="https://images.unsplash.com/photo-1523354177913-be035fcee55e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1567&q=80">
</div>
<div class="column">
<img src="https://images.unsplash.com/photo-1563281746-48bb478e9b2a?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1400&q=80">
</div>
<div class="column">
<img src="https://images.unsplash.com/photo-1563170446-9c3c0622d8a9?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1534&q=80">
</div>
</div>
</div>
You can abuse padding for this.
tl;dr: https://jsfiddle.net/Hoargarth/u247vz0k/ Just look at the fiddle, pretty self explanatory
First of all we are using flexboxes, for this we need a flex container and flex items in it.
<div class="flex-container">
<div class="flex-item">
<div class="image-wrapper">
<div class="image" style="background-image: url('https://www.url.to/image.png');">
</div>
</div>
</div>
<!-- Any number of flex items inside container -->
</div>
I'm not explayning the flex-system here, I guess you should know about it.
But for everyone not knowing about flex, here is a pretty good explanation: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
So we start at the flex-item:
position: relative because we need the next element
(image-wrapper) to be absolute positioned to flex-item
width: 32%
becasue you want 3 images per row, don't forget to give your
flex-container a width
padding-bottom: 32% the padding is the key, 32% padding is relative to the width of the flex-container. So if you use padding-bottom: 100%, the flex-item's height would be exact same like flex-container width. In our case we want a quadratic image, so we use 32%
.flex-item {
position: relative;
width: 32%;
padding-bottom: 32%;
}
Next is image-wrapper:
position: absolute because we don't wanna take this container (or any other container inside this one) to take up any more space.
overflow: hidden to make sure nothing can escape our quadratic image and overlaps to another container
.image-wrapper {
position: absolute;
overflow: hidden;
width: 100%;
height: 100%;
}
And last, the image itself:
No magic here, just add your background image as background-image: url() in html so you don't have to create a lot of extra classes.
position: relative I don't remember why I added it, maybe some crossbrowser related stuff. But you can try to remove it, it's working on Firefox without.
background *-size: cover so all the quadratic space gets filled, no matter what size the image is; *-position: 50% to completely center the image (vertically and horizontally); *-repeat: no-repeat you don't really need it since background-size: cover fills the whole space, I just added it so there is no special case where the image would be repeated
.image {
position: relative;
height: 100%;
background-size: cover;
background-position: 50%;
background-repeat: no-repeat;
}
This solution is responsive out of the box, but you can change the number of Images per Row with simple Media Queries:
Example:
/*Window Width smaller 800px with two images per row*/
.flex-item {
position: relative;
width: 48%;
padding-bottom: 48%;
}
/*Window Width larger or equal 800px with three images per row*/
#media (min-width: 800px){
.flex-item {
width: 32%;
padding-bottom: 32%;
}
}
I hope it's understandable, if not let me know!

How do I scale the height of a div the same way that a div with an image does?

I have 2 divs that are floated next to each other. In one of the divs I have an image that scales (both it´s height and width) when I decrease the size of the browser window. In the other div I have some other content, but this is only being scaled in width when I decrease the size of the browser window. I want both of the divs to have the same height at all times, even when they are being scaled. Is this possible?
If you want a live preview, please check out this link:
http://jjberg.com/cipher/index.html
I know part of the problem is that I´ve actually set a height of 500px to the cipherSide div. This is because so far I haven´t been able to make the height of this div closer to the height of the pinupSide div in any other way.
I tried to copy the declarations from the pinupSide and pinUpGirl to the cipherSide and verticalAlign divs, but to no avail. This only pushed the content in the cipherSide div all the way to the top.
<div class="container">
<div class="pinupSide">
<img class="pinUpGirl" src="images/pin_up_edited_x2.png" alt="Pin up girl">
</div>
<div class="cipherSide">
<div class="verticalAlign">
<h1> Dirty Diana </h1>
<p>Dirty Diana wants to send dirty love messages to her husband, but she does not want Big Brother to know about it. Try out the tool I made for her!</p>
<textarea rows="10" placeholder="Insert the text you want to cipher or decipher here!" required></textarea>
<button id="cipherIT">Cipher It!</button>
<button id="deCipher">Decipher!</button>
<p id="newOne"></p>
</div><!-- verticalAlign -->
</div><!-- cipherSide -->
</div><!-- container -->
.container {
max-width: 992px;
height: 100%;
margin: 0 auto;
background: blue;
}
.pinupSide {
background: green;
width: 50%;
height: 100%;
float: left;
}
.pinUpGirl {
max-width: 100%;
max-height: 100%;
background: black;
}
.cipherSide {
position: relative;
background: red;
width: 50%;
height: 500px;
float: left;
}
.verticalAlign {
position: absolute;
top: 25%;
height: 50%;
width: 100%;
background: yellow;
}
I want both of the divs to have the same height at all times, no matter how I´m scaling the width of the browser window.
Considering you code I assume you want the two elements to have the same height but also the same width at all time. I also assume you want the image to be as big as possible inside the left element without being distorted. Is that right?
If you can use CSS Grid, you can achieve that layout with a grid made up of two columns of each 1fr, which represent one fraction of the available space. See the following code:
The <img> element has its width set to 100% so that it is as big as possible inside its parent element, and its parent element has the font-size set to 0 to remove an unwanted space below the image.
body {
margin: 0;
background-color: #3ff4fe;
}
.container {
max-width: 992px;
margin: auto;
display: grid;
grid-template-columns: 1fr 1fr;
}
.image {
background-color: black;
font-size: 0;
}
.image img {
width: 100%;
}
.text {
background-color: red;
}
<div class="container">
<div class="image">
<img src="http://jjberg.com/cipher/images/pin_up_edited_x2.png" alt="Pin up girl">
</div>
<div class="text">
Some text
</div>
</div>
Does this help?
I second the use of grid like Auguste said. You could also use flex-box instead of floats and absolute positioning. Here is one possible implementation.
You'll probably have to play with object-fit on the image. Or just set the background of the pinup side to be the image and change the positioning through background properties. Either way it should work out.
You can also set hard heights and widths if you want to and just you the flex-box for positioning.
If you run the code snippet be sure to view it full screen because it uses view-port units for the height of the container.
* {
box-sizing: border-box;
}
.container {
padding: 2rem;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.pinupSide,
.cipherSide {
flex: 1 1;
height: 100%;
display: flex;
justify-content: center;
flex-direction: column;
}
.pinupSide {
align-items: center;
background: rgba(0,0,0,.6);
}
.pinUpGirl {
width: 100%;
object-fit: cover;
object-position: 50% 50%;
}
.cipherSide {
align-items: flex-start;
background: rgba(231, 76, 60, 1)
}
.heading-group {
background: rgba(241, 196, 15, 1);
}
textarea {
width: 100%;
}
.button-group {
width: 100%;
}
<div class="container">
<div class="pinupSide">
<img class="pinUpGirl" src="https://images.unsplash.com/photo-1530650819615-f14c8a735dd8?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1055&q=80" alt="Pin up girl">
</div>
<div class="cipherSide">
<div class="heading-group">
<h1> Dirty Diana </h1>
<p>Dirty Diana wants to send dirty love messages to her husband, but she does not want Big Brother to know about it. Try out the tool I made for her!</p>
</div>
<textarea rows="10" placeholder="Insert the text you want to cipher or decipher here!" required></textarea>
<div class="button-group">
<button id="cipherIT">Cipher It!</button>
<button id="deCipher">Decipher!</button>
</div>
<p id="newOne"></p>
</div><!-- cipherSide -->
</div><!-- container -->

Flex items are not aligned side by side (i.e. spaced out)?

Okay using flex to align the image (purple) and the content (yellow) side by side. However I am getting extra space between and is throwing off the image to the right.
See here: http://imgur.com/a/nl0ZJ
It's supposed to be:
image should be inside the blue div next to the yellow div
the yellow div should be 60% width (These are flex items)
I've checked padding and margin, however it hasn't worked for me. Any ideas?
Here is the html
<div class="sec-1">
<h2>Introducing 'Keeva' world's smartest assistant.</h2>
<div class="flex-box">
<div>
<p class="sales-copy">Keeva smartphone app helps you organize your work schedule, meetings, project deadlines and much more.</p>
<!-- Download Buttons -->
<img class="download-btns" src="img/playstore-1.png">
<img class="download-btns" src="img/iphone-1.png">
</div>
<!-- Phone 0 image -->
<img class="phone-img" src="img/iphone-cut.png" alt="phone image">
</div>
</div>
CSS
#media screen and (min-width: 599px) {
.sec-1 h2 {
font-size: 1.2em;
background-color: green;
}
.sec-1 p {
font-size: 1.1em;
width: 50%;
background-color: yellow;
}
.sec-1 .phone-img {
position: relative;
top: 10%;
left: 30%;
background-color: purple;
}
.download-btns {
position: relative;
right: 25%;
background-color: orange;
}
.sec-1 .sales-copy {
width: 50%;
}
.flex-box {
display: flex;
justify-content: flex-end;
}
}
Since display: flex makes its immediate descendants flex items, it is only the div that wraps the the p/img that becomes one.
So to make this work, and since img doesn't behave normal when being flex items, move that div wrapper to the img and it will flow as intended.
I also changed width: 50% to flex-basis: 60% so the yellow element becomes 60%, and added flex-grow: 1 to the div wrapper, so it takes the remaining space.
Updated based on a comment
Changed to an outer and an inner Flexbox wrapper, so the buttons are located below the yellow element and the image to the right
.sec-1 h2 {
font-size: 1.2em;
background-color: green;
}
.sec-1 p {
margin: 0;
font-size: 1.1em;
background-color: yellow;
}
.sec-1 .phone-img {
position: relative;
top: 10%;
left: 30%;
background-color: purple;
}
.flex-box-outer {
display: flex;
}
.flex-box-outer > div {
flex-grow: 1;
}
.flex-box-inner {
flex-basis: 60%;
display: flex;
flex-direction: column;
align-items: center;
}
<div class="sec-1">
<h2>Introducing 'Keeva' world's smartest assistant.</h2>
<div class="flex-box-outer">
<div class="flex-box-inner">
<p class="sales-copy">Keeva smartphone app helps you organize your work schedule, meetings, project deadlines and much more.</p>
<!-- Download Buttons -->
<div>
<img class="download-btns" src="http://placehold.it/100x50/?text=playstore">
<img class="download-btns" src="http://placehold.it/100x50/?text=iphone">
</div>
</div>
<!-- Phone 0 image -->
<div>
<img class="phone-img" src="http://placehold.it/100x50/?text=iphone cut" alt="phone image">
</div>
</div>
</div>