Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
1

Float, Inline-block, Flexbox, Table and Grid - which one?

Community Expert ,
Jan 28, 2017 Jan 28, 2017

A lazy Sunday afternoon, decide to experiment with different layout methods

The code

<!doctype html>

<html>

<head>

  <meta charset="utf-8">

  <title>Untitled Document</title>

  <style>

  body {

  background: #222;

  color: white;

  font-weight: 300;

  font-family: sans-serif;

  font-size: 85%;

  line-height: 1.4;

  margin: 0;

  padding: 1rem;

  }

  body h2 {

  font-weight: 500;

  margin: 0 0 0.5rem 0;

  }

  body a {

  color: white;

  align-content:

  }

  body [class*='-block'] {

  background: green;

  padding: 1rem;

  max-width: 20rem;

  margin: 0 0 1rem 0;

  }

  .float-block {

  overflow: hidden;

  }

  .float-block img {

  width: 75px;

  float: left;

  }

  .float-block> div {

  width: calc(100% - 75px - 1rem);

  float: right;

  }

  .inline-block {}

  .inline-block> img {

  /* defaults to inline-block */

  width: 75px;

  margin: 0 calc(1rem - 4px) 0 0;

  /* remove strange white space */

  }

  .inline-block> div {

  display: inline-block;

  vertical-align: top;

  width: calc(100% - 75px - 1rem);

  }

  .flex-block {

  display: flex;

  align-items: flex-start;

  }

  .flex-block> img {

  width: 75px;

  margin: 0 1rem 0 0;

  }

  .flex-block> div {

  flex: 1;

  }

  .table-block {

  display: table;

  }

  .table-block> img {

  display: table-cell;

  width: 75px;

  margin: 0 1rem 0 0;

  }

  .table-block> div {

  display: table-cell;

  vertical-align: top;

  }

  .grid-block {

  display: grid;

  grid-template-columns: 75px auto;

  grid-template-rows: auto;

  grid-column-gap: 1rem;

  }

  .grid-block> img {

  align-self: start;

  }

  .grid-block> div {

  vertical-align: top;

  }

  </style>

</head>

<body>

  <div class="float-block">

  <img src="http://lorempixel.com/output/abstract-q-c-75-70-5.jpg" alt="">

  <div>

  <h2>Float</h2>

  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nisi voluptate iure nostrum debitis quae nihil, id fugiat consequatur quo, laborum, non eligendi dolore expedita minima voluptates repudiandae</p>

  </div>

  </div>

  <div class="inline-block">

  <img src="http://lorempixel.com/output/abstract-q-c-75-70-5.jpg" alt="">

  <div>

  <h2>Inline</h2>

  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nisi voluptate iure nostrum debitis quae nihil, id fugiat consequatur quo, laborum, non eligendi dolore expedita minima voluptates repudiandae</p>

  </div>

  </div>

  <div class="flex-block">

  <img src="http://lorempixel.com/output/abstract-q-c-75-70-5.jpg" alt="">

  <div>

  <h2>Flexbox</h2>

  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nisi voluptate iure nostrum debitis quae nihil, id fugiat consequatur quo, laborum, non eligendi dolore expedita minima voluptates repudiandae</p>

  </div>

  </div>

  <div class="table-block">

  <img src="http://lorempixel.com/output/abstract-q-c-75-70-5.jpg" alt="">

  <div>

  <h2>Table</h2>

  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nisi voluptate iure nostrum debitis quae nihil, id fugiat consequatur quo, laborum, non eligendi dolore expedita minima voluptates repudiandae</p>

  </div>

  </div>

  <div class="grid-block">

  <img src="http://lorempixel.com/output/abstract-q-c-75-70-5.jpg" alt="">

  <div>

  <h2>Grid</h2>

  <p>This example needs a Grid-aware browser to render as intended, see <a href="https://developers.google.com/web/updates/2014/03/Get-on-the-CSS-Grid" target="_blank">Get on the CSS Grid!</a>

  </p>

  </div>

  </div>

</body>

</html>

The result

After much discussion in various topics, I am wondering what the feeling of this forum is regarding the correct layout method.

For my input, I regard each method as being the correct one, I tend to use the one that is most convenient at the time. Having said that, I also think that Table the easiest one is to work with. Strange that Table has never been considered as a viable layout mechanism.

Wappler, the only real Dreamweaver alternative.
4.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 30, 2017 Jan 30, 2017

No need to apologise Ben.

The first time I tried flexbox I walked away from it for months, and maintained that it was useless. It was only when I used the first 'proper' implementation in IE10 that I began to see what was possible, then Opera had an implementation to the latest specs, (before it moved to the Blink engine) and I became hooked.

I can see grids and srcset facing much the same ridicule, and especially srcset.

