Firefox ignores width property of element when using flex - css

I am trying to align some elements using different flex and width properties. In Safari and Chrome the behavior is as expected, but in firefox it is not.
It seems that the width property gets ignored, even though you set the width of the element to a very high, fixed value.
See example here:
https://jsfiddle.net/wugrtwjc/
The desired behavior is to have the two divs wrapped in the class "r-6" under each other, both covering the whole width of their parent (This is happening in Firefox and Chrome).
In firefox the two divs is aligned next to each other even though the width is set to 100%. You can also try to set the width of this class to something like 10000px, but it will still only take up half of the space of its parent div.
Html setup:
<div class="layout-row">
<div class="c-l-8">
<div class="layout-col h-800">
<div class="r-6">
<div class="one"></div>
</div>
<div class="r-6">
<div class="two"></div>
</div>
</div>
</div>
</div>
CSS:
.layout-row {
-webkit-flex-flow: row wrap;
width: 100%;
}
.layout-col {
-webkit-flex-flow: column wrap;
}
.layout-row, .layout-col {
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
}
.c-l-8 {
width: 66.66667%;
}
.r-6 {
width: 100%;
height: 50%;
}
.h-800 {
height: 800px;
}
.one, .two {
width: 100%;
height: 100%;
}
.one {
background: red;
}
.two {
background: blue;
}

try this code
<style>
.layout-row,
.layout-col {
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
}
.layout-row {
flex-flow: row wrap;
width: 100vw;
}
.layout-col {
flex-flow: column wrap;
}
.c-l-8 {
width: 100%;
}
.r-6 {
width: 100%;
height: 50%;
}
.h-800 {
height: 800px;
}
.one,
.two {
width: 100%;
height: 100%;
}
.one {
background: red;
}
.two {
background: blue;
}
</style>
Hope this helps..
Take care and happy coding

Related

Position an element x% of a way along with flexbox?

I want to position an element so that of the available space, 1/3 is above it and 2/3 are below. This is a React Native project so I can use flexbox but not grid or floats.
This code works but it's not very clean having to have empty elements div.first and div.last, can it be done without them?
body {
display: flex;
flex-direction: column;
height: 100vh;
}
.one {
background: gold
}
.first {
flex: 1;
}
.last {
flex: 2
}
<div class="first"></div>
<div class="one">One</div>
<div class="last"></div>
https://codepen.io/adsfdsfhdsafkhdsafjkdhafskjds/pen/PoPjdad
How about using margin like this?
Edit: Just add overflow-y:hidden; to body
body {
display: flex;
flex-direction: column;
height: 100vh;
overflow-y:hidden;
}
.one {
background: gold;
margin:33vh 0 66vh 0;
}
<div class="one">One</div>

Can not center align text under icons in flex table

