Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flex Box out of borders? [duplicate]

Tags:

html

css

flexbox

Hello I have been trying to make a flex box in CSS like the image belowenter image description here

but I have a problem that's look like this image enter image description here

it seems like the div number 3 push every thing down here is the code

#flexcontainer
{
width: 500px;
height: 210px;
border: 3px solid black;
display: flex;
flex-wrap: wrap;
padding: 5px;

}

.flexitem
{
background: yellow;
width : 150px;
text-align: center;
height: 100px;
line-height: 100px;
margin: 2px;
}

.two
{
width : 200px;
}
.three
{
width : 120px;
height: 100%;
}

I also tried to use align-self property and set it to stretch to .three but also it doesn't work. Here is html code

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>
            Project Name
        </title>

    <link rel="stylesheet" type="text/css" href="main.css">
</head>

<body>
   <div id="flexcontainer">
    <div class="flexitem one">1</div> 
    <div class="flexitem two">2</div> 
    <div class="flexitem three">3</div> 
    <div class="flexitem four">4</div> 
    <div class="flexitem four">5</div> 
   </div>
</body>
</html>
like image 399
Mohammad Istanboli Avatar asked May 02 '16 17:05

Mohammad Istanboli


People also ask

How do you avoid double border in CSS?

Add a border-left and border-top to the parent.

What does flex wrap Nowrap do?

nowrap. The flex items are laid out in a single line which may cause the flex container to overflow. The cross-start is either equivalent to start or before depending on the flex-direction value. This is the default value.


1 Answers

Actually you can wrap flex columns and then reorder the children:

#flexcontainer {
  width: 500px;
  height: 210px;
  border: 3px solid black;
  display: flex;
  flex-flow: column wrap;
  padding: 5px;
}

.flexitem {
  background: yellow;
  width: 150px;
  text-align: center;
  height: 100px;
  line-height: 100px;
  margin: 2px;
}

.two {
  width: 200px;
  order: 3;
}

.three {
  width: 120px;
  height: 100%;
  order: 5;
}

.five { order: 4; }
<div id="flexcontainer">
  <div class="flexitem one">1</div>
  <div class="flexitem two">2</div>
  <div class="flexitem three">3</div>
  <div class="flexitem four">4</div>
  <div class="flexitem five">5</div>
</div>

jsFiddle: https://jsfiddle.net/azizn/12xkrtp4/

like image 195
Aziz Avatar answered Nov 03 '22 01:11

Aziz