This question already has answers here:
Force flex item to span full row width
(2 answers)
Closed 5 years ago.
I have this HTML
<div class="wrap">
<div class="one"></div>
<div class="two"></div>
<div class="three"></div>
<div class="four"></div>
</div>
plus this CSS
.wrap {
display: flex;
align-items: center;
}
.one {
flex: 0 1 200px;
}
.two {
display: flex;
flex: 1 1 auto;
align-items: center;
justify-content: center;
}
.three {
display: flex;
flex: 0 1 200px;
justify-content: flex-end;
}
.four {
???
}
and i wanna make it look like this, i don't know what else to use for .four to make that last div to move on a new line plus 100% width
[- one -----][----- two -----][----- three -]
[----------------- four --------------------]
atm looks like this
[- one -----][----- two -----][----- three -] [- four -----]
i know i can use another
<div class="wrap">
but i don't want this,
Thank you.
Add flex-wrap: wrap to the .wrap class, and make your .four class flex: 1 1 100%, that should do the trick:
.wrap {
display: flex;
align-items: center;
flex-wrap: wrap;
}
.one {
flex: 0 1 200px;
}
.two {
display: flex;
flex: 1 1 auto;
align-items: center;
justify-content: center;
}
.three {
display: flex;
flex: 0 1 200px;
justify-content: flex-end;
}
.four {
flex: 1 1 100%;
}
Here's a Codepen example (I added a border and height to your divs just to make it easier to visualise).
Please check you can try this
<div class="wrap">
<div class="one"></div>
<div class="two"></div>
<div class="three"></div>
<div class="four"></div>
</div>
CSS
.wrap {
display: flex;
align-items: center;
justify-content: center;
flex-wrap: wrap;
}
.wrap > div{
border: 1px solid;
height: 200px;
}
.one {
flex: 0 1 200px;
}
.two {
flex: 1 1 auto;
}
.three {
flex: 0 1 200px;
}
.four {
flex: 100%;
}
link https://jsfiddle.net/JentiDabhi/eoat01zn/
this is simple:
To achieve this:
.wrapper{
display: flex;
flex-wrap: wrap;
flex-direction: row;
background: blue;
width: 100%;
}
.one, .two, .three{
width: 33%;
background:red;
}
.four{
width:100%;
background:pink;
}
<div class="wrapper">
<div class="one">
one
</div>
<div class="two">
two
</div>
<div class="three">
three
</div>
<div class="four">
four
</div>
</div>
Related
This question already has answers here:
Left column and stacked right column using flexbox CSS [duplicate]
(2 answers)
Closed 1 year ago.
I am trying to make the design below with flexbox how would I do it?
Create a container and dive it into 2 half using flex.
Create the first half and divide it into 2 half of the 8:2 ratio again using it flex in the child flex-elements.
.container {
display: flex;
gap: 1rem;
}
.box {
height: 200px;
flex: 1;
background-color: blue;
}
.box1 {
background-color: white;
display: flex;
flex-direction: column;
gap: 1rem;
}
.internal-box1 {
flex: 8;
background-color: blue;
}
.internal-box2 {
background-color: blue;
flex: 2;
}
<div class="container">
<div class="box box1">
<div class="internal-box1"></div>
<div class="internal-box2"></div>
</div>
<div class="box"></div>
</div>
Try something like this:
<div style="
height: 250px;
width: 100%;
display: flex;
"><div style="
display: flex;
flex-direction: column;
flex: 1;
margin-right: 20px;
"><div style="
flex: 1;
background-color: paleturquoise;
margin-bottom: 20px;
"></div><div style="
height: 40px;
background: blue;
"></div></div><div style="
flex: 1;
background: teal;
"></div></div>
I want to make four boxes in two rows. There will be no padding/gap between two rows. Entire section will be stretched.
Example of the boxes is as below :
How to gain this ? Please help. Thanks in advance.
You can do this by adding CUSTOM HTML module in VC, and then using flex
html, body {
height: 100%;
margin: 0;
}
.grid2x2 {
min-height: 100%;
display: flex;
flex-wrap: wrap;
flex-direction: row;
}
.grid2x2 > div {
display: flex;
flex-basis: calc(50% - 0px);
justify-content: center;
flex-direction: column;
}
.grid2x2 > div > div {
display: flex;
justify-content: center;
flex-direction: row;
}
.box { margin: 0px; }
.box1 { background-color: red; }
.box2 { background-color: orange; }
.box3 { background-color: purple; }
.box4 { background-color: grey; }
<div class="grid2x2">
<div class="box box1"><div>one</div></div>
<div class="box box2"><div>two</div></div>
<div class="box box3"><div>three</div></div>
<div class="box box4"><div>four</div></div>
</div>
I'm trying to make my css with flexbox, so I followed some articles and tried to set my elements like this example:
the elements 1 & 2 are in another container
I'm trying to set the two elements (1 and 3) to be next each other as the second example (The first is what I have now and the other is what I'm trying to achieve.)
but I can't find a good way with the Flexbox since I set the container to flex-direction: column;
<div class="container">
<div class="sub-ctn">
<h5 class="1"><span>♦ </span>{{ text }}</h5>
<span class="2">{{ value }}</span>
<div class="3">
<h5>{{ text }}
</div>
</div>
</div>
CSS:
.container {
margin-right: 2.5%;
direction: rtl;
}
.sub-ctn {
display: flex;
flex-flow: row;
margin-top: 1%;
flex-direction: column;
}
.1 {
width: 100%;
direction: rtl;
text-align: right;
}
.2 {
float: right;
/* text-align: right; */
}
.3 {
margin-left: 1%;
display: flex;
flex-direction: column;
}
let me know if another information is needed
Don't use float and flex together. Flex alone will be much easier and better.
.cont{
display: flex;
width: 80%;
border: 1px solid black;
padding: 10px;
}
.left-cont{
height: 100%;
flex-grow: 1;
}
.right-cont{
flex-grow: 1;
display: flex;
flex-direction: column;
}
.item{
text-align: center;
border: 1px solid black;
margin: 3px;
}
<div class="cont">
<div class="left-cont">
<div class="item">3</div>
</div>
<div class="right-cont">
<div class="item">1</div>
<div class="item">2</div>
</div>
</div>
This question already has answers here:
Force flex item to span full row width
(2 answers)
Closed 4 years ago.
I am three items in a row. I want to keep first two items 50% 50% of the row and push the next third item to the next row and cover the 100% of the row.
.container {
display: flex;
flex-wrap: nowrap;
justify-content: space-between;
}
.div1, .div2 {
flex: 0 0 50%;
}
.div3{
flex: 1;
}
html markup
<div class="container">
<div class="div1"></div>
<div class="div2"></div>
<div class="div3"></div>
</div>
What I want is first two elements lined together in one row and third element pushed to next row covering 100%;
you can do this.
.container {
display: flex;
flex-wrap: wrap;
}
.container div {
height: 20px;
}
.div1, .div2 {
flex: 0 0 50%;
}
div.div3{
flex: 0 0 100%;
}
div.div1 {
background-color:green;
}
div.div2 {
background-color: yellow;
}
div.div3 {
background-color: red;
}
<div class="container">
<div class="div1"></div>
<div class="div2"></div>
<div class="div3"></div>
</div>
...
.container {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.div1, .div2 {
width: 50%;
}
.div3{
width: 100%;
}
<div class="container">
<div class="div1"></div>
<div class="div2"></div>
<div class="div3"></div>
</div>
The following situation doesn't work in Google Chrome;
<div class="flex-container">
<div class="flex-item">
<div>
<div>
<h2>This is a test</h2>
</div>
</div>
</div>
<div class="flex-item">
<div>
<div>
<h2>This is a test</h2>
</div>
</div>
</div>
<div class="flex-item">
<div>
<div>
<h2>This is a test</h2>
</div>
</div>
</div>
</div>
SCSS
body,html {
height:100%;
background:#1D1F20;
font-family:sans-serif;
color:#fff;
}
.flex-container {
display: flex;
flex-direction: column;
align-items: center;
height:100%;
.flex-item {
flex: 1 1 auto;
align-self: center;
background:#87BEB7;
padding:0 10px;
&:nth-child(2) {
background:#ADBEBC;
}
&:nth-child(3) {
background:#BE8A74;
}
> div {
display: flex;
justify-content: center;
align-items: flex-start;
height:100%; // This seems to be the issue
div {
flex: 0 1 auto;
align-self: center;
background:#5C726F;
padding:10px
}
}
}
}
I would expect the second flexbox-container (.flex-item > div) to be the full height of the flex-child (.flex-item) but it doesn't seem to work. (chrome only)
The workaround I have involves using position absolute, but i'd rather not use it.
Codepen: http://codepen.io/anon/pen/QwpzLX
Open in Firefox to see the desired result and in Chrome to see the current situation.
Any help or suggestions would be appreciated.
Here is the working scss:
.flex-container {
display: flex;
flex-direction: column;
align-items: center;
height:100%;
.flex-item {
flex: 1 1 auto;
align-self: center;
background:#87BEB7;
padding:0 10px;
display: flex;
&:nth-child(2) {
background:#ADBEBC;
}
&:nth-child(3) {
background:#BE8A74;
}
> div {
display: flex;
justify-content: center;
align-items: flex-start;
div {
flex: 0 1 auto;
align-self: center;
background:#5C726F;
padding:10px
}
}
}
}
You have to set display:flex; to .flex-item and remove the height: 100%.
Here is the demo: http://jsfiddle.net/omgL91r8/1/