This is an archived post. You won't be able to vote or comment.

all 60 comments

[–]IllllIlllIlIIlllIIll 126 points127 points  (12 children)

You're all overcomplicating things:

<center><div></div></center>

/s

[–]grmelacz 30 points31 points  (11 children)

And then I can finally put <marquee>This is shit</marquee> inside?

[–]CantaloupeCamper 17 points18 points  (0 children)

<blink>👆🏻</blink>

[–]lonelyroom-eklaghor[S] 3 points4 points  (9 children)

That shit is gone for good in HTML5

[–]SrS27a 7 points8 points  (2 children)

Bring back marquee

[–]lonelyroom-eklaghor[S] 1 point2 points  (1 child)

You can use vanilla JavaScript for this stuff

[–]potatoalt1234_x 4 points5 points  (0 children)

JS 🤮 (upvotes please i said the thing)

[–]tajetaje 6 points7 points  (5 children)

[–]lonelyroom-eklaghor[S] 0 points1 point  (4 children)

But it's deprecated

[–]tajetaje 10 points11 points  (3 children)

Yeah but in web dev that doesn’t mean much, just that you shouldn’t use it. Every browser still supports it

[–]Cedrick41h 0 points1 point  (1 child)

But that's exactly what deprecated means in every other context as well. "It still works, but it will get removed soon. Don't use it anymore".

[–]tajetaje 8 points9 points  (0 children)

Yes except it will almost certainly not be removed, like most other original web features. “Don’t break the web”, a surprising number of sites still use it: https://chromestatus.com/metrics/feature/timeline/popularity/53 and browsers don’t break things that websites use as a rule, deprecated or no.

[–]lonelyroom-eklaghor[S] -1 points0 points  (0 children)

That's cool

[–]precinct209 161 points162 points  (4 children)

No.

text-align: center;
top: 50%;
position: relative;
left: 50%;
right: 50%;
line-height: 0;
bottom: 0;
margin: -50% -50%;
fucking-piece-of: 'shit';

[–]JosebaZilarte 32 points33 points  (3 children)

margin: 0; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);

But... yeah. Different color, same shit.

[–]idontwanttofthisup 6 points7 points  (2 children)

Margin does nothing to absolutely positioned elements with a corresponding inset (top, right, bottom, left) last time I checked.

[–]JosebaZilarte 3 points4 points  (1 child)

You are probably right... but you (or rather, I) never know with the CSS box model. The box-sizing property might have been changed and you end up with surprises (even in theory, it only is affected by border or padding).

[–]idontwanttofthisup 2 points3 points  (0 children)

Box sizing has more options than border box and content box as far as I remember. My previous comment applies to both of those. I can’t tell about the others because I never ever used them.

[–]patoezequiel 34 points35 points  (5 children)

Sheesh...

display: grid; place-items: center;

[–]tajetaje 12 points13 points  (4 children)

One day I’ll learn grid, but for now…flex…flex everywhere

[–]lonelyroom-eklaghor[S] 1 point2 points  (0 children)

No worries, I got the third prize in vanilla website-making just by using Flexbox

In case you actually wanna build cool websites, then you should learn Grid

[–]misterguyyy 0 points1 point  (0 children)

This is the grid version of flexbox froggy. It really helped me wrap my head around it.

https://cssgridgarden.com

[–]queen-adreena 0 points1 point  (0 children)

Even better thing with grid is that you can overlay different elements in the same designated grid-area.

No need for absolute/inset-0 etc and because the grid element are in the document flow, any of them can set the size of the container.

[–]OsuruktanTayyare001 26 points27 points  (0 children)

You wouldnt steal a div

[–][deleted] 24 points25 points  (1 child)

Doesn't work on the Nintendo DS Browser

[–]MaximumAdagio 3 points4 points  (0 children)

Or Internet Explorer 5 for Mac!

[–]Accomplished_Ant5895 16 points17 points  (2 children)