I've made this flexbox table like this:
<div class="flex-row">
<div class="flex-col">
<i class="thumbs-up"></i>
<i>20</i>
</div>
<div class="flex-col">
<i class="thumbs-down"></i>
<i>5</i>
</div>
</div>
scss:
.thumbs-up {
width: 24px;
height: 24px;
&:after {
content: " ";
background: url(https://cdnjs.cloudflare.com/ajax/libs/ionicons/4.5.6/collection/build/ionicons/svg/ios-arrow-up.svg) no-repeat;
width: 100%;
height: 100%;
display: block;
}
}
.thumbs-down {
width: 24px;
height: 24px;
&:after {
content: " ";
background: url(https://cdnjs.cloudflare.com/ajax/libs/ionicons/4.5.6/collection/build/ionicons/svg/ios-arrow-down.svg) no-repeat;
width: 100%;
height: 100%;
display: block;
}
}
.flex-row {
display: flex;
flex-direction: row;
flex-wrap: wrap;
width: 20%;
}
.flex-col {
display: flex;
flex-direction: column;
flex-basis: 100%;
flex: 1;
text-align: center;
i {
text-align: left;
}
}
Here is the jsfiddle.
As you can see the numbers are not quite center-aligned below the icons.
How can I fix this?
The reason your numbers aren't center-aligned is because:
The i elements within .flex-col have the style text-align: left applied.
The i elements don't have a width set, so take up 100% of the parent element width (.flex-col)
So if you had aligned the text in the center, it would have been in the middle of the column, away from the icon. I've added some debugging borders to elements on this fiddle to try and explain the issue.
To fix this I've added a width to the i element containing the numbers example fiddle solution
An alternative solution would be to set margin: right on the .flex-col elements, removing flex-basis and flex style rules. Then set text-align: center on the i element as above.
see alternative example fiddle

Resize flex item based on its content

Sorry, another flexbox related question :)
I have two flex elements :
A container (red) containing a centered div (yellow)
A footer (blue) with an undefined height
The red container has a flex-grow:1 attribute, forcing it to take the remaining space on the screen
The issue happens when the yellow element is bigger than the screen size. I would like my red container to grow based on its content. Any idea of how I could do that ?
HTML:
<div class="container">
<div class="content"></div>
</div>
<div class="footer"></div>
CSS:
body,
html {
margin: 0;
height: 100%;
display: flex;
flex-direction: column;
}
.container {
flex-grow: 1;
display: flex;
align-items: center;
justify-content: center;
background: red;
}
.content {
background: yellow;
height: 2000px;
width: 100px;
}
.footer {
flex-shrink: 0;
height: 50px;
background-color: blue;
}
https://codepen.io/stepinsight/pen/roRVGQ
== EDIT ==
Andre helped me find the answer, thanks heaps !
The only thing you need to change in the code above is to replace height by min-height and the % by vh for the body/html tags 🎉
body,
html {
margin: 0;
min-height: 100vh;
display: flex;
flex-direction: column;
}
Simply remove the height property on the body element and add height: 100% to html
* { box-sizing: border-box; }
html {
height: 100%
}
body {
display: flex;
flex-direction: column;
margin: 0;
padding: 0;
}
.container {
display: flex;
align-items: center;
justify-content: center;
background: red;
}
.content {
background: yellow;
height: 2000px;
width: 100px;
}
.footer {
height: 50px;
background-color: blue;
}
Corrected: https://codepen.io/ferreirandre/pen/maoVvb
Feel free to play around with the height of .content

firefox v.37 nested squared flexboxes

I made a flexbox layout with some squared flexboxes nested in the main layout flexboxes. It works fine in Chrome and IE but Firefox v37.02 won't make them squared or doesn't show them at all.
I would like the containers themselves to be flexboxes of the main layout, so I can rearrange them with media-queries and have the content flexboxes wrap in the available space.
Here is a Fiddle example https://jsfiddle.net/SanMoll/jj591x8f/
<div class="main">
<div class="article">
<div class="itemXL"></div>
<div class="itemXL"></div>
</div>
<div class="aside">
<div class="itemL"></div>
<div class="itemL"></div>
<div class="itemL"></div>
<div class="itemL"></div>
</div>
</div>
<style>
.main {
display:flex;
width:100%;
height:100%;
background-color:#000;
}
.article {
/* display: flex;*/
flex-wrap: wrap;
flex-direction: column;
width: 50%;
flex: 1;
}
.itemXL {
background-color: #f4f4f4;
width: 97%;
height:0;
margin-right: 3%;
margin-bottom: 3%;
padding-bottom: 97%;
}
.aside {
/*display: flex;*/
flex-wrap: wrap;
flex-direction: row;
width: 50%;
}
.itemL {
background-color: #f4f4f4;
width: 47%;
height:0%;
margin-right: 3%;
margin-bottom: 3%;
padding-bottom:47%;
}
</style>
Any help is much appreciated.
Thank in advance!
You can use the flex-basis it is like the widht of the element but for flexboxes.
For example flex-basis: 50%;
and in the media query: flex-basis: 100%; (if flex-wrap is wrap the container will push the others down)
You should also start variable names not with numbers, you can put a '_'infront then it is fine
If you have problems with browser support just add this to be sure that it works in every browser
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;

percentage height in nested flex box

I've got a pretty good adjustable interface working with flexbox where a user can adjust the height and width of panels.
However, I want to change the panel heights, which currently use pixels, to use percentage, so when they change one panel, the other panels flow.
Everything works fine for widths, but when I use height % it breaks.
Here's a fiddle showing the broken %.
http://jsfiddle.net/59trW/1/
This fiddle has a 50% height set on the red element, but it isn't visible at all.
here's the css
.outer-flex {
position: absolute;
top: 0;
bottom: 0;
left:0;
right:0;
display: flex;
-webkit-box-align: stretch;
flex-direction: row;
}
.left-panel {
width: 30px;
background-color: #5eddd8;
}
.flex {
display: flex;
flex:1;
-webkit-box-align: stretch;
flex-direction: column;
background-color: #64b92a;
min-height: 1px;
}
.fixed {
height: 20px;
background-color: #ecf0f1;
}
.top-box {
height: 30%;
background-color: red;
}
.bottom-box {
flex: 1;
}
And the html
<div class="outer-flex">
<div class="left-panel">
this is ok.
</div>
<div class="flex">
<div class="fixed">doesn't move</div>
<div class="top-box">top box</div>
<div class="bottom-box">bottom box</div>
</div>
</div>
I'm hoping there is a small change I can make to have the div be adjustable by %.
You need to add a height to your right column:
http://jsfiddle.net/59trW/2/
.flex {
display: flex;
flex:1;
flex-direction: column;
background-color: #64b92a;
height: 100%; /* here */
}
Also, -webkit-box-align: stretch is doing nothing for you because it comes from the old 2009 draft (which you aren't even using here), not the current spec (also, stretch is the default value for that property).

Resources