<div style="display:table;">
<div style="display:table-cell;vertical-align:middle;">
<div style="margin-left:auto;margin-right:auto;"></div>
</div>
</div>
[0] http://howtocenterincss.com/#contentType=div&horizontal=cent... <div style="display:table;">
<div style="display:table-cell;vertical-align:middle;">
<div style="margin-left:auto;margin-right:auto;"></div>
</div>
</div>
[0] http://howtocenterincss.com/#contentType=div&horizontal=cent...Also, naming issues aside, we are forced to pollute our markup with pointless, unsemantic container divs simply to achieve a basic style on the contained div.
Also, if divs have no semantic meaning in the context of the document's structure, it means they serve some other purpose: and that purpose is visual styling (not directly but through a css applied to them). How is this not a violation of the separation between document structure and presentation?
That said, separation between structure and presentation is desirable, and the necessity to use multiple divs to achieve a layout effect means CSS 2 is not as powerful as we could want. The grid model in CSS 3 is much more powerful, and allows things like separating the presentation order from the structural order.
Yes, it's better to have fewer divs that serve no purpose but to create the desired visual effect. As someone else suggested, in your example you probably don't need <div style="display:table;"> so it only requires adding one container div.
Why wouldn't the principle be applied everywhere? Expressing your intent -- writing semantically -- is a general principle of clean code, and of clear communication in general.
It's fine if you want to argue it's more important in html than in css, but that doesn't grant a pass to the creators and proponents of pure CSS who peddle the ideal of semantics with religious zeal and then fail to apply the principle to their own language, or even to realize that they've failed to do so because, I suspect, many of them don't actually grasp the true goal of the principle -- clarity and usability.
If they did, CSS wouldn't be the unusable mess of quirks that it is.
What I more often see is people advocating for using semantic HTML, because it exists, and separating concerns (content & presentation). If there was a choice to use CSS properties and values that better conveyed the presentation intent (what you might call its semantic value), they would advocate for that as well.
That's exactly what I said. I think the difference is in our interpretation of that causality: you see it as an intentional concession in the name of backwards compatibility; I see it as a failure of imagination.
You seem to be misinterpreting my arguments -- I'll assume not deliberately. They could have easily provided the same facilities for backwards compatibility of table behavior while also providing clearly-named and usable methods for doing things as basic as centering.
Is your position that CSS is a thoughtfully, well-designed system for presentation, and that the complaints of 95% of professionals web developers are the result of their own misunderstanding of it? Can you imagine taking such a position on user complaints as the CTO of a private software company?
I do believe most complaints about CSS is really complaints about missing and buggy implementations in browsers. For example for years I have seen people complain that CSS is not as powerful and simple as html tables, when the issue really was that Internet Explorer didn't support the display:table properties from CSS2, which meant you either had to use hacks with floats (which was never designed for this) or use html tables. This gave CSS a bad rep, when it really was IE that was to blame.
In any case, there is no irony here. The display:table-* properties is defined precisely to mimic the layout model of HTML tables (hence the name), in order to allow you to achieve the same layout with pure CSS, so you don't have to misuse <table>-elements.
It seems some people have misunderstood the recommendation against using <table>-element for layout, and thinks there is something wrong with table-based layouts. But table-based layouts are fine, and sometimes the only was to achieve a desired effect. The problem is only misuse of <table>-elements for something which is not semantically a table.
<style>
.table-example { display: table; }
.table-example div { display:table-cell;
vertical-align:middle; }
.table-example div div { margin-left:auto;
margin-right:auto; }
</style>
<div class="table-example">
<div>
<div></div>
</div>
</div>Of course such a project won't work with most non-React web projects. Idiomatic React projects tend to have a large number of small components with extensive re-use. (~5 lines of HTML not counting closing tags per component is my metric)
In a perfect world, we don't need wrap layers of div of divs for styling, why don't we invent a more semantic tag called "table". Oh wait...
Just because CSS hasn't proven to be all it was supposed to be, does t mean the criticism of the old way was incorrect.
I always failed to understand what is hard about the _being_ something vs _being displayed_ as something. I have met so many smart people just failing to grasp this simple dichotomy.
For the sake of public education, here is an example from the article. H1 is for (document) titles, and is so used by auto outliners and Google and Pocket. Document titles are document titles regardless of the way your page is displayed (user agent or current style fashion). If you want to display bigger just use "font-size".