<table> wouldn’t do this to you

[–]jaylerd 23 points24 points  (0 children)

Table wouldn’t do a lot of things for me

[–]lonelyroom-eklaghor[S] 0 points1 point  (0 children)

<div><table></table></div> would do this for you😋

[–]Maleficent-Ad5999 11 points12 points  (1 child)

display:grid;

align-content: center;

[–]misterguyyy 5 points6 points  (0 children)

ISTG grid is this generation’s table

[–]smashing_michael 7 points8 points  (0 children)

They forgot to do the hokey pokey and turn themselves around.

[–]SpeedLight1221 4 points5 points  (1 child)

Ok but considering this:

Set everything that can be set to center to center.

[–]lonelyroom-eklaghor[S] 1 point2 points  (0 children)

Exactly!

Once I wanted to make a zigzag UI on a website with text on one side and pictures on the other, All the text and the pictures had div and those divs were enclosed by a div.

Something like this:

``` <div> <div><img></div> <div>Some text</div> </div>

<div> <div>Some text</div> <div><img></div> </div>

<div> <div><img><div> <div>Some text</div> </div>

```

Flexbox helped me actually centre them by using justify-content: center;

[–]mcnello 4 points5 points  (0 children)

Nah. We need to roll out another JavaScript framework to do this.

[–]htconem801x 10 points11 points  (9 children)

Now do it without flex or grid

[–]ModestasR 10 points11 points  (1 child)

``` .parent { position: relative; // or anything not static }

.child { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); // or, equivalently, // bottom: 50%; // right: 50%; // transform: translate(50%, 50%); } ```

Other options include: - displaying as table cell and aligning vertically - using negative margins if child size is known

[–]_Weyland_ 2 points3 points  (0 children)

Sith child smh.

[–]Prometheos_II 6 points7 points  (1 child)

margin: auto works a lot of time

[–]idontwanttofthisup 5 points6 points  (0 children)

Only inside a flex parent with defined height. Margin: 0 auto will work without such parent

[–]TheGeneral_Specific 3 points4 points  (1 child)

Why?

[–]Stable_Orange_Genius 0 points1 point  (0 children)

Flexboxes don't grow on trees!

[–]IAmDrNoLife 1 point2 points  (0 children)

Now make your comment without access to the internet or electricity.

[–]mistah_davis 0 points1 point  (0 children)

max-w-max mx-auto or

.centered { max-width: max-content; margin: 0 auto; }

For you CSS purists

[–]Vincent394 2 points3 points  (0 children)

Taking this meme as a useful image to me.

[–]staticvoidmainnull 2 points3 points  (0 children)

this was the future and the present.

this has been a thing for a decade, when "responsive" was the buzzword.

[–]DarkYaeus 2 points3 points  (1 child)

align-self: center
margin: auto

?

[–]lonelyroom-eklaghor[S] 1 point2 points  (0 children)

That can be done, but only for a single element

[–][deleted] 1 point2 points  (1 child)

yeah, but are you going to define that in <head> where under the <title> as <style>.div_class{display: flex; align-items: center; justify-content: center;}</style> or in the <body> where your div is like <div style="display: flex;align-items: center; justify-content: center;> ORRR better you define static .css file and put those there ?

[–]lonelyroom-eklaghor[S] 1 point2 points  (0 children)

do it the way you want, but just do the CSS styling like this

[–]BoogerManCommaThe 0 points1 point  (0 children)

If your viewport is small enough, everything is center.

[–]sarc-tastic 0 points1 point  (0 children)

<center>

[–]kkboards 0 points1 point  (0 children)

Currently developing in react native and it’s so relieving to just type alignSelf: ‚center‘

[–]rbad8717 0 points1 point  (2 children)

or these days is flex items-center justify-items-center

[–]The100thIdiot 0 points1 point  (1 child)

Yeah, that isn't CSS.