I’m trying to add a border between two row flex items, however whenever I add one, the flex items stay in top of eachother instead of being next to eachother, here is an example:
This is how I want it to look. (line was drawn in paint, not a real thing)
https://i.sstatic.net/M6PQW26p.png
This is what I get.
https://i.sstatic.net/JkcXXx2C.png
<body>
<div class="flex-container">
<div class="flex-item1">
<p>Flex content</p>
</div>
<div class="flex-item2">
<p>Flex content</p>
</div>
</div>
</body>
.flex-container {
display: flex;
overflow: hidden;
flex-flow: row wrap;
height: 100vh;
.flex-item1 {
flex: 1 50%;
background-color: aqua;
border: 1px solid black;
}
.flex-item2 {
flex: 1 50%;
background-color: white;
}
}
3
Answers
Because by default your flex elements have
box-sizing: content-box;
and border adds up to 50% of your 2px.I advise you to always start with
* { box-sizing: border-box }
:If you intentionally want to use
box-sizing: content-box;
then do this:Remove
flex-flow: row wrap;
and useborder-right
instead ofborder
If you want to place items in row you can either give border-right to the first item or border-left to the second item.
Similarly if you want to place them in flex-direction: ‘column’, you can either give border-bottom to the first item or border-top to the second item.
Also as someone has mentioned it below, you need to change box-sizing to border-box
Hope this helps.
Reason why i didn’t write code is that i want you to do it on your own!