296 points · by sebkomianos · 11y ago · 111 comments
<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.
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.
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...
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".
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.
?
Certainly, flex-box addresses a problem that's been making CSS writers frustrated for a long time.
Same deal with mobile OS support, really. You have to have a pretty unusual or long-standing audience to support anything pre-4.2, let alone pre-4.0. iOS7 is also probably not worth the time to target for most products.
Yes i.e. DRY
You don't need web programmers for web design. You can export from a WISYWIG to HTML, or design a big ol' GIF and post it on Wordpress. Lots of restaurants do that sort of thing.
But you probably want something that interacts with the user, changes layouts based on screen size, provides information to disabled users, validates and submits information, allows commenting and moderation of comments, etc. Eg, a program. And you do need programmers for that.
Print designers also have to think about the platform their design is presented on e.g. what kind of color bleeding will happen in the press when an image is used on newsprint.
[0] https://www.netmarketshare.com/browser-market-share.aspx?qpr...
I pretty sure my kid would care if that happened.
I wasn't trying to be a smartarse, I wish flexbox was usable. But IE < 11 is still a very large player.
.centered {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
now just put it in a relatively positioned container and you're done. i thought this was common knowledge by now, i haven't used `table-cell` in years.Wordpress with her custom theme seems to fail C. Github pages / Jekyll is failing B
I now am basically 100% Jekyll and Middleman...but having tried teaching Github Pages to college students...I'm skeptical that it's easy enough for a child to hack around with and get the same amount of enjoyment and productivity that she would out of Tumblr or WordPress.
(Apparently Ghost is pretty good too but I've never tried it)
For a little more functionality, I like ASmallOrange. My partner hosts her site/blog with them for $35/year and it's great, too.
Livejournal is still the best for writing posts and having discussions on. Takes no effort to keep going, and has threaded comments, supports images and videos, and basically just works:
http://andrewducker.livejournal.com/ (for an example)
body { position: relative; height: 100vh; }
#content { height: <defined>; top: 0; right: 0; left: 0; bottom: 0; position: absolute } .vertically-centered {
position: absolute
top: 50%;
height: 200px;
margin-top: -100px; /* minus half of `height` */
}
If you have trouble, try setting `height` to 100% on the <body> tag and any parentsThe typical problem with WYSIWYG webpage builders is that the web is not a printed document. If you don't know the underlying concepts of layout you expect things to behave much differently than they actually do. Or at least, that was how it was for me.
One of my earliest memories of 'coding' (It seems silly to call it that now, but hey, I was 13!) was opening the generated html files to remove the "Created with Frontpage" html comments that were automatically injected.
I'm thinking something like whatever minimal core would be considered the PCF of the web world.
<div class="center-this"><div>Stuff</div></div>
.center-this {display:table;} .center-this > div {display:table-cell;height:100%;vertical-align:middle;}
I even code pen'd it for you: http://codepen.io/anon/pen/RPEypL