How to put img properly in flex container
.item:nth-child(1)
.item:nth-child(2)
.item:nth-child(3)
are crumbled when i put image.
you can see what`s going on at http://dainielhhong.com/page1.html
.container{
display: flex;
margin: auto;
margin-top: 2vh;
height: 88vh;
width: 67vw;
border-top: 2px black solid;
border-left: 2px black solid;
border-right: 2px black solid;
}
.item:nth-child(1){
flex: 1;
height: 28vh;
border-right: 2px black solid;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
}
.item:nth-child(2){
flex: 2.6;
height: 28vh;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
}
.item:nth-child(3){
flex: 1;
height: 28vh;
border-left: 2px black solid;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
}
<div class = "container">
<div class = "item">
</div>
<div class = "item">
</div>
<div class = "item">
</div>
<img src="crack.svg">
</div>
I want to make image to not crumble item:nth-child(1)(2)(3).
What should I do?
html css html5 css3 flexbox
add a comment |
.item:nth-child(1)
.item:nth-child(2)
.item:nth-child(3)
are crumbled when i put image.
you can see what`s going on at http://dainielhhong.com/page1.html
.container{
display: flex;
margin: auto;
margin-top: 2vh;
height: 88vh;
width: 67vw;
border-top: 2px black solid;
border-left: 2px black solid;
border-right: 2px black solid;
}
.item:nth-child(1){
flex: 1;
height: 28vh;
border-right: 2px black solid;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
}
.item:nth-child(2){
flex: 2.6;
height: 28vh;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
}
.item:nth-child(3){
flex: 1;
height: 28vh;
border-left: 2px black solid;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
}
<div class = "container">
<div class = "item">
</div>
<div class = "item">
</div>
<div class = "item">
</div>
<img src="crack.svg">
</div>
I want to make image to not crumble item:nth-child(1)(2)(3).
What should I do?
html css html5 css3 flexbox
do you want the img insidenth-child(3)
?
– לבני מלכה
Jan 1 at 6:57
no. I want another box. You can see <img src="crack.svg"> in html code
– Daniel Hong
Jan 1 at 8:54
add a comment |
.item:nth-child(1)
.item:nth-child(2)
.item:nth-child(3)
are crumbled when i put image.
you can see what`s going on at http://dainielhhong.com/page1.html
.container{
display: flex;
margin: auto;
margin-top: 2vh;
height: 88vh;
width: 67vw;
border-top: 2px black solid;
border-left: 2px black solid;
border-right: 2px black solid;
}
.item:nth-child(1){
flex: 1;
height: 28vh;
border-right: 2px black solid;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
}
.item:nth-child(2){
flex: 2.6;
height: 28vh;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
}
.item:nth-child(3){
flex: 1;
height: 28vh;
border-left: 2px black solid;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
}
<div class = "container">
<div class = "item">
</div>
<div class = "item">
</div>
<div class = "item">
</div>
<img src="crack.svg">
</div>
I want to make image to not crumble item:nth-child(1)(2)(3).
What should I do?
html css html5 css3 flexbox
.item:nth-child(1)
.item:nth-child(2)
.item:nth-child(3)
are crumbled when i put image.
you can see what`s going on at http://dainielhhong.com/page1.html
.container{
display: flex;
margin: auto;
margin-top: 2vh;
height: 88vh;
width: 67vw;
border-top: 2px black solid;
border-left: 2px black solid;
border-right: 2px black solid;
}
.item:nth-child(1){
flex: 1;
height: 28vh;
border-right: 2px black solid;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
}
.item:nth-child(2){
flex: 2.6;
height: 28vh;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
}
.item:nth-child(3){
flex: 1;
height: 28vh;
border-left: 2px black solid;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
}
<div class = "container">
<div class = "item">
</div>
<div class = "item">
</div>
<div class = "item">
</div>
<img src="crack.svg">
</div>
I want to make image to not crumble item:nth-child(1)(2)(3).
What should I do?
.container{
display: flex;
margin: auto;
margin-top: 2vh;
height: 88vh;
width: 67vw;
border-top: 2px black solid;
border-left: 2px black solid;
border-right: 2px black solid;
}
.item:nth-child(1){
flex: 1;
height: 28vh;
border-right: 2px black solid;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
}
.item:nth-child(2){
flex: 2.6;
height: 28vh;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
}
.item:nth-child(3){
flex: 1;
height: 28vh;
border-left: 2px black solid;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
}
<div class = "container">
<div class = "item">
</div>
<div class = "item">
</div>
<div class = "item">
</div>
<img src="crack.svg">
</div>
.container{
display: flex;
margin: auto;
margin-top: 2vh;
height: 88vh;
width: 67vw;
border-top: 2px black solid;
border-left: 2px black solid;
border-right: 2px black solid;
}
.item:nth-child(1){
flex: 1;
height: 28vh;
border-right: 2px black solid;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
}
.item:nth-child(2){
flex: 2.6;
height: 28vh;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
}
.item:nth-child(3){
flex: 1;
height: 28vh;
border-left: 2px black solid;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
}
<div class = "container">
<div class = "item">
</div>
<div class = "item">
</div>
<div class = "item">
</div>
<img src="crack.svg">
</div>
html css html5 css3 flexbox
html css html5 css3 flexbox
edited Jan 1 at 23:45
Michael_B
151k48245357
151k48245357
asked Jan 1 at 6:53
Daniel HongDaniel Hong
327
327
do you want the img insidenth-child(3)
?
– לבני מלכה
Jan 1 at 6:57
no. I want another box. You can see <img src="crack.svg"> in html code
– Daniel Hong
Jan 1 at 8:54
add a comment |
do you want the img insidenth-child(3)
?
– לבני מלכה
Jan 1 at 6:57
no. I want another box. You can see <img src="crack.svg"> in html code
– Daniel Hong
Jan 1 at 8:54
do you want the img inside
nth-child(3)
?– לבני מלכה
Jan 1 at 6:57
do you want the img inside
nth-child(3)
?– לבני מלכה
Jan 1 at 6:57
no. I want another box. You can see <img src="crack.svg"> in html code
– Daniel Hong
Jan 1 at 8:54
no. I want another box. You can see <img src="crack.svg"> in html code
– Daniel Hong
Jan 1 at 8:54
add a comment |
3 Answers
3
active
oldest
votes
If you want to put the image below the flex items, wrap your .container
inside a parent container, and put the image in there. Currently, flex will squeeze the image in the same row as the items.
<div class="parent-container">
<div class="container">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
<img src="crack.svg">
</div>
Now, style the .parent-container
like your .container
, and change to container to just display: flex
.
Now if I had to guess, you want to use the SVG as a separator. For that, also add img { width: 100%; }
and remove the fixed height: 88vh
from your .parent-container
.
The result will be:
add a comment |
Here is 3 ways to position image
The 2 first ways are to change html because you use flex
The last is to position the img
.container{
display: flex;
margin: auto;
margin-top: 2vh;
height: 88vh;
width: 67vw;
border-top: 2px black solid;
border-left: 2px black solid;
border-right: 2px black solid;
position: relative;
}
.img{
position: absolute;
right: 99px;
}
.item:nth-child(1){
flex: 1;
height: 28vh;
border-right: 2px black solid;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
}
.item:nth-child(2){
flex: 2.6;
height: 28vh;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
}
.item:nth-child(3){
flex: 1;
height: 28vh;
border-left: 2px black solid;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
}
<h1>image after container</h1>
<div class = "container">
<div class = "item">
</div>
<div class = "item">
</div>
<div class = "item">
</div>
</div>
<img src="crack.svg">
<h1>image inside nth-child(3)</h1>
<div class = "container">
<div class = "item">
</div>
<div class = "item">
</div>
<div class = "item">
<img src="crack.svg">
</div>
</div>
<h1>image inside nth-child(3) with css and not change html</h1>
<div class = "container">
<div class = "item">
</div>
<div class = "item">
</div>
<div class = "item">
</div>
<img src="crack.svg" class="img">
</div>
add a comment |
You can set flex-basis
with the percentage for each item, make the first 3 100% in total and add
flex-wrap: wrap
to the container. Also note I added
box-sizing: border-box;
to each item, so the percentage will include the border size.
or any value that will fit the ratio you need
.container {
display: flex;
flex-wrap: wrap;
margin: auto;
margin-top: 2vh;
height: 88vh;
width: 67vw;
border-top: 2px black solid;
border-left: 2px black solid;
border-right: 2px black solid;
}
.item:nth-child(1) {
flex-basis: 22%;
height: 28vh;
border-right: 2px black solid;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
box-sizing: border-box;
}
.item:nth-child(2) {
flex-basis: 56%;
height: 28vh;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
box-sizing: border-box;
}
.item:nth-child(3) {
flex: 22%;
height: 28vh;
border-left: 2px black solid;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
box-sizing: border-box;
}
.container img{
flex-basis: 100%;
width: 100%;
box-sizing: border-box;
}
<div class="container">
<div class="item">
</div>
<div class="item">
</div>
<div class="item">
</div>
<img src="https://svgshare.com/i/AFb.svg">
</div>
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53993575%2fhow-to-put-img-properly-in-flex-container%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you want to put the image below the flex items, wrap your .container
inside a parent container, and put the image in there. Currently, flex will squeeze the image in the same row as the items.
<div class="parent-container">
<div class="container">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
<img src="crack.svg">
</div>
Now, style the .parent-container
like your .container
, and change to container to just display: flex
.
Now if I had to guess, you want to use the SVG as a separator. For that, also add img { width: 100%; }
and remove the fixed height: 88vh
from your .parent-container
.
The result will be:
add a comment |
If you want to put the image below the flex items, wrap your .container
inside a parent container, and put the image in there. Currently, flex will squeeze the image in the same row as the items.
<div class="parent-container">
<div class="container">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
<img src="crack.svg">
</div>
Now, style the .parent-container
like your .container
, and change to container to just display: flex
.
Now if I had to guess, you want to use the SVG as a separator. For that, also add img { width: 100%; }
and remove the fixed height: 88vh
from your .parent-container
.
The result will be:
add a comment |
If you want to put the image below the flex items, wrap your .container
inside a parent container, and put the image in there. Currently, flex will squeeze the image in the same row as the items.
<div class="parent-container">
<div class="container">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
<img src="crack.svg">
</div>
Now, style the .parent-container
like your .container
, and change to container to just display: flex
.
Now if I had to guess, you want to use the SVG as a separator. For that, also add img { width: 100%; }
and remove the fixed height: 88vh
from your .parent-container
.
The result will be:
If you want to put the image below the flex items, wrap your .container
inside a parent container, and put the image in there. Currently, flex will squeeze the image in the same row as the items.
<div class="parent-container">
<div class="container">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
<img src="crack.svg">
</div>
Now, style the .parent-container
like your .container
, and change to container to just display: flex
.
Now if I had to guess, you want to use the SVG as a separator. For that, also add img { width: 100%; }
and remove the fixed height: 88vh
from your .parent-container
.
The result will be:
edited Jan 1 at 7:03
answered Jan 1 at 6:57
NikxDaNikxDa
3,12111737
3,12111737
add a comment |
add a comment |
Here is 3 ways to position image
The 2 first ways are to change html because you use flex
The last is to position the img
.container{
display: flex;
margin: auto;
margin-top: 2vh;
height: 88vh;
width: 67vw;
border-top: 2px black solid;
border-left: 2px black solid;
border-right: 2px black solid;
position: relative;
}
.img{
position: absolute;
right: 99px;
}
.item:nth-child(1){
flex: 1;
height: 28vh;
border-right: 2px black solid;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
}
.item:nth-child(2){
flex: 2.6;
height: 28vh;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
}
.item:nth-child(3){
flex: 1;
height: 28vh;
border-left: 2px black solid;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
}
<h1>image after container</h1>
<div class = "container">
<div class = "item">
</div>
<div class = "item">
</div>
<div class = "item">
</div>
</div>
<img src="crack.svg">
<h1>image inside nth-child(3)</h1>
<div class = "container">
<div class = "item">
</div>
<div class = "item">
</div>
<div class = "item">
<img src="crack.svg">
</div>
</div>
<h1>image inside nth-child(3) with css and not change html</h1>
<div class = "container">
<div class = "item">
</div>
<div class = "item">
</div>
<div class = "item">
</div>
<img src="crack.svg" class="img">
</div>
add a comment |
Here is 3 ways to position image
The 2 first ways are to change html because you use flex
The last is to position the img
.container{
display: flex;
margin: auto;
margin-top: 2vh;
height: 88vh;
width: 67vw;
border-top: 2px black solid;
border-left: 2px black solid;
border-right: 2px black solid;
position: relative;
}
.img{
position: absolute;
right: 99px;
}
.item:nth-child(1){
flex: 1;
height: 28vh;
border-right: 2px black solid;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
}
.item:nth-child(2){
flex: 2.6;
height: 28vh;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
}
.item:nth-child(3){
flex: 1;
height: 28vh;
border-left: 2px black solid;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
}
<h1>image after container</h1>
<div class = "container">
<div class = "item">
</div>
<div class = "item">
</div>
<div class = "item">
</div>
</div>
<img src="crack.svg">
<h1>image inside nth-child(3)</h1>
<div class = "container">
<div class = "item">
</div>
<div class = "item">
</div>
<div class = "item">
<img src="crack.svg">
</div>
</div>
<h1>image inside nth-child(3) with css and not change html</h1>
<div class = "container">
<div class = "item">
</div>
<div class = "item">
</div>
<div class = "item">
</div>
<img src="crack.svg" class="img">
</div>
add a comment |
Here is 3 ways to position image
The 2 first ways are to change html because you use flex
The last is to position the img
.container{
display: flex;
margin: auto;
margin-top: 2vh;
height: 88vh;
width: 67vw;
border-top: 2px black solid;
border-left: 2px black solid;
border-right: 2px black solid;
position: relative;
}
.img{
position: absolute;
right: 99px;
}
.item:nth-child(1){
flex: 1;
height: 28vh;
border-right: 2px black solid;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
}
.item:nth-child(2){
flex: 2.6;
height: 28vh;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
}
.item:nth-child(3){
flex: 1;
height: 28vh;
border-left: 2px black solid;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
}
<h1>image after container</h1>
<div class = "container">
<div class = "item">
</div>
<div class = "item">
</div>
<div class = "item">
</div>
</div>
<img src="crack.svg">
<h1>image inside nth-child(3)</h1>
<div class = "container">
<div class = "item">
</div>
<div class = "item">
</div>
<div class = "item">
<img src="crack.svg">
</div>
</div>
<h1>image inside nth-child(3) with css and not change html</h1>
<div class = "container">
<div class = "item">
</div>
<div class = "item">
</div>
<div class = "item">
</div>
<img src="crack.svg" class="img">
</div>
Here is 3 ways to position image
The 2 first ways are to change html because you use flex
The last is to position the img
.container{
display: flex;
margin: auto;
margin-top: 2vh;
height: 88vh;
width: 67vw;
border-top: 2px black solid;
border-left: 2px black solid;
border-right: 2px black solid;
position: relative;
}
.img{
position: absolute;
right: 99px;
}
.item:nth-child(1){
flex: 1;
height: 28vh;
border-right: 2px black solid;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
}
.item:nth-child(2){
flex: 2.6;
height: 28vh;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
}
.item:nth-child(3){
flex: 1;
height: 28vh;
border-left: 2px black solid;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
}
<h1>image after container</h1>
<div class = "container">
<div class = "item">
</div>
<div class = "item">
</div>
<div class = "item">
</div>
</div>
<img src="crack.svg">
<h1>image inside nth-child(3)</h1>
<div class = "container">
<div class = "item">
</div>
<div class = "item">
</div>
<div class = "item">
<img src="crack.svg">
</div>
</div>
<h1>image inside nth-child(3) with css and not change html</h1>
<div class = "container">
<div class = "item">
</div>
<div class = "item">
</div>
<div class = "item">
</div>
<img src="crack.svg" class="img">
</div>
.container{
display: flex;
margin: auto;
margin-top: 2vh;
height: 88vh;
width: 67vw;
border-top: 2px black solid;
border-left: 2px black solid;
border-right: 2px black solid;
position: relative;
}
.img{
position: absolute;
right: 99px;
}
.item:nth-child(1){
flex: 1;
height: 28vh;
border-right: 2px black solid;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
}
.item:nth-child(2){
flex: 2.6;
height: 28vh;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
}
.item:nth-child(3){
flex: 1;
height: 28vh;
border-left: 2px black solid;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
}
<h1>image after container</h1>
<div class = "container">
<div class = "item">
</div>
<div class = "item">
</div>
<div class = "item">
</div>
</div>
<img src="crack.svg">
<h1>image inside nth-child(3)</h1>
<div class = "container">
<div class = "item">
</div>
<div class = "item">
</div>
<div class = "item">
<img src="crack.svg">
</div>
</div>
<h1>image inside nth-child(3) with css and not change html</h1>
<div class = "container">
<div class = "item">
</div>
<div class = "item">
</div>
<div class = "item">
</div>
<img src="crack.svg" class="img">
</div>
.container{
display: flex;
margin: auto;
margin-top: 2vh;
height: 88vh;
width: 67vw;
border-top: 2px black solid;
border-left: 2px black solid;
border-right: 2px black solid;
position: relative;
}
.img{
position: absolute;
right: 99px;
}
.item:nth-child(1){
flex: 1;
height: 28vh;
border-right: 2px black solid;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
}
.item:nth-child(2){
flex: 2.6;
height: 28vh;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
}
.item:nth-child(3){
flex: 1;
height: 28vh;
border-left: 2px black solid;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
}
<h1>image after container</h1>
<div class = "container">
<div class = "item">
</div>
<div class = "item">
</div>
<div class = "item">
</div>
</div>
<img src="crack.svg">
<h1>image inside nth-child(3)</h1>
<div class = "container">
<div class = "item">
</div>
<div class = "item">
</div>
<div class = "item">
<img src="crack.svg">
</div>
</div>
<h1>image inside nth-child(3) with css and not change html</h1>
<div class = "container">
<div class = "item">
</div>
<div class = "item">
</div>
<div class = "item">
</div>
<img src="crack.svg" class="img">
</div>
answered Jan 1 at 7:06
לבני מלכהלבני מלכה
10.5k1826
10.5k1826
add a comment |
add a comment |
You can set flex-basis
with the percentage for each item, make the first 3 100% in total and add
flex-wrap: wrap
to the container. Also note I added
box-sizing: border-box;
to each item, so the percentage will include the border size.
or any value that will fit the ratio you need
.container {
display: flex;
flex-wrap: wrap;
margin: auto;
margin-top: 2vh;
height: 88vh;
width: 67vw;
border-top: 2px black solid;
border-left: 2px black solid;
border-right: 2px black solid;
}
.item:nth-child(1) {
flex-basis: 22%;
height: 28vh;
border-right: 2px black solid;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
box-sizing: border-box;
}
.item:nth-child(2) {
flex-basis: 56%;
height: 28vh;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
box-sizing: border-box;
}
.item:nth-child(3) {
flex: 22%;
height: 28vh;
border-left: 2px black solid;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
box-sizing: border-box;
}
.container img{
flex-basis: 100%;
width: 100%;
box-sizing: border-box;
}
<div class="container">
<div class="item">
</div>
<div class="item">
</div>
<div class="item">
</div>
<img src="https://svgshare.com/i/AFb.svg">
</div>
add a comment |
You can set flex-basis
with the percentage for each item, make the first 3 100% in total and add
flex-wrap: wrap
to the container. Also note I added
box-sizing: border-box;
to each item, so the percentage will include the border size.
or any value that will fit the ratio you need
.container {
display: flex;
flex-wrap: wrap;
margin: auto;
margin-top: 2vh;
height: 88vh;
width: 67vw;
border-top: 2px black solid;
border-left: 2px black solid;
border-right: 2px black solid;
}
.item:nth-child(1) {
flex-basis: 22%;
height: 28vh;
border-right: 2px black solid;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
box-sizing: border-box;
}
.item:nth-child(2) {
flex-basis: 56%;
height: 28vh;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
box-sizing: border-box;
}
.item:nth-child(3) {
flex: 22%;
height: 28vh;
border-left: 2px black solid;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
box-sizing: border-box;
}
.container img{
flex-basis: 100%;
width: 100%;
box-sizing: border-box;
}
<div class="container">
<div class="item">
</div>
<div class="item">
</div>
<div class="item">
</div>
<img src="https://svgshare.com/i/AFb.svg">
</div>
add a comment |
You can set flex-basis
with the percentage for each item, make the first 3 100% in total and add
flex-wrap: wrap
to the container. Also note I added
box-sizing: border-box;
to each item, so the percentage will include the border size.
or any value that will fit the ratio you need
.container {
display: flex;
flex-wrap: wrap;
margin: auto;
margin-top: 2vh;
height: 88vh;
width: 67vw;
border-top: 2px black solid;
border-left: 2px black solid;
border-right: 2px black solid;
}
.item:nth-child(1) {
flex-basis: 22%;
height: 28vh;
border-right: 2px black solid;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
box-sizing: border-box;
}
.item:nth-child(2) {
flex-basis: 56%;
height: 28vh;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
box-sizing: border-box;
}
.item:nth-child(3) {
flex: 22%;
height: 28vh;
border-left: 2px black solid;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
box-sizing: border-box;
}
.container img{
flex-basis: 100%;
width: 100%;
box-sizing: border-box;
}
<div class="container">
<div class="item">
</div>
<div class="item">
</div>
<div class="item">
</div>
<img src="https://svgshare.com/i/AFb.svg">
</div>
You can set flex-basis
with the percentage for each item, make the first 3 100% in total and add
flex-wrap: wrap
to the container. Also note I added
box-sizing: border-box;
to each item, so the percentage will include the border size.
or any value that will fit the ratio you need
.container {
display: flex;
flex-wrap: wrap;
margin: auto;
margin-top: 2vh;
height: 88vh;
width: 67vw;
border-top: 2px black solid;
border-left: 2px black solid;
border-right: 2px black solid;
}
.item:nth-child(1) {
flex-basis: 22%;
height: 28vh;
border-right: 2px black solid;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
box-sizing: border-box;
}
.item:nth-child(2) {
flex-basis: 56%;
height: 28vh;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
box-sizing: border-box;
}
.item:nth-child(3) {
flex: 22%;
height: 28vh;
border-left: 2px black solid;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
box-sizing: border-box;
}
.container img{
flex-basis: 100%;
width: 100%;
box-sizing: border-box;
}
<div class="container">
<div class="item">
</div>
<div class="item">
</div>
<div class="item">
</div>
<img src="https://svgshare.com/i/AFb.svg">
</div>
.container {
display: flex;
flex-wrap: wrap;
margin: auto;
margin-top: 2vh;
height: 88vh;
width: 67vw;
border-top: 2px black solid;
border-left: 2px black solid;
border-right: 2px black solid;
}
.item:nth-child(1) {
flex-basis: 22%;
height: 28vh;
border-right: 2px black solid;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
box-sizing: border-box;
}
.item:nth-child(2) {
flex-basis: 56%;
height: 28vh;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
box-sizing: border-box;
}
.item:nth-child(3) {
flex: 22%;
height: 28vh;
border-left: 2px black solid;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
box-sizing: border-box;
}
.container img{
flex-basis: 100%;
width: 100%;
box-sizing: border-box;
}
<div class="container">
<div class="item">
</div>
<div class="item">
</div>
<div class="item">
</div>
<img src="https://svgshare.com/i/AFb.svg">
</div>
.container {
display: flex;
flex-wrap: wrap;
margin: auto;
margin-top: 2vh;
height: 88vh;
width: 67vw;
border-top: 2px black solid;
border-left: 2px black solid;
border-right: 2px black solid;
}
.item:nth-child(1) {
flex-basis: 22%;
height: 28vh;
border-right: 2px black solid;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
box-sizing: border-box;
}
.item:nth-child(2) {
flex-basis: 56%;
height: 28vh;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
box-sizing: border-box;
}
.item:nth-child(3) {
flex: 22%;
height: 28vh;
border-left: 2px black solid;
border-bottom: 2px black solid;
font-family: 'Indie Flower', cursive;
box-sizing: border-box;
}
.container img{
flex-basis: 100%;
width: 100%;
box-sizing: border-box;
}
<div class="container">
<div class="item">
</div>
<div class="item">
</div>
<div class="item">
</div>
<img src="https://svgshare.com/i/AFb.svg">
</div>
edited Jan 1 at 7:10
answered Jan 1 at 7:04
Itay GalItay Gal
8,12052560
8,12052560
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53993575%2fhow-to-put-img-properly-in-flex-container%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
do you want the img inside
nth-child(3)
?– לבני מלכה
Jan 1 at 6:57
no. I want another box. You can see <img src="crack.svg"> in html code
– Daniel Hong
Jan 1 at 8:54