The problem with all these new methods, is that people are writing about them when they are at the stage of learning that I was with flexbox, the first time I tried it, given everyone who is trying to learn these new methods the wrong impression.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 30, 2017 Jan 30, 2017

pziecina wrote:

I can see grids and srcset facing much the same ridicule, and especially srcset.

I've already jumped out of my pram concerning srcset BUT I suspect I'll reverse my opinions when I fully understand it and there is a clearer path as to what to use. At the moment how to deal with images for different devices is still a grey area.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 30, 2017 Jan 30, 2017
LATEST

osgood_ wrote:

I've already jumped out of my pram concerning srcset BUT I suspect I'll reverse my opinions when I fully understand it and there is a clearer path as to what to use. At the moment how to deal with images for different devices is still a grey area.

Don't under any circumstances read anything on-line at the moment, especially when it comes to using the sizes attribute. Most of what I have seen and read on-line, makes it look so difficult that one would never even consider using it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 30, 2017 Jan 30, 2017

BenPleysier wrote:

It is the ridiculing of other methods without any substantive argument that bothers me. Emotional arguments plucked out of the air because it happens to suit the argument.

Its not so much ridiculing them as being logical. You have to read lots and make a judgement based on that. Thats how I come to my judgements. If floats were ever meant to be used for layout then why so many hacks needed to make them work?

Its also not that floats didnt do a good job, they did and still do, but now we have something better why no use it.

Sure if you need to support IE9 and possible 10 then you have to be more selective but if those are browsers you don't need to concern yourself with then you may as well just use Flexbox particulary if you are using a pre-processor which will produce all the  css vendor prefixes for you. I prefer to just get it right in the browers that support display: flex; and then go back through the css after and add in the prefixes, that keeps the ugliness out of the file until the last minute.

Also there are many way to use Flexbox. Its not critical that you use Flexbox at its purist. You can combine it with the way you have always worked. It brings more options to the party.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jan 30, 2017 Jan 30, 2017

No need to clarify Rob, I use Flexbox at the moment

Good. I had in fact gotten the impression from this discussion that you had not really waded into the flexy waters.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jan 29, 2017 Jan 29, 2017

To me, pixel-precision is irrelevant. But there are many designers around that are not so progressive . But being that this is a Dreamweaver forum, run by Adobe, I find it the whole issue pretty funny.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 29, 2017 Jan 29, 2017

As Rob says, it all depends on the layout, and mix and match of layout methods has been the norm for the last few years.

One layout method you did not mention is multi-column, which i have found essential for layouts with lots of text, no matter which main layout method one decides to use.

As a little bit of history though. The reason table layouts never recieved the attention they deserved, was because of a bug in Chrome and Android browsers, which was not fixed until the same version that introduced the the 'new' flexbox syntax. Effectively placing all the attention on flexbox.

Of course all new layout methods that would not work in IE8, without a polyfill or falback css, many talked down as unworkable, or not untill 2021, to complexed and every other objection one can think of was put forward.

All the objections and reasons for not using anything new, has left us with a situation of some coders using the new methods, and not enough overall experiance of their use(s) making its way into public forums such as this.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 29, 2017 Jan 29, 2017

As a thought on which layout to use, and i have said this often over a number of years.

Without support in whatever editor or ide, only professional coders will use ithe newer layou methods, this efectively means 90% of web or app creators have no idea how to use anything beyond floats.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 29, 2017 Jan 29, 2017

BenPleysier wrote:

Strange that Table has never been considered as a viable layout mechanism.

I think it has by any developer that has a reasonable insight into coding. I was using it to resolve certain layout issue before Flex came along and I know of many a good developer that still use it frequently, although I'm not sure why now to be honest, given Flex can do it much better, maybe they don't want to pack their css with vendor prefixes, that's the only real reason  I can think why I would want to use 'table' over 'flex', unless I needed to support a lesser browser, but that decsion has to be made by the individual.

I'll go with flex as its here an now, suits my workflow and I like to try and remain current. I dont think theres any point in putting off what can be used today until tomorrow or next year, once something has major browser support and those browsers that dont support are insignificant regarding user numbers, move on.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 29, 2017 Jan 29, 2017

Remember your complaint about flexbox being only one direction, and the link to the article you used that said do not use?

Well the author wrote another article 5 months later saying use -

https://jakearchibald.com/2014/dont-use-flexbox-for-page-layout/

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 29, 2017 Jan 29, 2017

BenPleysier

just a though Bem.

Given all the discussions over the last few months, (or maybe that should be years) why are you asking this question?

After all, we have covered all this previously.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 30, 2017 Jan 30, 2017

Floats are now included in the Updated 2.1 specs in regards to positioning, because of css exclusions -

https://www.w3.org/TR/css3-exclusions/

Exclusions where originally called 'positioned floats' in the original draft, and must be declared as floated elements for them to work. Currently it is only implemented in IE10+, but other browsers, (except FF) are working on an implementation.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines