News for hackers. Stuff that matters.
Re:Flexbox and Grids: your layout’s best friends by c-smile on Monday November 06, 2017 @01:56PM (#15637870)
"flexbox horrors":

"flex-basis" - defines mysterious "main width" (WTF is wrong with just width?)

"flex-grow" and "flex-shrink" - grow and shrink relative to what?

How to define flexible margins? Like I want left margin to be twice larger than right one and all this to be flexible:

    |---m:2*-------|--1*---|--m:1*-| 
?

Effectively flexbox breaks CSS box model that postulates only width/height to define box dimensions.

Why I cannot say just this:

    { width: 1fr;
      margin-left: 2fr;
      margin-right: 1fr; } 
?

Where 'fr' are flex units introduced in CSS Grid https://developer.mozilla.org/en-US/docs/Web/CSS/flex_value

Why two specifications define the same entity (flex weight) by two different mechanisms - by property and by unit?

CSS looks like Christmas tree where each passer-by (Google and Microsoft here) adds its own shiny stuff ...

Is this what we name as modularity of CSS?

Re:Flexbox and Grids: your layout’s best friends by sillysaurus3 on Monday November 06, 2017 @03:33PM (#15638774)
Just use Bulma. You can drop it into any project. https://bulma.io/documentation/columns/sizes/

Your example can be accomplished like this:

  <div class="columns">
    <div class="column is-half">m:2*</div>
    <div class="column">1*</div>
    <div class="column">m:*1</div>
  </div>
There's a good reason to limit yourself to 12 columns: the layout is consistent across all common screen sizes, whether it's tiny mobile screens or huge desktop screens. If you have sizes like 1.374fr, you lose a lot of that automatic layout functionality.
Re:Flexbox and Grids: your layout’s best friends by c-smile on Monday November 06, 2017 @04:30PM (#15639193)
Bulma, as any other grid systems based on % units, is quite limited in real life.

Check this: https://sciter.com/images/wt-langs.png You see the same HTML markup there but in different languages. Text in most of European languages is longer.

This is HTML/CSS Sciter UI that uses flex units and flow property: https://sciter.com/docs/flex-flow/flex-layout.htm

Re:Flexbox and Grids: your layout’s best friends by sillysaurus3 on Monday November 06, 2017 @04:45PM (#15639282)
Hmm, why is it limited? I'm interested in hearing your experiences.
Re:Flexbox and Grids: your layout’s best friends by c-smile on Monday November 06, 2017 @04:53PM (#15639337)
Check screenshots above. There is a block having 4-columns layout. Each column there a) is flexible and b) uses min-content constraint. So widths of columns are unknown upfront - determined by actual content in grid cells.

That last part (use of actual content) is what you cannot reproduce using % units in principle.

Re:Flexbox and Grids: your layout’s best friends by SippinLean on Tuesday November 07, 2017 @10:15AM (#15643973)
That doesn't solve the problem the parent was describing. It just removes flex and sets 50% width on the half-column.
Re:Flexbox and Grids: your layout’s best friends by baby on Tuesday November 07, 2017 @04:12AM (#15641931)
Are you the laracast guy?
Re:Flexbox and Grids: your layout’s best friends by sillysaurus3 on Tuesday November 07, 2017 @06:49AM (#15642581)
Nope. But amusingly, you do know me. Shoot me an email if you want to know more.

Hope you've been well. Your 4chan board was hilariously cool.

Re:Flexbox and Grids: your layout’s best friends by e12e on Tuesday November 07, 2017 @12:41PM (#15645566)
(still) OT: now you two have made me curious about your story...
Re:Flexbox and Grids: your layout’s best friends by krsdcbl on Monday November 06, 2017 @09:13PM (#15640577)
Flexbox works kinda like this as far as i know:

Your items get distributed along the main axis, using their flex-basis.

When all elements are layed out, flexbox will evaluate how much space is left, or how much overlap there is.

This total remaining space will be distributed among all flex items proportionally to their flex-grow value. A flex-grow value of 2 means "grow twice as much as your siblings if there's spare room" (0 will prevent an element from growing at all, even if there is space left).

So if 3 elements with flex-grow 1--1--2 and 100px basis each where to fill a 400px box, the remaining 100px would be distributed 25--25--50.

Flex-shrink works the other way round. The same 400px-box example with flex-basis 200px and shrink 1--1--2 would result in 150--150--100px wide elements.

Re:Flexbox and Grids: your layout’s best friends by c-smile on Monday November 06, 2017 @10:10PM (#15640800)
"Flexbox works kinda like this as far as i know:"

That's the thing - nobody knows exactly how it works. Except few developers who actually tried to implement the spec.

Nobody knows why do we need separate flex-shrink and flex-grow. Nobody knows why these are properties and not units so they can be used not just for width/height but for padding, margin, border-width, top/left/bottom/right, size, etc.

Nobody knows why 'flex' is a value of 'display' property and not of some other property orthogonal to display like 'flow' or 'layout'. So we can write something like this:

    td.some { 
      display:table-cell; 
      flow: horizontal; // a.k.a. flex/row 
    }
At the moment there is no way to define flexible content flow inside table-cell's and list-item's as display:flex is mutually exclusive with display:table-cell.

Really, flexbox is the worst CSS module ever published and accepted by W3C.

Re:Flexbox and Grids: your layout’s best friends by Doxin on Tuesday November 07, 2017 @03:38AM (#15641820)
> nobody knows exactly how it works.

That's either plain nonsense or trivially true of all css, depending on your definitions.

Flexbox really isn't all that confusing or hard, and it does more than table layouts ever did.

Separate flex-grow and flex-shrink are needed for the same reason there's a min-width and a max-width property. flex-shrink defines if the element is allowed to shrink, and how much it does when needed. flex-grow defines if the element is allowed to grow, and how much when needed. The reason they are unitless values is because they are used to calculate ratios.

I agree that there have been some dubious design decisions, but if you really need to do a table cell with a flex-flowing content you can always stick a wrapper div in the cell.

Re:Flexbox and Grids: your layout’s best friends by c-smile on Tuesday November 07, 2017 @12:37PM (#15645518)
"flex-shrink defines if the element is allowed to shrink" Rhetorical question: Shrink from what? From defined flex-base or from defined width? What is the behavior when they are different?

"you can always stick a wrapper div in the cell" Nice, tag soup forever.

Re:Flexbox and Grids: your layout’s best friends by kowdermeister on Tuesday November 07, 2017 @05:30AM (#15642251)
Just take your time learning it, it's not that hard. If bootcampers can learn it in a few days, I'm sure you can do it too.
Re:Flexbox and Grids: your layout’s best friends by krsdcbl on Wednesday November 08, 2017 @01:55PM (#15655679)
Sorry I didnt mean to create the impression that i am guessing here.

This _is_ how it works, i just didnt have the source at hand and wanted to just exolain the broad mechanism

Re:Flexbox and Grids: your layout’s best friends by Nition on Monday November 06, 2017 @11:12PM (#15641031)
Man, you could almost have done this back in pre-CSS days with tables, if you didn't mind setting the total width of the whole thing including margins instead of just the inner width.

   <table style="width:75%"> // Total width of all three
      <tr>
        <th width="50%">LeftMargin</th>
        <th width="25%">Main</th>
        <th width="25%">RightMargin</th>
      </tr>
   </table>
How far have we really come?
Re:Flexbox and Grids: your layout’s best friends by c-smile on Monday November 06, 2017 @11:33PM (#15641100)
Exactly. 10 years we were told how dangerous are tables.

In the same 10 years (http://www.w3.org/TR/css-flexbox-1/) we were trying to come up with something that can be used instead. And have got that ugly flexbox.

And still... were are my col/rowspans?

Something is terribly wrong with the process.

Re:Flexbox and Grids: your layout’s best friends by gjjrfcbugxbhf on Tuesday November 07, 2017 @02:06AM (#15641534)
Well the table based layout does not work on mobile. The float, flex or grid based layouts do.

So we've come somewhere but there is further to go and maybe we didn't need to go in so many circles.

Re:Flexbox and Grids: your layout’s best friends by Nition on Tuesday November 07, 2017 @04:15AM (#15641951)
What's broken with table layouts on mobile? I just tested my code above on Safari on iOS 10 and it displayed as expected.

Here's the live HTML I uploaded for testing: http://momentstudio.co.nz/temp/test.html

This page we're on now also runs mostly on tables.

Re:Flexbox and Grids: your layout’s best friends by losvedir on Tuesday November 07, 2017 @09:06AM (#15643423)
> What's broken with table layouts on mobile? I just tested my code above on Safari on iOS 10 and it displayed as expected.

Depends what you'd expect, I suppose. These days, I'd expect the columns to switch to a vertical stacking layout when viewed at a mobile width. I guess maybe it's not "broken", per se, but it's not responsive and certainly pretty limited in how it can be used.

Re:Flexbox and Grids: your layout’s best friends by c-smile on Tuesday November 07, 2017 @12:40PM (#15645555)
What stops you from declaring

   table { display:block; }
etc. if you need to transform your table into vertical flow layout?
Re:Flexbox and Grids: your layout’s best friends by gjjrfcbugxbhf on Tuesday November 07, 2017 @01:33PM (#15646107)
Or even...

.responsive { display: block }

@media(min-size: 768px) { . responsive { display: table }}

Re:Flexbox and Grids: your layout’s best friends by kowdermeister on Tuesday November 07, 2017 @05:22AM (#15642208)
Go use tables, it's a free world. Col/Rowspans are there in the Grid specification, give the article a go linked by OP.

The only thing got wrong is that it took a bit long, but current CSS layout techniques are totally awesome today.

Re:Flexbox and Grids: your layout’s best friends by ams6110 on Tuesday November 07, 2017 @11:50AM (#15644967)
Tables were/are never wrong for displaying actual tabular content.
Re:Flexbox and Grids: your layout’s best friends by darkmarmot on Tuesday November 07, 2017 @09:24AM (#15643564)
It's been 20 years and we STILL don't have tables with a fixed header in the HTML spec. We deserve a better standards body -- or an entirely new layout system.
Re:Flexbox and Grids: your layout’s best friends by Mystrl on Monday November 06, 2017 @02:55PM (#15638491)
Do you mean something like https://jsfiddle.net/Mystrl/9uj40kam/1/
Re:Flexbox and Grids: your layout’s best friends by c-smile on Monday November 06, 2017 @03:10PM (#15638617)
Close but without those artificial DOM elements.

Here is an illustration of the idea of flex units:

https://sciter.com/docs/flex-flow/images/flex-springs.png

Re:Flexbox and Grids: your layout’s best friends by dangerlibrary on Monday November 06, 2017 @02:35PM (#15638311)
In the face of ambiguity, guess.

There should be N-- and preferably only N --obvious ways to do it.

Re:Flexbox and Grids: your layout’s best friends by c-smile on Monday November 06, 2017 @03:02PM (#15638554)
"obvious" is key point here.

This

    {  width:100px; 
       margin-left:1fr }  
has clear and obvious physical meaning: solid block with the spring of strength 1 on the left of it.

So the block is attached to the right side of its container. And so you don't need all those aligns - flex units can do alignment in more flexible ways.

That's obvious indeed.

But those flex-shrink/grow ...

Re:Flexbox and Grids: your layout’s best friends by joshribakoff on Monday November 06, 2017 @02:54PM (#15638480)
Your margin scenario is exactly what css grid handles nicely (grid gutters)
Re:Flexbox and Grids: your layout’s best friends by c-smile on Monday November 06, 2017 @03:06PM (#15638593)
Yes but flex units can be used not just in grid context.

Consider this:

   <p>Foo <input style="width:1fr /> bar.</p>
That <input> will span free space left in the p element from "Foo " and " bar."